From 8874cf97227139ed10e75fe13108988b45492172 Mon Sep 17 00:00:00 2001
From: Tucker Evans <tucker@tuckerevans.com>
Date: Sat, 4 Jul 2020 22:06:49 -0400
Subject: Add truncate to vectors

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

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

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)+
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- 
cgit v1.1

