diff options
author | Tucker Evans <tucker@tuckerevans.com> | 2020-07-01 16:19:16 -0400 |
---|---|---|
committer | Tucker Evans <tucker@tuckerevans.com> | 2020-07-01 16:46:50 -0400 |
commit | 65ddeea23e1303d0b2d9656601b90df138d19e6c (patch) | |
tree | 658eba5ff624e00e8f7f668e8d2c0876faaf1d74 /collections/vector/vector.c | |
parent | 754414b451c4ca93d139f61b82bacfa81d236a04 (diff) |
Add start to vector
Diffstat (limited to 'collections/vector/vector.c')
-rw-r--r-- | collections/vector/vector.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/collections/vector/vector.c b/collections/vector/vector.c new file mode 100644 index 0000000..2c75bc1 --- /dev/null +++ b/collections/vector/vector.c @@ -0,0 +1,53 @@ +#include "vector.h" + +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#include <stdio.h> + +#define START_SIZE 64; + +struct vector { + void **base; + int end, limit; +}; + +vec* vec_new() +{ + vec *root; + + root = malloc(sizeof(vec)); + assert(root); + + root->limit = START_SIZE; + root->base = malloc(root->limit * sizeof(void*)); + assert(root->base); + + return root; +} + +vec* vec_with_capacity(n) +int n; +{ + vec *root; + + root = malloc(sizeof(vec)); + assert(root); + + root->limit = n; + root->base = malloc(root->limit * sizeof(void*)); + assert(root->base); + + return root; +} + +int vec_size(root) +vec *root; +{ + if (!root) { + return -1; + } + return root->end; +} + |