diff options
| author | steven-na <noreply.github@stvnc.dev> | 2026-08-06 02:36:01 -0700 |
|---|---|---|
| committer | steven-na <noreply.github@stvnc.dev> | 2026-08-06 02:36:01 -0700 |
| commit | 5d575f8cd99e9bc064b3d998f17b194a818e3546 (patch) | |
| tree | 8a8e1485dda924aeefb5428e26dbcca74f74721e /src/slidingwindow.h | |
| parent | d07b96b9914e706630dc1d2807ecfa9e104945d5 (diff) | |
Sliding window array implementation
Diffstat (limited to 'src/slidingwindow.h')
| -rw-r--r-- | src/slidingwindow.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/slidingwindow.h b/src/slidingwindow.h new file mode 100644 index 0000000..3cfe821 --- /dev/null +++ b/src/slidingwindow.h @@ -0,0 +1,19 @@ +#pragma once + +#include "common.h" +#include "smrt_arena.h" + +#define SLIDING_WINDOW_BASE_POS (sizeof(sliding_window_array_t)) + +typedef struct { + u64 size; + u64 num_elements; + u64 start_idx; + u64 element_size_bytes; +} sliding_window_array_t; + +#define SMRTA_ALLOC_SLIDINGWINDOW(arena, T, n) (sliding_window_array_t*)sw_create(arena, sizeof(T), (n)) +#define SLIDINGWINDOW_GET(w, T) ((T*)((u8*)(w) + SLIDING_WINDOW_BASE_POS) + (w)->start_idx) + +sliding_window_array_t *sw_create(smrt_arena_t *arena, u64 elem_size, u64 size); +void sw_insert(sliding_window_array_t *sw, void *x); |