summaryrefslogtreecommitdiff
path: root/kit/dynamic_array.h
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-11-17 05:24:04 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-11-17 05:24:04 +0100
commitd5a727a062e4d727491f4e7f047269d60a93a8cf (patch)
tree565aec155ab056f1bef8ddc7dc78d52e65aa76b7 /kit/dynamic_array.h
parent4ba961dcbf60f7c12f53f46baa261757e15d5931 (diff)
downloadsaw-d5a727a062e4d727491f4e7f047269d60a93a8cf.zip
Remove lots of dependencies
Diffstat (limited to 'kit/dynamic_array.h')
-rw-r--r--kit/dynamic_array.h126
1 files changed, 0 insertions, 126 deletions
diff --git a/kit/dynamic_array.h b/kit/dynamic_array.h
deleted file mode 100644
index 571f344..0000000
--- a/kit/dynamic_array.h
+++ /dev/null
@@ -1,126 +0,0 @@
-#ifndef KIT_DYNAMIC_ARRAY_H
-#define KIT_DYNAMIC_ARRAY_H
-
-#include "allocator.h"
-
-#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- i64 capacity;
- i64 size;
- void *values;
- kit_allocator_t *alloc;
-} kit_da_void_t;
-
-void kit_da_init(kit_da_void_t *array, i64 element_size, i64 size,
- kit_allocator_t *alloc);
-
-void kit_da_resize(kit_da_void_t *array, i64 element_size, i64 size);
-
-void kit_da_resize_exact(kit_da_void_t *array, i64 element_size,
- i64 size);
-
-/* Dynamic array type definition.
- */
-#define KIT_DA(element_type_) \
- struct { \
- i64 capacity; \
- i64 size; \
- element_type_ *values; \
- kit_allocator_t *alloc; \
- }
-
-/* Initialize dynamic array.
- */
-#define KIT_DA_INIT(array_, size_, alloc_) \
- kit_da_init((kit_da_void_t *) &(array_), \
- sizeof((array_).values[0]), (size_), (alloc_))
-
-/* Declare and initialize dynamic array.
- */
-#define KIT_DA_CREATE(name_, element_type_, size_) \
- KIT_DA(element_type_) name_; \
- KIT_DA_INIT(name_, (size_), NULL)
-
-/* Destroy dynamic array.
- */
-#define KIT_DA_DESTROY(array_) \
- do { \
- if ((array_).values != NULL) \
- kit_alloc_dispatch((array_).alloc, KIT_DEALLOCATE, 0, \
- (array_).capacity * \
- sizeof((array_).values[0]), \
- (array_).values); \
- memset(&(array_), 0, sizeof(array_)); \
- } while (0)
-
-/* Resize dynamic array.
- */
-#define KIT_DA_RESIZE(array_, size_) \
- kit_da_resize((kit_da_void_t *) &(array_), \
- sizeof((array_).values[0]), size_)
-
-/* Resize dynamic array with exact capacity.
- */
-#define KIT_DA_RESIZE_EXACT(array_, capacity_) \
- kit_da_resize_exact((kit_da_void_t *) &(array_), \
- sizeof((array_).values[0]), capacity_)
-
-/* Append a value to dynamic array.
- */
-#define KIT_DA_APPEND(array_, value_) \
- do { \
- i64 kit_index_back_ = (array_).size; \
- KIT_DA_RESIZE((array_), kit_index_back_ + 1); \
- if (kit_index_back_ < (array_).size) \
- (array_).values[kit_index_back_] = (value_); \
- } while (0)
-
-/* Insert a value into dynamic array.
- */
-#define KIT_DA_INSERT(array_, index_, value_) \
- do { \
- i64 kit_i_; \
- i64 kit_index_back_ = (array_).size; \
- i64 kit_indert_n_ = (index_); \
- KIT_DA_RESIZE((array_), kit_index_back_ + 1); \
- if (kit_index_back_ + 1 == (array_).size) { \
- for (kit_i_ = kit_index_back_; kit_i_ > kit_indert_n_; \
- kit_i_--) \
- (array_).values[kit_i_] = (array_).values[kit_i_ - 1]; \
- (array_).values[kit_indert_n_] = (value_); \
- } \
- } while (0)
-
-/* Erase a value from dynamic array.
- */
-#define KIT_DA_ERASE(array_, index_) \
- do { \
- i64 i_; \
- for (i_ = (index_) + 1; i_ < (array_).size; i_++) \
- (array_).values[i_ - 1] = (array_).values[i_]; \
- KIT_DA_RESIZE((array_), (array_).size - 1); \
- } while (0)
-
-#ifdef __cplusplus
-}
-#endif
-
-#define da_void_t kit_da_void_t
-#define da_init kit_da_init
-#define da_resize kit_da_resize
-#define DA KIT_DA
-#define DA_INIT KIT_DA_INIT
-#define DA_CREATE KIT_DA_CREATE
-#define DA_DESTROY KIT_DA_DESTROY
-#define DA_RESIZE KIT_DA_RESIZE
-#define DA_RESIZE_EXACT KIT_DA_RESIZE_EXACT
-#define DA_APPEND KIT_DA_APPEND
-#define DA_INSERT KIT_DA_INSERT
-#define DA_ERASE KIT_DA_ERASE
-
-#endif