7#ifndef __UTILS_ARRAYS_H__
8#define __UTILS_ARRAYS_H__
10#define array_index_of(_array, size, element) \
11 _array_index_of ((void **) _array, size, (void *) element)
16#define array_append(_array, size, element) (_array)[(size)++] = element;
18#define array_double_append(arr1, arr2, size, el1, el2) \
27#define array_insert(_array, size, pos, element) \
28 for (int ii = size; ii > pos; ii--) \
30 _array[ii] = _array[ii - 1]; \
32 _array[pos] = element; \
40#define array_double_insert(arr1, arr2, size, pos, el1, el2) \
41 for (int ii = size; ii > pos; ii--) \
43 arr1[ii] = arr1[ii - 1]; \
44 arr2[ii] = arr2[ii - 1]; \
70_array_double_size_if_full (
85#define array_double_size_if_full(_array, count, size, type) \
86 ((size_t) (count) < (size_t) (size) \
88 : _array_double_size_if_full ( \
89 (void **) &_array, (size_t) (count), &size, sizeof (type)))
95#define array_delete(_array, size, element) \
96 for (size_t ii = 0; ii < (size_t) size; ii++) \
98 if ((void *) _array[ii] == (void *) element) \
101 for (size_t jj = ii; jj < (size_t) size; jj++) \
103 _array[jj] = _array[jj + 1]; \
113#define array_delete_confirm(_array, size, element, confirm) \
115 for (size_t ii = 0; ii < (size_t) size; ii++) \
117 if ((void *) _array[ii] == (void *) element) \
121 for (size_t jj = ii; jj < (size_t) size; jj++) \
123 _array[jj] = _array[jj + 1]; \
133#define array_delete_primitive(_array, size, element) \
134 for (int ii = 0; ii < size; ii++) \
136 if (_array[ii] == element) \
139 for (int jj = ii; jj < size; jj++) \
141 _array[jj] = _array[jj + 1]; \
151#define array_delete_return_pos(_array, size, element, pos) \
152 for (int ii = 0; ii < size; ii++) \
154 if (_array[ii] == element) \
158 for (int jj = ii; jj < size; jj++) \
160 _array[jj] = _array[jj + 1]; \
172#define array_double_delete(array1, array2, size, element1, element2) \
173 for (int ii = 0; ii < size; ii++) \
175 if (array1[ii] == element1) \
178 for (int jj = ii; jj < size; jj++) \
180 array1[jj] = array1[jj + 1]; \
181 array2[jj] = array2[jj + 1]; \
187#define array_contains_cmp(_array, size, element, cmp, equal_val, pointers) \
188 _array_contains_cmp ( \
189 (void **) _array, size, (void *) element, (int (*) (void *, void *)) cmp, \
196#define array_contains(_array, size, element) \
197 _array_contains ((void **) _array, size, (void *) element)
199#define array_dynamic_swap(arr1, sz1, arr2, sz2) \
200 _array_dynamic_swap ( \
201 (void ***) arr1, (size_t *) sz1, (void ***) arr2, (size_t *) sz2)
212_array_dynamic_swap (
void *** arr1,
size_t * sz1,
void *** arr2,
size_t * sz2);
215array_contains_int (
int * _array,
int size,
int element)
217 for (
int i = 0; i < size; i++)
219 if (_array[i] == element)
233array_shuffle (
void * _array,
size_t n,
size_t size);
240NONNULL WARN_UNUSED_RESULT
int
241_array_contains (
void ** _array,
int size,
void * element);
259 int (*cmp) (
void *,
void *),
268_array_index_of (
void ** _array,
int size,
void * element);
271array_sort_alphabetically (
char ** _array,
int size,
int case_sensitive);
274array_sort_float (
float * _array,
int size);
277array_sort_long (
long * _array,
int size);
279#define array_get_count(_arr, _sz) _array_get_count ((void **) _arr, _sz)
285_array_get_count (
void ** _array,
size_t element_size);