array.h
Exposes functions for handling arrays, fixed-length composite data-structures, with elements accessible by index.
- Author: Edward Jones
- Date: 2021-09-17
dest_arr
Destroy an array object.
- Param
arr
: Pointer to the array to destroy - Param
ed
: Element destructor function or NULL
void dest_arr(Array* arr, func_sig(void, ed, (void*)));
dest_arr_iter
Destror an array iterator.
- Param
iter
: Pointer to the iterator to destroy
void dest_arr_iter(ArrayIter* iter);
get_arrv
Get array value at a given index.
- Param
ret
: Pointer to a Maybe type to populate with the result - Param
arr
: Pointer to the array containing the required value - Param
idx
: Index of the array element to find
void get_arrv(Maybe* ret, Array* arr, size_t idx);
iter_arr
Iterate once over an array.
- Param
v
: Pointer to the return value - Param
iter
: Pointer to the array iterator to use
Returns: True iff a value was successfully written to v
, false iff there were no elements left
bool iter_arr(void** v, ArrayIter* iter);
make_arr
Make an array object, a block of memory of finite length.
- Param
arr
: Pointer to the array to initialise. - Param
cnt
: Length of the array
Returns: True iff memory allocation was successful
bool make_arr(Array* arr, size_t cnt);
make_arr_iter
Make an array iterator.
- Param
iter
: Pointer to the iterator to make - Param
arr
: Pointer to the array to iterate over
void make_arr_iter(ArrayIter* iter, Array* arr);
set_arrv
Set the value of an array at a particular index.
- Param
arr
: Pointer to the array to modify - Param
idx
: Index of the value to change - Param
val
: Value to assign to arr[idx]
Returns: Returns true iff idx
is a valid index of arr
bool set_arrv(Array* arr, size_t idx, void* val);