diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-04 22:06:49 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-04 23:14:20 -0400 |
commit | 8874cf97227139ed10e75fe13108988b45492172 (patch) | |
tree | f9e3bb5305f1463ee2cebb924107b133cd551817 /collections/vector/vector.adoc | |
parent | a1d4279c40612e6f98564db43192929b41c59d40 (diff) |
Add truncate to vectors
Diffstat (limited to 'collections/vector/vector.adoc')
-rw-r--r-- | collections/vector/vector.adoc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/collections/vector/vector.adoc b/collections/vector/vector.adoc index d423c37..e3fa94a 100644 --- a/collections/vector/vector.adoc +++ b/collections/vector/vector.adoc @@ -1,7 +1,7 @@ Vector ====== Tucker Evans -v0.14, 2020-07-03 +v0.15, 2020-07-04 A basic vector, that hold pointers to your data structures. @@ -367,6 +367,36 @@ assert(str_cmp(vec_back(vector, str2) == 0); assert(vec_size == 2); ---- +[[vec_truncate]] ++void vec_truncate(vec *self, int size)+ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Truncates vector +self+ to +size+ elements, elements in positions > +size+ will +no longer be accessable through +self+. Does nothing if +size+ > current number +of elements. + +NOTE: Does not currently reduce memory footprint + +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)); + +vec_truncate(vector, 1); + +assert(vec_size == 1); +---- + [[vec_clear]] +void vec_clear(vec *self)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |