|
| #define | ARRAY_SENTINEL 0x15bada55 |
| |
| #define | array_create(basic_type) ((basic_type *)(_array_create_helper(sizeof(basic_type), 1))) |
| | Creates a new dynamic array of ‘basic_type’. More...
|
| |
| #define | array_create_size(basic_type, capacity) ((basic_type *)(_array_create_helper(sizeof(basic_type), capacity))) |
| | Creates a new dynamic array of ‘basic_type’ with an initial capacity. More...
|
| |
| #define | array_resize(ptr_array, new_size) (_array_resize_helper((void **)(ptr_array), sizeof((ptr_array)[0][0]), new_size)) |
| | Resizes the array to accomodate new_size elements. More...
|
| |
| #define | array_grow(ptr_array) (*(__typeof__((ptr_array)[0]))_array_grow_helper((void **)(ptr_array), sizeof((ptr_array)[0][0]))) |
| | Increases the number of elements by one and returns the last element. More...
|
| |
| #define | array_push_back(ptr_array, element) do array_grow(ptr_array) = element; while (0) |
| | Adds a new element at the end of the array. More...
|
| |
| #define | array_erase(ptr_array, first, last) (_array_erase_helper((void **)(ptr_array), sizeof((ptr_array)[0][0]), (void *)(first), (void *)(last))) |
| | Erases elements in interval [first, last). More...
|
| |
| #define | array_shrink(ptr_array) (_array_shrink_helper((void **)(ptr_array), sizeof((ptr_array)[0][0]))) |
| | Shrinks memory to fit only ‘size’ elements. More...
|
| |
| #define | array_free(ptr_array) _array_free_helper((void *)(ptr_array)) |
| | Frees memory allocated and sets array to NULL. More...
|
| |
| #define | array_reserved(array) (_array_private_container(array)->_reserved) |
| | Returns number of elements reserved. More...
|
| |
| #define | array_begin(array) (array) |
| | Returns a pointer to the beginning of the reserved memory space. More...
|
| |
| #define | array_end(array) ((array) + array_size(array)) |
| | Returns a pointer to the end of the reserved memory space. More...
|
| |
| #define | array_front(ptr_array) (*array_begin(ptr_array)) |
| | Returns the first element in the array. More...
|
| |
| #define | array_back(ptr_array) (*(array_end(ptr_array) - 1)) |
| | Returns the last element in the array. More...
|
| |
| #define | array_copy(basic_type, ptr_array) ((basic_type *)(_array_copy_helper(sizeof(basic_type), (void *)(ptr_array)))) |
| | Returns a shallow copy of the input array.
More...
|
| |
Provides macros to work with dynamic arrays.
- Note
- Except were noted, macros do not have side effects from expansions.
Usage example:
static my_type *my_array = NULL;
while (need_fill)
need_fill = fill_array_member( &
array_grow( &my_array ) );
do_stuff( &my_array[i] );
my_array = NULL;
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_shrink(ptr_array)
Shrinks memory to fit only ‘size’ elements.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition in file array.h.