From 1a41fe605ab6bde15f622e72abb7aee846531fcf Mon Sep 17 00:00:00 2001
From: Tucker Evans <tucker@tuckerevans.com>
Date: Fri, 3 Jul 2020 01:18:17 -0400
Subject: Add swap_pop function for vectors

---
 collections/vector/vector.adoc | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

(limited to 'collections/vector/vector.adoc')

diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc
index cc83375..ee453ff 100644
--- a/collections/vector/vector.adoc
+++ b/collections/vector/vector.adoc
@@ -1,7 +1,7 @@
 Vector
 ======
 Tucker Evans
-v0.11, 2020-07-03
+v0.12, 2020-07-03
 
 A basic vector, that hold pointers to your data structures.
 
@@ -283,6 +283,34 @@ assert(str_cmp(vec_index(vector, 0), str2) == 0);
 assert(str_cmp(vec_back(vector), str1) == 0);
 ----
 
+[[vec_swap_pop]]
++void* vec_swap_pop(vec *self, int index)+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Swaps back element with item at +index+, and pops item now at back.
+Will return same element as +vec_remove(self, index)+.
+Does not keep order of elements, but faster that <<vec_remove,+vec_remove()+>>.
+
+Examples
+^^^^^^^^
+[source,c]
+----
+#include "vector.h"
+#include <string.h>
+
+char *str1 = "ONE";
+char *str2 = "TWO";
+char *str3 = "THREE";
+
+vec *vector = vec_new();
+vec_push(vector, str_dup(str1));
+vec_push(vector, str_dup(str2));
+vec_push(vector, str_dup(str3));
+
+assert(str_cmp(vec_swap_pop(vector, 2), str3) == 0);
+assert(str_cmp(vec_back(vector, str2) == 0);
+assert(vec_size == 2);
+----
+
 [[vec_clear]]
 +void vec_clear(vec *self)+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- 
cgit v1.1

