ucx
UAP Common Extensions
|
Array list implementation. More...
#include "list.h"
Go to the source code of this file.
Data Structures | |
struct | cx_array_reallocator_s |
Defines a reallocation mechanism for arrays. More... | |
Macros | |
#define | cxArrayListCreateSimple(item_size, initial_capacity) cxArrayListCreate(NULL, NULL, item_size, initial_capacity) |
Allocates an array list for storing elements with item_size bytes each. | |
Enumerations | |
enum | cx_array_copy_result { CX_ARRAY_COPY_SUCCESS , CX_ARRAY_COPY_REALLOC_NOT_SUPPORTED , CX_ARRAY_COPY_REALLOC_FAILED } |
Return codes for cx_array_copy(). | |
Functions | |
enum cx_array_copy_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) |
Copies elements from one array to another. | |
void | cx_array_swap (void *arr, size_t elem_size, size_t idx1, size_t idx2) |
Swaps two array elements. | |
CxList * | cxArrayListCreate (CxAllocator const *allocator, cx_compare_func comparator, size_t item_size, size_t initial_capacity) |
Allocates an array list for storing elements with item_size bytes each. | |
Array list implementation.
Also provides several low-level functions for custom array list implementations.
#define cxArrayListCreateSimple | ( | item_size, | |
initial_capacity | |||
) | cxArrayListCreate(NULL, NULL, item_size, initial_capacity) |
Allocates an array list for storing elements with item_size
bytes each.
The list will use the cxDefaultAllocator and NO compare function. If you want to call functions that need a compare function, you have to set it immediately after creation or use cxArrayListCreate().
If item_size
is CX_STORE_POINTERS, the created list will be created as if cxListStorePointers() was called immediately after creation.
item_size | the size of each element in bytes |
initial_capacity | the initial number of elements the array can store |
enum cx_array_copy_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 | ||
) |
Copies elements from one array to another.
The elements are copied to the target
array at the specified index
, overwriting possible elements. The index
does not need to be in range of the current array size
. If the new index plus the number of elements added would extend the array's size, and capacity
is not NULL
, the remaining capacity is used.
If the capacity is insufficient to hold the new data, a reallocation attempt is made, unless the allocator is set to NULL
, in which case this function ultimately returns a failure.
target | the target array |
size | a pointer to the size of the target array |
capacity | a pointer to the target array's capacity - NULL if only the size shall be used to bound the array |
index | the index where the copied elements shall be placed |
src | the source array |
elem_size | the size of one element |
elem_count | the number of elements to copy |
reallocator | the array re-allocator to use, or NULL if re-allocation shall not happen |
void cx_array_swap | ( | void * | arr, |
size_t | elem_size, | ||
size_t | idx1, | ||
size_t | idx2 | ||
) |
Swaps two array elements.
arr | the array |
elem_size | the element size |
idx1 | index of first element |
idx2 | index of second element |
CxList * cxArrayListCreate | ( | CxAllocator const * | allocator, |
cx_compare_func | comparator, | ||
size_t | item_size, | ||
size_t | initial_capacity | ||
) |
Allocates an array list for storing elements with item_size
bytes each.
If item_size
is CX_STORE_POINTERS, the created list will be created as if cxListStorePointers() was called immediately after creation.
allocator | the allocator for allocating the list memory (if NULL the cxDefaultAllocator will be used) |
comparator | the comparator for the elements (if NULL sort and find functions will not work) |
item_size | the size of each element in bytes |
initial_capacity | the initial number of elements the array can store |