summaryrefslogtreecommitdiff
path: root/source/kit/dynamic_array.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/kit/dynamic_array.h')
-rw-r--r--source/kit/dynamic_array.h34
1 files changed, 22 insertions, 12 deletions
diff --git a/source/kit/dynamic_array.h b/source/kit/dynamic_array.h
index 526fb13..d2f2a6b 100644
--- a/source/kit/dynamic_array.h
+++ b/source/kit/dynamic_array.h
@@ -8,26 +8,29 @@ extern "C" {
#endif
typedef struct {
- ptrdiff_t capacity;
- ptrdiff_t size;
- void *values;
- kit_allocator_t alloc;
+ ptrdiff_t capacity;
+ ptrdiff_t size;
+ void *values;
+ kit_allocator_t *alloc;
} kit_da_void_t;
void kit_da_init(kit_da_void_t *array, ptrdiff_t element_size,
- ptrdiff_t size, kit_allocator_t alloc);
+ ptrdiff_t size, kit_allocator_t *alloc);
void kit_da_resize(kit_da_void_t *array, ptrdiff_t element_size,
ptrdiff_t size);
+void kit_da_resize_exact(kit_da_void_t *array, ptrdiff_t element_size,
+ ptrdiff_t size);
+
/* Dynamic array type definition.
*/
-#define KIT_DA(element_type_) \
- struct { \
- ptrdiff_t capacity; \
- ptrdiff_t size; \
- element_type_ *values; \
- kit_allocator_t alloc; \
+#define KIT_DA(element_type_) \
+ struct { \
+ ptrdiff_t capacity; \
+ ptrdiff_t size; \
+ element_type_ *values; \
+ kit_allocator_t *alloc; \
}
/* Initialize dynamic array.
@@ -40,7 +43,7 @@ void kit_da_resize(kit_da_void_t *array, ptrdiff_t element_size,
*/
#define KIT_DA_CREATE(name_, element_type_, size_) \
KIT_DA(element_type_) name_; \
- KIT_DA_INIT(name_, (size_), kit_alloc_default())
+ KIT_DA_INIT(name_, (size_), NULL)
/* Destroy dynamic array.
*/
@@ -57,6 +60,12 @@ void kit_da_resize(kit_da_void_t *array, ptrdiff_t element_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_) \
@@ -106,6 +115,7 @@ typedef KIT_DA(char) kit_string_t;
# 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