From 5625a8626fe303748b205c80f87035593cf2f561 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Fri, 8 May 2026 19:30:44 -0400 Subject: Initial commit --- teensy/dyn_arr.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 teensy/dyn_arr.h (limited to 'teensy/dyn_arr.h') diff --git a/teensy/dyn_arr.h b/teensy/dyn_arr.h new file mode 100644 index 0000000..7a45d4e --- /dev/null +++ b/teensy/dyn_arr.h @@ -0,0 +1,33 @@ +#ifndef DYN_ARR_H_ +#define DYN_ARR_H_ + +#include "common.h" + +#define TY_LIST_MIN_CAP 8 +#define TY_LIST_GROW_RATE 2 + +#define ty_list_create(T, init_capacity) \ + ((T*)_ty_list_create(sizeof(T), init_capacity)) + +#define ty_list_len_ptr(arr) ((int*)arr - 2) +#define ty_list_len(arr) (*ty_list_len_ptr(arr)) + +#define ty_list_cap_ptr(arr) ((int*)arr - 1) +#define ty_list_cap(arr) (*ty_list_cap_ptr(arr)) + +#define ty_list_base(arr) ((void*)ty_list_len_ptr(arr)) + +#define ty_list_append_slot(T, arr) \ + ((T*)_ty_list_append_slot(sizeof(T), (void**)arr)) + +#define ty_list_append(T, arr, elem) \ + (*ty_list_append_slot(T, arr) = elem) + +#define ty_list_clear(arr) \ + (*ty_list_len_ptr(arr) = 0) + +void *_ty_list_create(size_t type_size, int init_cap); +void *_ty_list_append_slot(size_t type_size, void **arr); +void ty_list_free(void *arr); + +#endif // DYN_ARR_H_ -- cgit v1.3-2-g0d8e