aboutsummaryrefslogtreecommitdiff
path: root/collections/vector/vector.c
diff options
context:
space:
mode:
authorTucker Evans <tucker@tuckerevans.com>2020-07-04 22:17:27 -0400
committerTucker Evans <tucker@tuckerevans.com>2020-07-04 23:14:34 -0400
commit5fa1551b4a0acc28d5c656479806511ab0c81a18 (patch)
tree47738892753aaf5947f011f779efd159ea476266 /collections/vector/vector.c
parent8aa9f42d914a453a0570752ee292b9a9cfcae9d6 (diff)
Add reserve function to vectors
Diffstat (limited to 'collections/vector/vector.c')
-rw-r--r--collections/vector/vector.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/collections/vector/vector.c b/collections/vector/vector.c
index 391b5a6..f14c302 100644
--- a/collections/vector/vector.c
+++ b/collections/vector/vector.c
@@ -250,6 +250,20 @@ int size;
root->end = size;
}
+void vec_reserve(root, n)
+vec *root;
+int n;
+{
+ int i;
+
+ if (!root || n + root->end <= root->limit)
+ return;
+
+ for (i = root->limit; i < root->end + n; i*=2);
+
+ root->base = reallocarray(root->base, i, sizeof(void*));
+}
+
void vec_clear(root)
vec *root;
{