diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-03 01:05:09 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-04 23:10:28 -0400 |
commit | 72cb2e77024970509ff403670f9e4245bcefebd6 (patch) | |
tree | e5209cd49f7f005884561bb834b37f7175b67363 /collections/vector/vector.adoc | |
parent | b253b373ea74539a0f29a88ac2be728aa8158d2a (diff) |
Add swap function to vectors
Diffstat (limited to 'collections/vector/vector.adoc')
-rw-r--r-- | collections/vector/vector.adoc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc index 0409b05..cc83375 100644 --- a/collections/vector/vector.adoc +++ b/collections/vector/vector.adoc @@ -1,7 +1,7 @@ Vector ====== Tucker Evans -v0.10, 2020-07-03 +v0.11, 2020-07-03 A basic vector, that hold pointers to your data structures. @@ -257,6 +257,32 @@ vec_push(vector, str_dup(str3)); assert(str_cmp(vec_index(vector, 1), str2) == 0); ---- +[[vec_swap]] ++void vec_swap(vec *self, int i, int j)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Swaps elements at positions +i+ and +j+, does nothing if +i+ or +j+ are out of +bounds. + +Examples +^^^^^^^^ +[source,c] +---- +#include "dvector.h" +#include <string.h> + +char *str1 = "ONE"; +char *str2 = "TWO"; + +vec *vector = vec_new(); +vec_push(vector, str_dup(str1)); +vec_push(vector, str_dup(str2)); + +vec_swap(vector, 0, 1); + +assert(str_cmp(vec_index(vector, 0), str2) == 0); +assert(str_cmp(vec_back(vector), str1) == 0); +---- + [[vec_clear]] +void vec_clear(vec *self)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |