37#ifndef UCX_ARRAY_LIST_H
38#define UCX_ARRAY_LIST_H
54#define CX_ARRAY(type, name) \
104#define cx_array_init_a(allocator, array, capacity) cx_array_init_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity)
118#define cx_array_init(array, capacity) cx_array_init_a(cxDefaultAllocator, array, capacity)
157#define cx_array_init_fixed(array, fixed_size_array, num_initialized) \
158 cx_array_init_fixed_((CxArray*)&(array), fixed_size_array, cx_nmemb(fixed_size_array), num_initialized)
186#define cx_array_reserve_a(allocator, array, capacity) \
187 cx_array_reserve_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity)
199#define cx_array_reserve(array, capacity) \
200 cx_array_reserve_a(cxDefaultAllocator, array, capacity)
233#define cx_array_copy_to_new_a(allocator, array, capacity) \
234 cx_array_copy_to_new_(allocator, (CxArray*)&(array), sizeof((array).data[0]), capacity)
251#define cx_array_copy_to_new(array, capacity) \
252 cx_array_copy_to_new_a(cxDefaultAllocator, array, capacity)
270 size_t elem_size,
size_t index, const
void *other,
size_t n);
283#define cx_array_add_a(allocator, array, element) \
284 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, (void*)&(element), 1)
296#define cx_array_add(array, element) \
297 cx_array_add_a(cxDefaultAllocator, array, element)
311#define cx_array_insert_a(allocator, array, index, element) \
312 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, (void*)&(element), 1)
325#define cx_array_insert(array, index, element) \
326 cx_array_insert_a(cxDefaultAllocator, array, index, element)
341#define cx_array_insert_array_a(allocator, array, index, other, n) \
342 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), index, other, n)
356#define cx_array_insert_array(array, index, other, n) \
357 cx_array_insert_array_a(cxDefaultAllocator, array, index, other, n)
371#define cx_array_add_array_a(allocator, array, other, n) \
372 cx_array_insert_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (array).size, other, n)
385#define cx_array_add_array(array, other, n) \
386 cx_array_add_array_a(cxDefaultAllocator, array, other, n)
405 size_t elem_size,
const void *sorted_data,
size_t n,
422#define cx_array_insert_sorted_a(allocator, array, element, cmp_func) \
423 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, true)
438#define cx_array_insert_sorted(array, element, cmp_func) \
439 cx_array_insert_sorted_a(cxDefaultAllocator, array, element, cmp_func)
456#define cx_array_insert_sorted_array_a(allocator, array, sorted_data, n, cmp_func) \
457 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, true)
473#define cx_array_insert_sorted_array(array, sorted_data, n, cmp_func) \
474 cx_array_insert_sorted_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func)
490#define cx_array_insert_unique_a(allocator, array, element, cmp_func) \
491 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, false)
506#define cx_array_insert_unique(array, element, cmp_func) \
507 cx_array_insert_unique_a(cxDefaultAllocator, array, element, cmp_func)
524#define cx_array_insert_unique_array_a(allocator, array, sorted_data, n, cmp_func) \
525 cx_array_insert_sorted_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, false)
541#define cx_array_insert_unique_array(array, sorted_data, n, cmp_func) \
542 cx_array_insert_unique_array_a(cxDefaultAllocator, array, sorted_data, n, cmp_func)
562 size_t elem_size, const
void *sorted_data,
size_t n,
580#define cx_array_insert_sorted_ca(allocator, array, element, cmp_func, context) \
581 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, true)
597#define cx_array_insert_sorted_c(array, element, cmp_func, context) \
598 cx_array_insert_sorted_ca(cxDefaultAllocator, array, element, cmp_func, context)
616#define cx_array_insert_sorted_array_ca(allocator, array, sorted_data, n, cmp_func, context) \
617 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, true)
634#define cx_array_insert_sorted_array_c(array, sorted_data, n, cmp_func, context) \
635 cx_array_insert_sorted_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context)
652#define cx_array_insert_unique_ca(allocator, array, element, cmp_func, context) \
653 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, false)
669#define cx_array_insert_unique_c(array, element, cmp_func, context) \
670 cx_array_insert_unique_ca(cxDefaultAllocator, array, element, cmp_func, context)
688#define cx_array_insert_unique_array_ca(allocator, array, sorted_data, n, cmp_func, context) \
689 cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), sorted_data, n, cmp_func, context, false)
706#define cx_array_insert_unique_array_c(array, sorted_data, n, cmp_func, context) \
707 cx_array_insert_unique_array_ca(cxDefaultAllocator, array, sorted_data, n, cmp_func, context)
757#define cx_array_sort(array, fn) \
758 cx_array_sort_((CxArray*)&(array), sizeof((array).data[0]), fn)
767#define cx_array_sort_c(array, fn, context) \
768 cx_array_sort_c_((CxArray*)&(array), sizeof((array).data[0]), fn, context)
794#define cx_array_iterator(array) \
795 cx_array_iterator_((CxArray*)&(array), sizeof((array).data[0]))
821#define cx_array_iterator_ptr(array) \
822 cx_array_iterator_ptr_((CxArray*)&(array))
851#define cx_array_remove(array, index) \
852 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, false)
867#define cx_array_remove_fast(array, index) \
868 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, 1, true)
884#define cx_array_remove_array(array, index, n) \
885 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, false)
902#define cx_array_remove_array_fast(array, index, n) \
903 cx_array_remove_((CxArray*)&(array), sizeof((array).data[0]), index, n, true)
924#define cx_array_free(array) cx_array_free_(cxDefaultAllocator, (CxArray*)&(array))
935#define cx_array_free_a(allocator, array) cx_array_free_(allocator, (CxArray*)&(array))
1048 size_t elem_size,
const void *elem,
cx_compare_func2 cmp_func,
void *context);
1072 size_t elem_size,
const void *elem,
cx_compare_func2 cmp_func,
void *context);
1102 size_t elem_size,
const void *elem,
cx_compare_func2 cmp_func,
void *context);
1130 size_t elem_size,
size_t initial_capacity);
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
void cx_array_sort_(CxArray *array, size_t elem_size, cx_compare_func fn)
Sorts an array.
CxIterator cx_array_iterator_ptr_(CxArray *array)
Creates an iterator over the elements of an array containing pointers.
int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity)
Initializes an array by allocating memory.
size_t cx_array_binary_search_sup_c(const void *arr, size_t size, size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context)
Searches the smallest upper bound in a sorted array.
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.
size_t cx_array_binary_search_c(const void *arr, size_t size, size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context)
Searches an item in a sorted array.
int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity)
Copies the array to a new memory region.
CxIterator cx_array_iterator_(CxArray *array, size_t elem_size)
Creates an iterator over the elements of an array.
size_t cx_array_binary_search_inf_c(const void *arr, size_t size, size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context)
Searches the largest lower bound in a sorted array.
void cx_array_sort_c_(CxArray *array, size_t elem_size, cx_compare_func2 fn, void *context)
Sorts an array.
int cx_array_insert_sorted_c_(const CxAllocator *allocator, CxArray *array, size_t elem_size, const void *sorted_data, size_t n, cx_compare_func2 cmp_func, void *context, bool allow_duplicates)
Inserts sorted data into a sorted array.
const unsigned cx_array_swap_sbo_size
The maximum item size in an array list that fits into a stack buffer when swapped.
CxList * cxArrayListCreate(const CxAllocator *allocator, size_t elem_size, size_t initial_capacity)
Allocates an array list for storing elements with elem_size bytes each.
struct cx_array_s CxArray
Internal structure for arrays.
int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array, size_t elem_size, const void *sorted_data, size_t n, cx_compare_func cmp_func, bool allow_duplicates)
Inserts sorted data into a sorted array.
void cx_array_free_(const CxAllocator *allocator, CxArray *array)
Deallocates an array.
void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size)
Initializes an array with fixed size memory.
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.
void cx_array_remove_(CxArray *array, size_t elem_size, size_t index, size_t n, bool fast)
Removes elements from the array.
int cx_array_reserve_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity)
Changes the capacity of an array.
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.
void cx_array_qsort_c(void *array, size_t nmemb, size_t size, cx_compare_func2 fn, void *context)
An alternative to qsort_r() when that is not available on your platform.
int cx_array_insert_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t index, const void *other, size_t n)
Inserts data into an array.
void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2)
Swaps two array elements.
#define CX_MALLOC
The attributed function always returns freshly allocated memory.
Definition common.h:156
#define CX_DEALLOC(...)
Not supported in clang.
Definition common.h:172
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:289
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NODISCARD
Warn about discarded return value.
Definition common.h:256
#define CX_NONNULL_ARG(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
int(* cx_compare_func)(const void *left, const void *right)
A comparator function comparing two arbitrary values.
Definition compare.h:53
int(* cx_compare_func2)(const void *left, const void *right, void *data)
A comparator function comparing two arbitrary values.
Definition compare.h:60
struct cx_iterator_s CxIterator
Iterator type.
Definition iterator.h:144
Interface for list implementations.
struct cx_list_s CxList
Common type for all list implementations.
Definition list.h:179
void cxListFree(CxList *list)
Deallocates the memory of the specified list structure.
Internal structure for arrays.
Definition array_list.h:66
void * data
The array data.
Definition array_list.h:68
size_t capacity
The maximum number of elements.
Definition array_list.h:72
size_t size
The number of elements.
Definition array_list.h:70