Dynarr 0.0.1
C dynamic array
|
Access and manipulate elements of a dynarr. More...
Functions | |
char * | vector_data (const vector_t *const vector) |
void * | vector_get (const vector_t *const vector, const size_t index) |
void | vector_set (vector_t *const vector, const size_t index, const void *const value) |
void | vector_set_zero (vector_t *const vector, const size_t index) |
void | vector_copy (const vector_t *const vector, char *dest, const size_t offset, const size_t length) |
void | vector_move (const vector_t *const vector, char *dest, const size_t offset, const size_t length) |
void | vector_part_copy (const vector_t *const vector, char *dest, const size_t offset, const size_t length, const size_t part_offset, const size_t part_length) |
void | vector_spread (vector_t *const vector, const size_t index, const size_t amount) |
void | vector_shift (vector_t *const vector, const size_t offset, const size_t length, const ssize_t shift) |
void | vector_swap (vector_t *const vector, const size_t index_a, const size_t index_b) |
int | vector_foreach (const vector_t *const vector, const size_t limit, const foreach_t func, void *const param) |
int | vector_aggregate (const vector_t *const vector, const size_t limit, const aggregate_t func, void *const acc, void *const param) |
int | vector_transform (vector_t *const vector, const size_t limit, const transform_t func, void *const param) |
void | dynarr_clear (dynarr_t *const dynarr) |
Clean (reset) contents of the dynarr. | |
void * | dynarr_get (const dynarr_t *const dynarr, const size_t index) |
Returns pointer for the element at index . | |
void | dynarr_set (dynarr_t *const dynarr, const size_t index, const void *value) |
Sets element at given index to a value . | |
void | dynarr_set_zero (dynarr_t *const dynarr, const size_t index) |
Sets element at given index to a zero value. | |
void * | dynarr_first (const dynarr_t *const dynarr) |
Access first element of a dynarr. | |
void * | dynarr_last (const dynarr_t *const dynarr) |
Access last element if a dynarr. | |
dynarr_status_t | dynarr_append (dynarr_t **const dynarr, const void *const value) |
Appends an element to the tail of a dynarr. | |
dynarr_status_t | dynarr_prepend (dynarr_t **const dynarr, const void *const value) |
Prepends an element to the head of a dynarr. | |
dynarr_status_t | dynarr_pop_back (dynarr_t **const dynarr) |
Removes an element from the tail of a dynarr. | |
dynarr_status_t | dynarr_pop_front (dynarr_t **const dynarr) |
Removes an element from the head of a dynarr. | |
dynarr_status_t | dynarr_insert (dynarr_t **const dynarr, const size_t index, const void *value) |
Inserts new element into a dynarr. | |
dynarr_status_t | dynarr_remove (dynarr_t **const dynarr, const size_t index) |
Removes an element from a dynarr. | |
dynarr_status_t | dynarr_remove_range (dynarr_t **const dynarr, const size_t index, const size_t amount) |
Removes range of elements from a dynarr. | |
dynarr_status_t | dynarr_remove_if (dynarr_t **const dynarr, const predicate_t predicate, const size_t limit, void *const param) |
Removes limit elements that match predicate. | |
dynarr_t * | dynarr_binary_merge (const dynarr_t *const first, const dynarr_t *const second, const compare_t cmp, void *const param) |
Non-destructive merge of two sorted dynarrs. | |
dynarr_status_t | dynarr_spread_insert (dynarr_t **const dynarr, const size_t index, const size_t amount, const void *const value) |
Insert single value as an element range. | |
size_t | dynarr_binary_find_insert_place (const dynarr_t *const dynarr, const void *const value, const compare_t cmp, void *param) |
Binary search for binary insert support. | |
dynarr_status_t | dynarr_binary_insert (dynarr_t **const dynarr, const void *const value, const compare_t cmp, void *const param, size_t *const index) |
Binary insert. | |
dynarr_status_t | dynarr_binary_insert_uniq (dynarr_t **const dynarr, const void *const value, const compare_t cmp, void *const param, size_t *const index) |
Binary unique insert. | |
dynarr_status_t | dynarr_binary_reserve (dynarr_t **const dynarr, const void *const value, const compare_t cmp, void *const param, size_t *const index) |
Reserve space for an element in sorted dynarr. | |
int | dynarr_foreach (const dynarr_t *const dynarr, const foreach_t func, void *const param) |
int | dynarr_aggregate (const dynarr_t *const dynarr, const aggregate_t func, void *const acc, void *const param) |
int | dynarr_transform (dynarr_t *const dynarr, const transform_t func, void *const param) |
Access and manipulate elements of a dynarr.
void dynarr_clear | ( | dynarr_t *const | dynarr | ) |
void * dynarr_get | ( | const dynarr_t *const | dynarr, |
const size_t | index ) |
void dynarr_set | ( | dynarr_t *const | dynarr, |
const size_t | index, | ||
const void * | value ) |
void dynarr_set_zero | ( | dynarr_t *const | dynarr, |
const size_t | index ) |
void * dynarr_first | ( | const dynarr_t *const | dynarr | ) |
Access first element of a dynarr.
Function assumes that element exists. Calling this function when
results in undefined behavior.
[in] | dynarr | Instance of a dynarr. |
Definition at line 196 of file dynarr.c.
void * dynarr_last | ( | const dynarr_t *const | dynarr | ) |
Access last element if a dynarr.
Function assumes that dynarr is not empty. Calling this function when
results in undefined behavior.
[in] | dynarr | Instance of a dynarr. |
Definition at line 204 of file dynarr.c.
dynarr_status_t dynarr_append | ( | dynarr_t **const | dynarr, |
const void *const | value ) |
Appends an element to the tail of a dynarr.
Probes size-capacity ratio if reaches grow threshold. If it does, then grow allocation. Appends and element to the end and inc size by one.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | value | Value to be appended. |
Definition at line 239 of file dynarr.c.
dynarr_status_t dynarr_prepend | ( | dynarr_t **const | dynarr, |
const void *const | value ) |
Prepends an element to the head of a dynarr.
Probes size-capacity ratio if reaches grow threshold. If it does, then grow allocation. Appends and element to the end and inc size by one.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | value | Value to be appended. |
Definition at line 248 of file dynarr.c.
dynarr_status_t dynarr_pop_back | ( | dynarr_t **const | dynarr | ) |
Removes an element from the tail of a dynarr.
Decrements size by one. Probes size-capacity ratio if reaches shrink threshold. If it does, then shrinks array allocation.
[in,out] | dynarr | Reference to a dynarr pointer. |
Definition at line 257 of file dynarr.c.
dynarr_status_t dynarr_pop_front | ( | dynarr_t **const | dynarr | ) |
Removes an element from the head of a dynarr.
Decrements size by one. Shifts all elements to the left by one position. Probes size-capacity ratio if reaches shrink threshold. If it does, then shrinks array allocation.
[in,out] | dynarr | Reference to a dynarr pointer. |
Definition at line 264 of file dynarr.c.
dynarr_status_t dynarr_insert | ( | dynarr_t **const | dynarr, |
const size_t | index, | ||
const void * | value ) |
Inserts new element into a dynarr.
Inserts an element at given index
, after shifting all elements from that index
forward.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | index | Designating index of a new element. |
[in] | value | Location that stores elements value to be stored. |
Definition at line 271 of file dynarr.c.
dynarr_status_t dynarr_remove | ( | dynarr_t **const | dynarr, |
const size_t | index ) |
Removes an element from a dynarr.
An element at given index
will be removed by shifting all elements from that index
backwards and decrementing the size.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | index | Designating index of an element to remove. |
Definition at line 381 of file dynarr.c.
dynarr_status_t dynarr_remove_range | ( | dynarr_t **const | dynarr, |
const size_t | index, | ||
const size_t | amount ) |
Removes range of elements from a dynarr.
Element range at given index
, amount
elements long will be removed by shifting all elements from that index
backwards by amount
and subtracting that amount
from size.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | index | Designating index of ranges first element. |
[in] | amount | Length of the range to remove. |
Definition at line 388 of file dynarr.c.
dynarr_status_t dynarr_remove_if | ( | dynarr_t **const | dynarr, |
const predicate_t | predicate, | ||
const size_t | limit, | ||
void *const | param ) |
Removes limit
elements that match predicate.
Element removal performed form tail to head of the array in order to reduce memory movement during the process. Array reallocation performed at most once per call.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | predicate | Callback that selects matching element for removal. |
[in] | limit | Maximum elements to remove in total. |
param | User defined param that is passed to predicate. |
Definition at line 402 of file dynarr.c.
dynarr_t * dynarr_binary_merge | ( | const dynarr_t *const | first, |
const dynarr_t *const | second, | ||
const compare_t | cmp, | ||
void *const | param ) |
Non-destructive merge of two sorted dynarrs.
Creates empty dynarr with options of the first
and feeds it with the data from both (sorted) dynarrs in order. An order is defined by cmp
callback. In case of allocation error NULL
will be returned.
[in] | first | First sorted array. |
[in] | second | Second sorted array. |
[in] | cmp | Callback for element comparison. |
param | Parameter that wll be passed to a cmp callback. |
NULL
on failure. Definition at line 423 of file dynarr.c.
dynarr_status_t dynarr_spread_insert | ( | dynarr_t **const | dynarr, |
const size_t | index, | ||
const size_t | amount, | ||
const void *const | value ) |
Insert single value as an element range.
Inserts range of value
copys amount
elements long at given index
.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | index | Designating index of ranges first element. |
[in] | amount | Length of the range to spread value on. |
[in] | value | Value to be spread inserted. |
Definition at line 290 of file dynarr.c.
size_t dynarr_binary_find_insert_place | ( | const dynarr_t *const | dynarr, |
const void *const | value, | ||
const compare_t | cmp, | ||
void * | param ) |
Binary search for binary insert support.
Returns index of the insert position for a new value that satisfies cmp
ordering. Function never fails.
[in] | dynarr | Instance of a dynarr. |
[in] | value | Value for new element to be inserted. |
[in] | cmp | Compare callback. |
param | Parameter that will be passed to callback. |
Definition at line 310 of file dynarr.c.
dynarr_status_t dynarr_binary_insert | ( | dynarr_t **const | dynarr, |
const void *const | value, | ||
const compare_t | cmp, | ||
void *const | param, | ||
size_t *const | index ) |
Binary insert.
Works only if previous elements that contained with-in the vector are ordered in same way. (Allocation may fail, so returning operation status)
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | value | Value for new element to be inserted. |
[in] | cmp | Compare callback. |
param | Parameter that will be passed to callback. | |
[out] | index | Optional. Index of new element will be stored at this address. If NULL provided, then function will ignore it. |
Definition at line 323 of file dynarr.c.
dynarr_status_t dynarr_binary_insert_uniq | ( | dynarr_t **const | dynarr, |
const void *const | value, | ||
const compare_t | cmp, | ||
void *const | param, | ||
size_t *const | index ) |
Binary unique insert.
Same as dynarr_binary_insert except ignores duplicated values.
Definition at line 343 of file dynarr.c.
dynarr_status_t dynarr_binary_reserve | ( | dynarr_t **const | dynarr, |
const void *const | value, | ||
const compare_t | cmp, | ||
void *const | param, | ||
size_t *const | index ) |
Reserve space for an element in sorted dynarr.
Similar to insert except it stores no data, leaving slot in undefined state. Usefull when element is too large and needs to be constructed in-place, or when exact contents of an element yet unspecified.
[in,out] | dynarr | Reference to a dynarr pointer. |
[in] | value | Referenced value for comparison. |
[in] | cmp | Compare callback. |
param | Parameter that will be passed to callback. | |
[out] | index | Index of new element will be stored at this address. |
Definition at line 359 of file dynarr.c.
int dynarr_foreach | ( | const dynarr_t *const | dynarr, |
const foreach_t | func, | ||
void *const | param ) |
Definition at line 506 of file dynarr.c.
int dynarr_aggregate | ( | const dynarr_t *const | dynarr, |
const aggregate_t | func, | ||
void *const | acc, | ||
void *const | param ) |
Definition at line 516 of file dynarr.c.
int dynarr_transform | ( | dynarr_t *const | dynarr, |
const transform_t | func, | ||
void *const | param ) |
Definition at line 528 of file dynarr.c.