37#ifndef UCX_ARRAY_LIST_H
38#define UCX_ARRAY_LIST_H
79#define CX_ARRAY_DECLARE_SIZED(type, name, size_type) \
81 size_type name##_size; \
82 size_type name##_capacity
108#define CX_ARRAY_DECLARE(type, name) CX_ARRAY_DECLARE_SIZED(type, name, size_t)
133#define cx_array_initialize(array, capacity) \
134 array##_capacity = capacity; \
136 array = malloc(sizeof(array[0]) * capacity)
160#define cx_array_initialize_a(allocator, array, capacity) \
161 array##_capacity = capacity; \
163 array = cxMalloc(allocator, sizeof(array[0]) * capacity)
351#define cx_array_simple_copy_a(reallocator, array, index, src, count) \
352 cx_array_copy((void**)&(array), &(array##_size), &(array##_capacity), \
353 sizeof(array##_size), index, src, sizeof((array)[0]), count, \
369#define cx_array_simple_copy(array, index, src, count) \
370 cx_array_simple_copy_a(NULL, array, index, src, count)
384#define cx_array_simple_reserve_a(reallocator, array, count) \
385 cx_array_reserve((void**)&(array), &(array##_size), &(array##_capacity), \
386 sizeof(array##_size), sizeof((array)[0]), count, \
400#define cx_array_simple_reserve(array, count) \
401 cx_array_simple_reserve_a(NULL, array, count)
426#define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \
427 cx_array_copy((void**)(target), size, capacity, sizeof(*(size)), \
428 *(size), elem, elem_size, 1, reallocator)
442#define cx_array_simple_add_a(reallocator, array, elem) \
443 cx_array_simple_copy_a(reallocator, array, array##_size, &(elem), 1)
456#define cx_array_simple_add(array, elem) \
457 cx_array_simple_add_a(cx_array_default_reallocator, array, elem)
518#define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \
519 cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator)
534#define cx_array_simple_add_sorted_a(reallocator, array, elem, cmp_func) \
535 cx_array_add_sorted(&array, &(array##_size), &(array##_capacity), \
536 sizeof((array)[0]), &(elem), cmp_func, reallocator)
550#define cx_array_simple_add_sorted(array, elem, cmp_func) \
551 cx_array_simple_add_sorted_a(NULL, array, elem, cmp_func)
567#define cx_array_simple_insert_sorted_a(reallocator, array, src, n, cmp_func) \
568 cx_array_insert_sorted((void**)(&array), &(array##_size), &(array##_capacity), \
569 cmp_func, src, sizeof((array)[0]), n, reallocator)
584#define cx_array_simple_insert_sorted(array, src, n, cmp_func) \
585 cx_array_simple_insert_sorted_a(NULL, array, src, n, cmp_func)
718 size_t initial_capacity
736#define cxArrayListCreateSimple(elem_size, initial_capacity) \
737 cxArrayListCreate(NULL, NULL, elem_size, initial_capacity)
size_t cx_array_binary_search_inf(const void *arr, size_t size, size_t elem_size, const void *elem, cx_compare_func cmp_func)
Searches the largest lower bound in a sorted array.
int cx_array_insert_sorted(void **target, size_t *size, size_t *capacity, cx_compare_func cmp_func, const void *src, size_t elem_size, size_t elem_count, CxArrayReallocator *reallocator)
Inserts a sorted array into another sorted array.
const unsigned cx_array_swap_sbo_size
The maximum item size in an array list that fits into stack buffer when swapped.
CxArrayReallocator cx_array_reallocator(const struct cx_allocator_s *allocator, const void *stackmem)
Creates a new array reallocator.
int cx_array_reserve(void **array, void *size, void *capacity, unsigned width, size_t elem_size, size_t elem_count, CxArrayReallocator *reallocator)
Reserves memory for additional elements.
size_t cx_array_binary_search_sup(const void *arr, size_t size, size_t elem_size, const void *elem, cx_compare_func cmp_func)
Searches the smallest upper bound in a sorted array.
CxArrayReallocator * cx_array_default_reallocator
A default stdlib-based array reallocator.
size_t cx_array_binary_search(const void *arr, size_t size, size_t elem_size, const void *elem, cx_compare_func cmp_func)
Searches an item in a sorted array.
int cx_array_copy(void **target, void *size, void *capacity, unsigned width, size_t index, const void *src, size_t elem_size, size_t elem_count, CxArrayReallocator *reallocator)
Copies elements from one array to another.
CxList * cxArrayListCreate(const CxAllocator *allocator, cx_compare_func comparator, size_t elem_size, size_t initial_capacity)
Allocates an array list for storing elements with elem_size bytes each.
void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2)
Swaps two array elements.
#define cx_attr_export
Only used for building Windows DLLs.
Definition common.h:285
#define cx_attr_allocsize(...)
Specifies the parameters from which the allocation size is calculated.
Definition common.h:178
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_malloc
The attributed function always returns freshly allocated memory.
Definition common.h:151
#define cx_attr_nonnull_arg(...)
The specified pointer arguments must be non-NULL.
Definition common.h:141
#define cx_attr_dealloc(...)
Not supported in clang.
Definition common.h:167
int(* cx_compare_func)(const void *left, const void *right)
A comparator function comparing two arbitrary values.
Definition compare.h:60
Interface for list implementations.
void cxListFree(CxList *list)
Deallocates the memory of the specified list structure.
Structure holding the data for an allocator.
Definition allocator.h:84
Defines a reallocation mechanism for arrays.
Definition array_list.h:170
void * ptr1
Custom data pointer.
Definition array_list.h:199
size_t int1
Custom data integer.
Definition array_list.h:207
size_t int2
Custom data integer.
Definition array_list.h:211
void * ptr2
Custom data pointer.
Definition array_list.h:203
void *(* realloc)(void *array, size_t capacity, size_t elem_size, struct cx_array_reallocator_s *alloc)
Reallocates space for the given array.
Definition array_list.h:189
Structure for holding the base data of a list.
Definition list.h:54