Dynarr 0.0.1
C dynamic array
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages

Access and manipulate elements of a dynarr. More...

Collaboration diagram for Elements:

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)
 

Detailed Description

Access and manipulate elements of a dynarr.

Function Documentation

◆ dynarr_clear()

void dynarr_clear ( dynarr_t *const dynarr)

Clean (reset) contents of the dynarr.

Drops amount of stored elements to zero, while not affecting a capacity.

Parameters
[in]dynarrInstance of a dynarr.

Definition at line 143 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_get()

void * dynarr_get ( const dynarr_t *const dynarr,
const size_t index )

Returns pointer for the element at index.

Parameters
[in]dynarrPointer to a dynarr instance.
[in]indexDenotes an element to be accessed.
Returns
A pointer to a dynarr element at index.

Definition at line 171 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_set()

void dynarr_set ( dynarr_t *const dynarr,
const size_t index,
const void * value )

Sets element at given index to a value.

Parameters
[in]dynarrPointer to a dynarr instance.
[in]indexDenotes an element to be overriden by value.
[in]valueValue to be stored at the index.

Definition at line 179 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_set_zero()

void dynarr_set_zero ( dynarr_t *const dynarr,
const size_t index )

Sets element at given index to a zero value.

Parameters
[in]dynarrPointer to a dynarr instance.
[in]indexDenotes an element to be zeroed.

Definition at line 188 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_first()

void * dynarr_first ( const dynarr_t *const dynarr)

Access first element of a dynarr.

Function assumes that element exists. Calling this function when

size == 0

results in undefined behavior.

Parameters
[in]dynarrInstance of a dynarr.
Returns
Pointer for the first element in the array, assuming that array contains at least one element.

Definition at line 196 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_last()

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

size == 0

results in undefined behavior.

Parameters
[in]dynarrInstance of a dynarr.
Returns
Pointer for the last element in the array, assuming that array contains at least one element.

Definition at line 204 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_append()

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.

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]valueValue to be appended.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_GROW_ERROR]

Definition at line 239 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_prepend()

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.

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]valueValue to be appended.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_GROW_ERROR]

Definition at line 248 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_pop_back()

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.

Note
Wont fail if there is nothing to remove.
Parameters
[in,out]dynarrReference to a dynarr pointer.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_SHRINK_ERROR]

Definition at line 257 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_pop_front()

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.

Note
Wont fail if there is nothing to remove.
Parameters
[in,out]dynarrReference to a dynarr pointer.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_SHRINK_ERROR]

Definition at line 264 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_insert()

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.

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]indexDesignating index of a new element.
[in]valueLocation that stores elements value to be stored.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_GROW_ERROR]

Definition at line 271 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_remove()

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.

Note
operation wont fail if index exceeds size.
Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]indexDesignating index of an element to remove.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_SHRINK_ERROR]

Definition at line 381 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_remove_range()

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.

Note
operation wont fail if index exceeds size.
Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]indexDesignating index of ranges first element.
[in]amountLength of the range to remove.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_SHRINK_ERROR]

Definition at line 388 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_remove_if()

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.

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]predicateCallback that selects matching element for removal.
[in]limitMaximum elements to remove in total.
paramUser defined param that is passed to predicate.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_SHRINK_ERROR]

Definition at line 402 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_binary_merge()

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.

Parameters
[in]firstFirst sorted array.
[in]secondSecond sorted array.
[in]cmpCallback for element comparison.
paramParameter that wll be passed to a cmp callback.
Returns
New dynarr with merged data or NULL on failure.

Definition at line 423 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_spread_insert()

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.

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]indexDesignating index of ranges first element.
[in]amountLength of the range to spread value on.
[in]valueValue to be spread inserted.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_GROW_ERROR]

Definition at line 290 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_binary_find_insert_place()

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.

Parameters
[in]dynarrInstance of a dynarr.
[in]valueValue for new element to be inserted.
[in]cmpCompare callback.
paramParameter that will be passed to callback.
Returns
Index of insert position for new element.

Definition at line 310 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_binary_insert()

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)

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]valueValue for new element to be inserted.
[in]cmpCompare callback.
paramParameter that will be passed to callback.
[out]indexOptional. Index of new element will be stored at this address. If NULL provided, then function will ignore it.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_GROW_ERROR]

Definition at line 323 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_binary_insert_uniq()

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.

See also
dynarr_binary_insert

Definition at line 343 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_binary_reserve()

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.

Parameters
[in,out]dynarrReference to a dynarr pointer.
[in]valueReferenced value for comparison.
[in]cmpCompare callback.
paramParameter that will be passed to callback.
[out]indexIndex of new element will be stored at this address.
Returns
Status of the operation: [DYNARR_SUCCESS | DYNARR_GROW_ERROR]

Definition at line 359 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_foreach()

int dynarr_foreach ( const dynarr_t *const dynarr,
const foreach_t func,
void *const param )
See also
vector_foreach

Definition at line 506 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_aggregate()

int dynarr_aggregate ( const dynarr_t *const dynarr,
const aggregate_t func,
void *const acc,
void *const param )
See also
vector_aggregate

Definition at line 516 of file dynarr.c.

Here is the call graph for this function:

◆ dynarr_transform()

int dynarr_transform ( dynarr_t *const dynarr,
const transform_t func,
void *const param )
See also
vector_transform

Definition at line 528 of file dynarr.c.

Here is the call graph for this function: