aboutsummaryrefslogtreecommitdiff
path: root/src/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vector.c')
-rw-r--r--src/vector.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/vector.c b/src/vector.c
new file mode 100644
index 0000000..46a65e5
--- /dev/null
+++ b/src/vector.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include "vector.h"
+
+/* create a new vector of the given capacity */
+struct vector* vector_new(int cap) {
+ struct vector *l = malloc(sizeof *l);
+ l->size = 0;
+ l->cap = cap;
+ l->values = malloc(l->cap * sizeof *l->values);
+ return l;
+}
+
+/* push a new value to the end of the vector's memory */
+int vector_push(struct vector *vec, void *value) {
+ vec->values[vec->size++] = value;
+ return vec->size - 1;
+}
+
+/* free vector related memory */
+void vector_free(struct vector *l) {
+ free(l->values);
+ free(l);
+} \ No newline at end of file