diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-03 01:18:17 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-04 23:11:41 -0400 |
commit | 1a41fe605ab6bde15f622e72abb7aee846531fcf (patch) | |
tree | eaffdc8276bc59989d13e32b4a572b8a6c2b1afb /collections/vector/vector.adoc | |
parent | 72cb2e77024970509ff403670f9e4245bcefebd6 (diff) |
Add swap_pop function for vectors
Diffstat (limited to 'collections/vector/vector.adoc')
-rw-r--r-- | collections/vector/vector.adoc | 30 |
1 files changed, 29 insertions, 1 deletions
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)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |