aboutsummaryrefslogtreecommitdiff
path: root/include/vector.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/vector.h')
-rw-r--r--include/vector.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/vector.h b/include/vector.h
new file mode 100644
index 0000000..a34ecea
--- /dev/null
+++ b/include/vector.h
@@ -0,0 +1,27 @@
+#ifndef VECTOR_H
+#define VECTOR_H
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#define VEC_CAP 32
+
+struct vector {
+ size_t cap;
+ size_t len;
+ void **values;
+};
+
+struct vector *vector_new_with_cap(size_t cap);
+
+#define vector_new() vector_new_with_cap(VEC_CAP)
+
+ssize_t vector_push(struct vector *, void *val);
+
+void vector_free(struct vector *);
+
+#define vector_foreach(vec, i, val) \
+ for (i = 0, val = vec->values[i]; i < vec->len; i++, val = vec->values[i])
+
+#endif