16#define BASE_CAPACITY 10
35 if (!alloc || !capacity || !elem_sz)
91 *out_index = arr->
size - 1;
104 if (!arr || !arr->
size)
117 if (!arr || !arr->
size)
128 if (!arr || !out_elem)
131 if (index >= arr->
size || index < 0)
144 if (!arr || !out_elem)
147 if (index >= arr->
size || index < 0)
154 *out_elem = (
u8 *)(arr->
data) + offset;
179 if (index > arr->
size || index < 0)
204 if (index >= arr->
size || index < 0)
221 if (!arr || !arr->
size)
230 return arr ? arr->
size == 0 :
true;
235 return arr ? arr->
size : 0;
245 if (!arr || !cmp || arr->
size < 2)
253 if (!arr || !elem || !compare_fn)
257 for (
u32 i = 0; i < arr->
size; i++)
260 if (!compare_fn(elem, (
u8 *)(arr->
data) + offset))
void MEM_Free(MEM_Allocator *ma, void *ptr)
Free a previously allocated block.
void * MEM_Alloc(MEM_Allocator *ma, u32 size)
Allocate a block of memory from the pool with at least 'size' bytes.
void * MEM_Realloc(MEM_Allocator *ma, void *ptr, u32 new_size)
Reallocate a previously allocated block to a new size.
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_ERR_EMPTY
Empty collection.
@ CL_ERR_OUT_OF_BOUNDS
Out of bounds.
@ CL_ERR_NO_MEMORY
No memory available.
@ CL_ERR_INVALID_PARAMS
Invalid arguments.
CL_Error CL_VectorGet(const CL_Vector *const arr, u32 index, void *out_elem)
Gets an element at the specified index.
void CL_VectorSort(CL_Vector *const arr, CL_CompareFn cmp)
Sorts the vector.
void CL_VectorFree(CL_Vector *arr)
Frees the memory previously assigned to the vector.
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.
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.
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.
_PRIVATE void * realloc_data(CL_Vector *const arr, u32 new_capacity)
CL_Vector * CL_VectorAlloc(MEM_Allocator *const alloc, u32 elem_sz)
Initializes the vector with a default capacity.
struct __Vector CL_Vector
MEM_Allocator * allocator