summaryrefslogtreecommitdiff
path: root/src/vec.h
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-10 09:32:35 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-10 09:32:35 +0100
commitccab86b21825ebc41f0887ea633ea28906b32a8e (patch)
tree60f378c3629c139f412d41a85142d1b48518e54f /src/vec.h
parent86c09e193ed66420da48a7fd62678286b89dace2 (diff)
adding vector and eventloop implementation
Diffstat (limited to 'src/vec.h')
-rw-r--r--src/vec.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/vec.h b/src/vec.h
new file mode 100644
index 0000000..2b4d11c
--- /dev/null
+++ b/src/vec.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "utils.h"
+
+#define WAYC_VEC_INITIAL 4
+#define WAYC_VEC_GROWTH 2
+#define WAYC_VEC_THRESHOLD 8
+
+struct raw_vec_s {
+ u8 *ptr;
+ usize size;
+ usize len, cap;
+};
+
+#define WAYC_RAW_VEC_INIT(size) {nullptr, size, 0, 0}
+
+void wayc_raw_vec_push(raw_vec_s *vec, const u8 *at);
+bool wayc_raw_vec_pop(raw_vec_s *vec, u8 *out);
+void wayc_raw_vec_deinit(raw_vec_s *vec);
+
+template <typename T> struct vec_s {
+ raw_vec_s raw;
+};
+
+#define WAYC_VEC_INIT(type) {WAYC_RAW_VEC_INIT(sizeof(type))}
+
+template <typename T>
+static inline void wayc_vec_push(vec_s<T> *vec, const T *at) {
+ wayc_raw_vec_push(&vec->raw, (u8 *)at);
+}
+
+template <typename T> static inline bool wayc_vec_pop(vec_s<T> *vec, T *out) {
+ return wayc_raw_vec_pop(&vec->raw, (u8 *)out);
+}
+
+template <typename T> static inline void wayc_vec_deinit(vec_s<T> *vec) {
+ wayc_raw_vec_deinit(&vec->raw);
+} \ No newline at end of file