![]() |
Maestro Audio Framework
v 1.0
NXP Semiconductors
|
vector data type implementation More...
#include <stdbool.h>
Data Structures | |
struct | Vector |
struct | VectorIter |
Functions | |
VECTOR FUNCTION PROTOTYPES | |
Vector * | vector_create (const uint32_t data_sz, uint32_t cap_init) |
Create a vector with minimal space. More... | |
void | vector_destroy (Vector *vt) |
Destroys the vector and frees the internal memory. More... | |
uint32_t | vector_capacity (const Vector *vt) |
Returns the capacity of a vector. More... | |
uint32_t | vector_size (const Vector *vt) |
Returns the size of a vector. More... | |
bool | vector_is_empty (const Vector *vt) |
Check if a vector is empty. More... | |
int | vector_clear (Vector *vt) |
Clear all the data in a vector. More... | |
int | vector_reserve (Vector *vt, const uint32_t size) |
Increases the memory allocation for a vector to be able to contain 'size' data entries. More... | |
int | vector_pushback (Vector *vt, const void *data) |
Pushes data to the end of a vector. More... | |
int | vector_popback (Vector *vt, void *data) |
Remove the data entry at the end of a vector and return its contents. More... | |
int | vector_at (const Vector *vt, const uint32_t index, void *data) |
Get data from the vector using the index of a data member. More... | |
int | vector_assign (const Vector *vt, const uint32_t index, const void *data) |
Assign data to a vector using an index, replacing previous contents. More... | |
int | vector_insert_at (Vector *vt, const uint32_t index, const void *data) |
Insert data to a vector using an index. More... | |
int | vector_remove_at (Vector *vt, const uint32_t index) |
Remove data from a vector using an index. More... | |
int | vector_swap (const Vector *vt, const uint32_t a, const uint32_t b) |
Swap the contents of two data entries in a vector. More... | |
VectorIter | vector_iter_begin (const Vector *vt) |
Get the iterator for the first data entry of a vector. More... | |
VectorIter | vector_iter_end (const Vector *vt) |
Get the iterator for the end of a vector. More... | |
VectorIter | vector_iter_next (VectorIter iter) |
Get the next iterator in a vector. More... | |
VectorIter | vector_iter_prev (const Vector *vt, VectorIter iter) |
Get the previous iterator in a vector. More... | |
bool | vector_iter_equal (const VectorIter a, const VectorIter b) |
Compare two iterators for equality. More... | |
int | vector_iter_at (const Vector *vt, VectorIter iter, uint32_t *at) |
Get the index of the data entry an iterator is pointing to. More... | |
void * | vector_iter_node (const VectorIter iter) |
Get the pointer to the data entry in a vector indicated by the iterator. More... | |
int | vector_iter_value (const Vector *vt, VectorIter iter, void *data) |
Get the data from the entry indicated by the iterator. More... | |
Vector* vector_create | ( | const uint32_t | data_sz, |
uint32_t | cap_init | ||
) |
The vector will allocate initial memory using this formula: VECTOR_SIZE_MIN * data_sz
data_sz | Size of each data member in vector |
cap_init | Initial capacity size of the created vector, if this parameter is set to 0, then a default minimal capacity is used. |
void vector_destroy | ( | Vector * | vt | ) |
vt | Pointer to a vector |
uint32_t vector_capacity | ( | const Vector * | vt | ) |
This value is how many data entries can be stored in the memory currently allocated for this vector.
vt | Pointer to a vector |
uint32_t vector_size | ( | const Vector * | vt | ) |
The size is the number of data entries saved in a vector.
vt | Pointer to a vector |
bool vector_is_empty | ( | const Vector * | vt | ) |
vt | Pointer to a vector |
int vector_clear | ( | Vector * | vt | ) |
Sets the vector capacity to default minimal, and sets size to 0. Memory will be deleted only if SHRINK_SIZE_AFTER_DATA_REMOVE is defined.
vt | Pointer to a vector |
ERRCODE_NO_ERROR | No error |
ERRCODE_INVALID_ARGUMENT | Parameter vt is NULL |
ERRCODE_OUT_OF_MEMORY | Reallocation of memory failed |
int vector_reserve | ( | Vector * | vt, |
const uint32_t | size | ||
) |
The new capacity will be the larger of the former capacity or the new size request.
vt | Pointer to a vector |
size | Amount of data space required |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector is NULL |
ERRCODE_OUT_OF_MEMORY | Not enough memory |
int vector_pushback | ( | Vector * | vt, |
const void * | data | ||
) |
If there is not enough space, the vector will expand.
vt | Pointer to a vector |
data | Pointer to the data |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector is NULL or data is NULL |
ERRCODE_OUT_OF_MEMORY | Not enough memory |
int vector_popback | ( | Vector * | vt, |
void * | data | ||
) |
Memory will be deleted only if SHRINK_SIZE_AFTER_DATA_REMOVE is defined.
vt | Pointer to a vector |
data | pointer to memory block for the returned data (allocated by the caller) |
int vector_at | ( | const Vector * | vt, |
const uint32_t | index, | ||
void * | data | ||
) |
vt | pointer to a vector |
index | data index in a vector |
data | pointer to memory block for the returned data (allocated by the caller) |
int vector_assign | ( | const Vector * | vt, |
const uint32_t | index, | ||
const void * | data | ||
) |
int vector_insert_at | ( | Vector * | vt, |
const uint32_t | index, | ||
const void * | data | ||
) |
The size of the vector will increase and the data after the index will move up one.
vt | Pointer to a vector |
index | Data index in a vector. Must be less than the vector size |
data | Pointer to the data |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector is NULL or data is NULL or index out of range |
int vector_remove_at | ( | Vector * | vt, |
const uint32_t | index | ||
) |
Data after the index will be moved down one. Memory will be deleted only if SHRINK_SIZE_AFTER_DATA_REMOVE is defined.
vt | Pointer to a vector |
index | Data index in a vector |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector is NULL or index out of range |
ERRCODE_OUT_OF_MEMORY | Not enough memory |
int vector_swap | ( | const Vector * | vt, |
const uint32_t | a, | ||
const uint32_t | b | ||
) |
vt | Pointer to a vector |
a | Data index in a vector |
b | Data index in a vector |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector is NULL or index out of range |
ERRCODE_OUT_OF_MEMORY | Not enough memory |
VectorIter vector_iter_begin | ( | const Vector * | vt | ) |
This allows other functions to step through the vector entries or to access the first entry in the vector.
vt | Pointer to a vector |
VectorIter vector_iter_end | ( | const Vector * | vt | ) |
This is the point after the last entry in the vector, where a new data entry would be added.
vt | pointer to a vector |
VectorIter vector_iter_next | ( | VectorIter | iter | ) |
This gives access to the next data entry in the vector.
iter | Current iterator |
VectorIter vector_iter_prev | ( | const Vector * | vt, |
VectorIter | iter | ||
) |
This gives access to the previous data entry in the vector.
vt | Pointer to a vector |
iter | Current iterator |
bool vector_iter_equal | ( | const VectorIter | a, |
const VectorIter | b | ||
) |
They are equal if they point to the same data entry in the vector.
a | Iterator a |
b | Iterator b |
int vector_iter_at | ( | const Vector * | vt, |
VectorIter | iter, | ||
uint32_t * | at | ||
) |
vt | pointer to a vector |
iter | current iterator |
at | save the index value |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector or at is NULL or iterator out of range |
void* vector_iter_node | ( | const VectorIter | iter | ) |
iter | Current iterator |
int vector_iter_value | ( | const Vector * | vt, |
VectorIter | iter, | ||
void * | data | ||
) |
vt | Pointer to a vector |
iter | Current iterator |
data | Save the value |
ERRCODE_NO_ERROR | OK |
ERRCODE_INVALID_ARGUMENT | Vector or data is NULL or iterator out of range |