summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-12-24 02:26:00 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-12-24 02:26:40 +0100
commita5d1c6da7e5617c15dd729a7907fb38cc25c2e1b (patch)
treea2311d363a96a6165b4bb3a956b653efbcab2aa1 /examples
parent144bd88ff5146af4df99596606a7bf2a624723fc (diff)
Add vectors
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile8
-rw-r--r--examples/gevector.c25
2 files changed, 30 insertions, 3 deletions
diff --git a/examples/Makefile b/examples/Makefile
index 25d3fa5..af41d5d 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -4,11 +4,13 @@ CC = cc
CFLAGS = -Og -g -ggdb
LDFLAGS = -I../src
-srcs = gehashmap
+progs = gehashmap gevector
-all: ${srcs}
+all: ${progs}
gehashmap: gehashmap.c
+gevector: gevector.c
+
clean:
- rm -f ${srcs}
+ rm -f ${progs}
diff --git a/examples/gevector.c b/examples/gevector.c
new file mode 100644
index 0000000..e554005
--- /dev/null
+++ b/examples/gevector.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <gevector.h>
+
+GEVECTOR_API(int, ivec);
+GEVECTOR_IMPL(int, ivec);
+
+int
+main(void)
+{
+ struct ivec *vec = malloc(sizeof(struct ivec));
+ ivec_new(vec, 2, 0);
+
+ ivec_append(vec, 42);
+ ivec_append(vec, 69);
+ ivec_append(vec, 420);
+ ivec_insert(vec, 1337, 2);
+
+ for (size_t i = 0; i < vec->size; i++)
+ printf("%d\n", vec->items[i]);
+
+ free(vec->items);
+ free(vec);
+}