Go to the source code of this file.
Macros | |
#define | CL_VECTOR_FOREACH(__type, __name, __arr, ...) |
Macro to iterate over the elements of the vector. | |
#define | CL_VECTOR_FOREACH_PTR(__type, __name, __arr, ...) |
Macro to iterate over the elements of the vector with a pointer to the current element. | |
Typedefs | |
typedef struct __Vector | CL_Vector |
Functions | |
CL_Vector * | CL_VectorAllocWithCapacity (MEM_Allocator *const alloc, u32 capacity, u32 elem_sz) |
Initializes the vector with allocated memory provided by the user. | |
CL_Vector * | CL_VectorAlloc (MEM_Allocator *const alloc, u32 elem_sz) |
Initializes the vector with a default capacity. | |
void | CL_VectorFree (CL_Vector *const arr) |
Frees the memory previously assigned to the vector. | |
CL_Error | CL_VectorPushBack (CL_Vector *const arr, const void *const elem, u32 *out_index) |
Adds an element at the end of the vector. | |
CL_Error | CL_VectorPushFront (CL_Vector *const arr, const void *const elem) |
Adds an element at the front of the vector. | |
void | CL_VectorPopBack (CL_Vector *const arr, void *out_elem) |
Removes the last element from the vector, optionally returning it. | |
void | CL_VectorPopFront (CL_Vector *const arr, void *out_elem) |
Removes the first element from the vector, optionally returning it. | |
CL_Error | CL_VectorGet (const CL_Vector *const arr, u32 index, void *out_elem) |
Gets an element at the specified index. | |
CL_Error | CL_VectorGetPtr (const CL_Vector *const arr, u32 index, void **out_elem) |
Gets a pointer to an element at the specified index. | |
CL_Error | CL_VectorGetLast (const CL_Vector *const arr, void *out_elem) |
Gets the last element from the vector. | |
CL_Error | CL_VectorGetLastPtr (const CL_Vector *const arr, void **out_elem) |
Gets a pointer to the last element from the vector. | |
CL_Error | CL_VectorInsert (CL_Vector *const arr, const void *const elem, u32 index) |
Inserts an element at the specified index. | |
CL_Error | CL_VectorRemove (CL_Vector *const arr, u32 index) |
Removes an element at the specified index. | |
void | CL_VectorClear (CL_Vector *const arr) |
Clears the vector. | |
bool | CL_VectorIsEmpty (const CL_Vector *const arr) |
Checks if the vector is empty. | |
u32 | CL_VectorSize (const CL_Vector *const arr) |
Gets the size of the vector. | |
u32 | CL_VectorCapacity (const CL_Vector *const arr) |
Gets the capacity of the vector. | |
void | CL_VectorSort (CL_Vector *arr, CL_CompareFn compare_fn) |
Sorts the vector. | |
bool | CL_VectorSearch (const CL_Vector *const arr, const void *elem, CL_CompareFn compare_fn, u32 *out_index) |
Searches for an element in the vector. | |
#define CL_VECTOR_FOREACH | ( | __type, | |
__name, | |||
__arr, | |||
... | |||
) |
Macro to iterate over the elements of the vector.
__type | The type of the elements in the vector. |
__name | The name of the variable to hold the current element. |
__arr | The vector to iterate over. |
... | The code to execute for each element. |
Definition at line 20 of file cl_vector.h.
#define CL_VECTOR_FOREACH_PTR | ( | __type, | |
__name, | |||
__arr, | |||
... | |||
) |
Macro to iterate over the elements of the vector with a pointer to the current element.
__type | The type of the elements in the vector. |
__name | The name of the variable to hold the current element. |
__arr | The vector to iterate over. |
... | The code to execute for each element. |
Definition at line 33 of file cl_vector.h.
Definition at line 11 of file cl_vector.h.
CL_Vector * CL_VectorAlloc | ( | MEM_Allocator *const | alloc, |
u32 | elem_sz | ||
) |
Initializes the vector with a default capacity.
alloc | The allocator to use for memory allocation. |
elem_sz | The size of each element in the vector. |
Definition at line 59 of file cl_vector.c.
CL_Vector * CL_VectorAllocWithCapacity | ( | MEM_Allocator *const | alloc, |
u32 | capacity, | ||
u32 | elem_sz | ||
) |
Initializes the vector with allocated memory provided by the user.
alloc | The allocator to use for memory allocation. |
capacity | The initial capacity of the vector. |
elem_sz | The size of each element in the vector. |
Definition at line 33 of file cl_vector.c.
Gets the capacity of the vector.
arr | The vector to get the capacity of. |
Definition at line 238 of file cl_vector.c.
void CL_VectorClear | ( | CL_Vector *const | arr | ) |
Clears the vector.
arr | The vector to clear. |
Definition at line 219 of file cl_vector.c.
void CL_VectorFree | ( | CL_Vector *const | arr | ) |
Frees the memory previously assigned to the vector.
arr | The vector to release the memory of. |
Definition at line 64 of file cl_vector.c.
Gets an element at the specified index.
arr | The vector to get the element from. |
index | The index of the element to get. |
out_elem | [OUTPUT] The element at the specified index. |
Definition at line 126 of file cl_vector.c.
Gets the last element from the vector.
arr | The vector to get the last element from. |
out_elem | [OUTPUT] The last element. |
Definition at line 158 of file cl_vector.c.
Gets a pointer to the last element from the vector.
arr | The vector to get the last element from. |
out_elem | [OUTPUT] The pointer to the last element. |
Definition at line 166 of file cl_vector.c.
Gets a pointer to an element at the specified index.
arr | The vector to get the element from. |
index | The index of the element to get. |
out_elem | [OUTPUT] The pointer to the element at the specified index. |
Definition at line 142 of file cl_vector.c.
Inserts an element at the specified index.
arr | The vector to insert the element to. |
elem | The element to insert. |
index | The index to insert the element at. |
Definition at line 174 of file cl_vector.c.
bool CL_VectorIsEmpty | ( | const CL_Vector *const | arr | ) |
Checks if the vector is empty.
arr | The vector to check. |
Definition at line 228 of file cl_vector.c.
void CL_VectorPopBack | ( | CL_Vector *const | arr, |
void * | out_elem | ||
) |
Removes the last element from the vector, optionally returning it.
arr | The vector to remove the last element from. |
out_elem | [OUTPUT] The removed element, if not NULL. |
Definition at line 102 of file cl_vector.c.
void CL_VectorPopFront | ( | CL_Vector *const | arr, |
void * | out_elem | ||
) |
Removes the first element from the vector, optionally returning it.
arr | The vector to remove the first element from. |
out_elem | [OUTPUT] The removed element, if not NULL. |
Definition at line 115 of file cl_vector.c.
Adds an element at the end of the vector.
arr | The vector to add the element to. |
elem | The element to add. |
out_index | [OUTPUT] The index of the added element, if not NULL. |
Definition at line 73 of file cl_vector.c.
Adds an element at the front of the vector.
arr | The vector to add the element to. |
elem | The element to add. |
Definition at line 96 of file cl_vector.c.
Removes an element at the specified index.
arr | The vector to remove the element from. |
index | The index to remove the element from. |
Definition at line 199 of file cl_vector.c.
bool CL_VectorSearch | ( | const CL_Vector *const | arr, |
const void * | elem, | ||
CL_CompareFn | compare_fn, | ||
u32 * | out_index | ||
) |
Searches for an element in the vector.
arr | The vector to search in. |
elem | The element to search for. |
compare_fn | The comparison function. |
out_index | [OUTPUT] The index of the element, if found and not NULL. |
Definition at line 251 of file cl_vector.c.
Gets the size of the vector.
arr | The vector to get the size of. |
Definition at line 233 of file cl_vector.c.
void CL_VectorSort | ( | CL_Vector * | arr, |
CL_CompareFn | compare_fn | ||
) |