20#define CL_VECTOR_FOREACH(__type, __name, __arr, ...) \
21 for (u32 __i = 0; __i < CL_VectorSize(__arr); __i++) \
24 CL_VectorGet(__arr, __i, (void *)&__name); \
33#define CL_VECTOR_FOREACH_PTR(__type, __name, __arr, ...) \
34 for (u32 __i = 0; __i < CL_VectorSize(__arr); __i++) \
37 CL_VectorGetPtr(__arr, __i, (void **)&__name); \
int(* CL_CompareFn)(const void *, const void *)
A function pointer type for comparing two elements.
CL_Error
Specify this in the size parameter of the collections initialization to tell the library that the num...
CL_Error CL_VectorGet(const CL_Vector *const arr, u32 index, void *out_elem)
Gets an element at the specified index.
u32 CL_VectorCapacity(const CL_Vector *const arr)
Gets the capacity of 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.
void CL_VectorPopBack(CL_Vector *const arr, void *out_elem)
Removes the last element from the vector, optionally returning it.
u32 CL_VectorSize(const CL_Vector *const arr)
Gets the size of the vector.
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.
bool CL_VectorIsEmpty(const CL_Vector *const arr)
Checks if the vector is empty.
void CL_VectorSort(CL_Vector *arr, CL_CompareFn compare_fn)
Sorts the vector.
CL_Vector * CL_VectorAllocWithCapacity(MEM_Allocator *const alloc, u32 capacity, u32 elem_sz)
Initializes the vector with allocated memory provided by the user.
CL_Error CL_VectorPushFront(CL_Vector *const arr, const void *const elem)
Adds an element at the front of the vector.
void CL_VectorPopFront(CL_Vector *const arr, void *out_elem)
Removes the first element from the vector, optionally returning it.
void CL_VectorFree(CL_Vector *const arr)
Frees the memory previously assigned to 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.
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_VectorPushBack(CL_Vector *const arr, const void *const elem, u32 *out_index)
Adds an element at the end of the vector.
CL_Vector * CL_VectorAlloc(MEM_Allocator *const alloc, u32 elem_sz)
Initializes the vector with a default capacity.