diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-03 00:57:58 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-04 23:10:16 -0400 |
commit | b253b373ea74539a0f29a88ac2be728aa8158d2a (patch) | |
tree | cffba7f4788d4710080145b568882c279bc109e8 /collections/vector/vector.adoc | |
parent | f900066b813fac2f34798c39f16dacda9a878610 (diff) |
Add set index function for vectors
Diffstat (limited to 'collections/vector/vector.adoc')
-rw-r--r-- | collections/vector/vector.adoc | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc index d439c85..0409b05 100644 --- a/collections/vector/vector.adoc +++ b/collections/vector/vector.adoc @@ -1,7 +1,7 @@ Vector ====== Tucker Evans -v0.9, 2020-07-03 +v0.10, 2020-07-03 A basic vector, that hold pointers to your data structures. @@ -208,6 +208,30 @@ vec_push(vector, str_dup(str2)); assert(strcmp(vec_back(vector), str2) == 0); ---- +[[vec_set]] ++void vec_set(vec *self, int index, void *item)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Sets the element at position +index+ in +self+ to +item+. + +Examples +^^^^^^^^ +[source,c] +---- +#include "vector.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_set(vector, 0, str2); + +assert(str_cmp(vec_pop(vector), str2) == 0); +assert(str_cmp(vec_pop(vector), str2) == 0); +---- [[vec_index]] +void* vec_index(vec *self, int index)+ |