ucx
UAP Common Extensions
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
array_list.h File Reference

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.
 
CxListcxArrayListCreate (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.
 

Detailed Description

Array list implementation.

Also provides several low-level functions for custom array list implementations.

Author
Mike Becker
Olaf Wintermann
Version
3.0

Macro Definition Documentation

◆ cxArrayListCreateSimple

#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.

Parameters
item_sizethe size of each element in bytes
initial_capacitythe initial number of elements the array can store
Returns
the created list

Function Documentation

◆ cx_array_copy()

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.

Parameters
targetthe target array
sizea pointer to the size of the target array
capacitya pointer to the target array's capacity - NULL if only the size shall be used to bound the array
indexthe index where the copied elements shall be placed
srcthe source array
elem_sizethe size of one element
elem_countthe number of elements to copy
reallocatorthe array re-allocator to use, or NULL if re-allocation shall not happen
Returns
zero on success, non-zero error code on failure

◆ cx_array_swap()

void cx_array_swap ( void *  arr,
size_t  elem_size,
size_t  idx1,
size_t  idx2 
)

Swaps two array elements.

Parameters
arrthe array
elem_sizethe element size
idx1index of first element
idx2index of second element

◆ cxArrayListCreate()

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.

Parameters
allocatorthe allocator for allocating the list memory (if NULL the cxDefaultAllocator will be used)
comparatorthe comparator for the elements (if NULL sort and find functions will not work)
item_sizethe size of each element in bytes
initial_capacitythe initial number of elements the array can store
Returns
the created list