summaryrefslogtreecommitdiffstats
path: root/wv_vec.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2026-05-06 17:46:49 +0800
committerSadeep Madurange <sadeep@asciimx.com>2026-05-06 17:46:49 +0800
commit8f0c3d4697742fb64cb1af8ba28fa2bb6f99de5a (patch)
tree1822d135ec879620361e1d80cb54a63d2d8d3602 /wv_vec.c
parentfd2d93f4a97ab5a3bc18764c353b971b4035ac6a (diff)
downloadweb-view-master.tar.gz
Implemented tokenizer.HEADmaster
Diffstat (limited to 'wv_vec.c')
-rw-r--r--wv_vec.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/wv_vec.c b/wv_vec.c
new file mode 100644
index 0000000..1d1eaad
--- /dev/null
+++ b/wv_vec.c
@@ -0,0 +1,46 @@
+#include <string.h>
+
+#include "wv_vec.h"
+
+void wv_vec_init(struct wv_vec *v, size_t unit_size)
+{
+ v->data = NULL;
+ v->len = 0;
+ v->cap = 0;
+ v->unit_size = unit_size;
+}
+
+void wv_vec_push(struct wv_vec *v, const void *item)
+{
+ if (v->len >= v->cap) {
+ v->cap = (v->cap == 0) ? 8 : v->cap * 2;
+ v->data = realloc(v->data, v->cap * v->unit_size);
+ }
+ void *target = (char *)v->data + (v->len * v->unit_size);
+ memcpy(target, item, v->unit_size);
+ v->len++;
+}
+
+void *wv_vec_pop(struct wv_vec *v)
+{
+ if (v->len == 0)
+ return NULL;
+
+ v->len--;
+ return (char *)v->data + (v->len * v->unit_size);
+}
+
+void *wv_vec_last(struct wv_vec *v)
+{
+ if (v->len == 0)
+ return NULL;
+ return (char *)v->data + ((v->len - 1) * v->unit_size);
+}
+
+void wv_vec_free(struct wv_vec *v)
+{
+ free(v->data);
+ v->data = NULL;
+ v->len = v->cap = 0;
+}
+