diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-03 23:49:15 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-04 23:13:34 -0400 |
commit | e6af2f70ec910ee8cb3813fa1e5b1c7d6e3ead60 (patch) | |
tree | ad518b44f3a1eb0601a1b52ca59cc55a61b16e72 /collections/vector/vector.c | |
parent | a691f4d4b0a57d62eb792e6ede0c0fa5334e3e61 (diff) |
Add insert function for vectors
Diffstat (limited to 'collections/vector/vector.c')
-rw-r--r-- | collections/vector/vector.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/collections/vector/vector.c b/collections/vector/vector.c index 79e31a4..2ae748f 100644 --- a/collections/vector/vector.c +++ b/collections/vector/vector.c @@ -174,6 +174,23 @@ int index; return root->base[index]; } +void vec_insert(root, index, item) +vec *root; +int index; +void *item; +{ + if (!root || index > root->end || index < 0) + return; + + if (root->end >= root->limit) + vec_resize(root); + + memmove(root->base + index + 1, root->base + index, + (root->end++ - index) * sizeof(void*)); + + root->base[index] = item; +} + void vec_swap(root, i, j) vec *root; int i,j; |