Maestro Audio Framework  v 1.0
NXP Semiconductors
vector.h File Reference

vector data type implementation More...

#include <stdbool.h>

Data Structures

struct  Vector
 
struct  VectorIter
 

Functions

VECTOR FUNCTION PROTOTYPES
Vectorvector_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...
 

Function Documentation

◆ vector_create()

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

Parameters
data_szSize of each data member in vector
cap_initInitial capacity size of the created vector, if this parameter is set to 0, then a default minimal capacity is used.
Returns
vector pointer or NULL if create failed

◆ vector_destroy()

void vector_destroy ( Vector vt)
Parameters
vtPointer to a vector
Returns
none

◆ vector_capacity()

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.

Parameters
vtPointer to a vector
Returns
capacity of a vector, 0 if the vector is NULL

◆ vector_size()

uint32_t vector_size ( const Vector vt)

The size is the number of data entries saved in a vector.

Parameters
vtPointer to a vector
Returns
size of a vector, 0 if the vector is NULL

◆ vector_is_empty()

bool vector_is_empty ( const Vector vt)
Parameters
vtPointer to a vector
Returns
bool

◆ vector_clear()

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.

Parameters
vtPointer to a vector
Returns
osa error code
Return values
ERRCODE_NO_ERRORNo error
ERRCODE_INVALID_ARGUMENTParameter vt is NULL
ERRCODE_OUT_OF_MEMORYReallocation of memory failed

◆ vector_reserve()

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.

Parameters
vtPointer to a vector
sizeAmount of data space required
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL
ERRCODE_OUT_OF_MEMORYNot enough memory

◆ vector_pushback()

int vector_pushback ( Vector vt,
const void *  data 
)

If there is not enough space, the vector will expand.

Parameters
vtPointer to a vector
dataPointer to the data
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or data is NULL
ERRCODE_OUT_OF_MEMORYNot enough memory

◆ vector_popback()

int vector_popback ( Vector vt,
void *  data 
)

Memory will be deleted only if SHRINK_SIZE_AFTER_DATA_REMOVE is defined.

Parameters
vtPointer to a vector
datapointer to memory block for the returned data (allocated by the caller)
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or data is NULL
ERRCODE_GENERAL_ERRORVector is empty
ERRCODE_OUT_OF_MEMORYNot enough memory

◆ vector_at()

int vector_at ( const Vector vt,
const uint32_t  index,
void *  data 
)
Parameters
vtpointer to a vector
indexdata index in a vector
datapointer to memory block for the returned data (allocated by the caller)
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or data is NULL or index out of range
ERRCODE_GENERAL_ERRORVector is empty

◆ vector_assign()

int vector_assign ( const Vector vt,
const uint32_t  index,
const void *  data 
)
Parameters
vtpointer to a vector
indexdata index in a vector. Must be less than the size of the vector.
datapointer to the data
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or data is NULL or index out of range
ERRCODE_GENERAL_ERRORVector is empty

◆ vector_insert_at()

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.

Parameters
vtPointer to a vector
indexData index in a vector. Must be less than the vector size
dataPointer to the data
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or data is NULL or index out of range

◆ vector_remove_at()

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.

Parameters
vtPointer to a vector
indexData index in a vector
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or index out of range
ERRCODE_OUT_OF_MEMORYNot enough memory

◆ vector_swap()

int vector_swap ( const Vector vt,
const uint32_t  a,
const uint32_t  b 
)
Parameters
vtPointer to a vector
aData index in a vector
bData index in a vector
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector is NULL or index out of range
ERRCODE_OUT_OF_MEMORYNot enough memory

◆ vector_iter_begin()

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.

Parameters
vtPointer to a vector
Returns
iterator, NULL if the vector is NULL

◆ vector_iter_end()

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.

Parameters
vtpointer to a vector
Returns
iterator, NULL if the vector is NULL

◆ vector_iter_next()

VectorIter vector_iter_next ( VectorIter  iter)

This gives access to the next data entry in the vector.

Parameters
iterCurrent iterator
Returns
iterator, NULL if the vector is NULL

◆ vector_iter_prev()

VectorIter vector_iter_prev ( const Vector vt,
VectorIter  iter 
)

This gives access to the previous data entry in the vector.

Parameters
vtPointer to a vector
iterCurrent iterator
Returns
iterator, NULL if the vector is NULL

◆ vector_iter_equal()

bool vector_iter_equal ( const VectorIter  a,
const VectorIter  b 
)

They are equal if they point to the same data entry in the vector.

Parameters
aIterator a
bIterator b
Returns
TRUE if two iterators are equal, else FALSE

◆ vector_iter_at()

int vector_iter_at ( const Vector vt,
VectorIter  iter,
uint32_t *  at 
)
Parameters
vtpointer to a vector
itercurrent iterator
atsave the index value
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector or at is NULL or iterator out of range

◆ vector_iter_node()

void* vector_iter_node ( const VectorIter  iter)
Parameters
iterCurrent iterator
Returns
Internal node pointer of data member in a vector. NULL indicates an error

◆ vector_iter_value()

int vector_iter_value ( const Vector vt,
VectorIter  iter,
void *  data 
)
Parameters
vtPointer to a vector
iterCurrent iterator
dataSave the value
Returns
osa error code
Return values
ERRCODE_NO_ERROROK
ERRCODE_INVALID_ARGUMENTVector or data is NULL or iterator out of range