aboutsummaryrefslogtreecommitdiff
path: root/include/vector.h
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-01-20 02:34:32 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2022-01-20 02:34:32 +0300
commitc0cd4e5f199e8567ec3b5e216fbee27837d21bea (patch)
treec78eee02932fc6e85413e367d27ec5b5627e1534 /include/vector.h
downloadcmonkey-c0cd4e5f199e8567ec3b5e216fbee27837d21bea.tar.gz
cmonkey-c0cd4e5f199e8567ec3b5e216fbee27837d21bea.zip
init
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