au-array
au-array is a simple array class in C.
Types
typedef struct _au_array
{
size_t length; /* number of elements in the array */
size_t element_size; /* size of every element in the array */
void *elements; /* elements of the array */
} au_array;
typedef void (*au_array_element_handler)(void *element)
- a function pointer type for element processing functions
Methods
Creating Arrays
-
au_array* au_array_create()
- creates an empty array -
au_array* au_array_create_of_length(size_t count, size_t size)
- creates an array withcount
elements ofsize
-
au_array* au_array_create_with_array(au_array *array)
- creates a copy from anotherarray
-
au_array* au_array_create_with_buffer(void *buffer, size_t count, size_t size)
: creates an array from abuffer
withcount
elements ofsize
Deallocating Arrays
-
void au_array_free(au_array *array)
- deallocates thearray
-
void au_array_free_with_elements(au_array *array)
- deallocates every item in thearray
with thearray
itself -
void au_array_free_with_element_handler(au_array *array, au_array_element_handler handler)
: calls a deallocationhandler
for every item in thearray
before deleting thearray
itself
Querying Metadata
-
bool au_array_is_empty(au_array *array)
- checks if thearray
is empty -
size_t au_array_length(au_array *array)
- gets the length of thearray
-
size_t au_array_size(au_array *array)
- gets the size of thearray
-
size_t au_array_element_size(au_array *array)
- gets the element size of thearray
Querying an Array
-
void *au_array_first(au_array *array)
- gets the first element of thearray
or returnNULL
if empty -
void *au_array_last(au_array *array)
- gets the last element of thearray
or returnNULL
if empty -
void *au_array_get(au_array *array, size_t index)
- gets an element atindex
from thearray
or returnNULL
if theindex
is out of range
Contributors
- Grigorii Derzhanskii
- Ruslan Dzhumakaliev
- Dmitrii Toksaitov