#ifndef UCX_ARRAY_LIST_H
#define UCX_ARRAY_LIST_H
#include "list.h"
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned cx_array_swap_sbo_size;
#define CX_ARRAY_DECLARE(type, name) \
type * name; \
size_t name##_size; \
size_t name##_capacity
#define cx_array_initialize(array, capacity) \
array##_capacity = capacity; \
array##_size =
0; \
array = malloc(
sizeof(array[
0]) * capacity)
struct cx_array_reallocator_s {
void *(*realloc)(
void *array,
size_t capacity,
size_t elem_size,
struct cx_array_reallocator_s *alloc
);
void *ptr1;
void *ptr2;
size_t int1;
size_t int2;
};
extern struct cx_array_reallocator_s *cx_array_default_reallocator;
enum cx_array_result {
CX_ARRAY_SUCCESS,
CX_ARRAY_REALLOC_NOT_SUPPORTED,
CX_ARRAY_REALLOC_FAILED,
};
enum cx_array_result cx_array_copy(
void **target,
size_t *size,
size_t *capacity,
size_t index,
void const *src,
size_t elem_size,
size_t elem_count,
struct cx_array_reallocator_s *reallocator
) __attribute__((__nonnull__(
1,
2,
5)));
#define cx_array_simple_copy(array, index, src, count) \
cx_array_copy((
void**)&(array), &(array##_size), &(array##_capacity), \
index, src,
sizeof((array)[
0]), count, cx_array_default_reallocator)
#define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \
cx_array_copy((
void**)(target), size, capacity, *(size), elem, elem_size,
1, reallocator)
#define cx_array_simple_add(array, elem) \
cx_array_simple_copy(array, array##_size, &(elem),
1)
void cx_array_swap(
void *arr,
size_t elem_size,
size_t idx1,
size_t idx2
) __attribute__((__nonnull__));
CxList *cxArrayListCreate(
CxAllocator
const *allocator,
cx_compare_func comparator,
size_t elem_size,
size_t initial_capacity
);
#define cxArrayListCreateSimple(elem_size, initial_capacity) \
cxArrayListCreate(
NULL,
NULL, elem_size, initial_capacity)
#ifdef __cplusplus
}
#endif
#endif