45 if (!alloc || !elem_sz)
72 current = current->
next;
95 list->
tail = new_node;
117 list->
head = new_node;
126 if (!list || !list->
size)
148 if (!list || !list->
size)
170 if (!list || !out_elem)
173 if (index >= list->
size)
178 while (idx++ < index)
179 current = current->
next;
188 if (!list || !out_elem)
191 if (index >= list->
size)
196 while (idx++ < index)
197 current = current->
next;
200 *out_elem = current->
data;
206 if (!list || !out_elem)
218 if (!list || !out_elem)
233 if (index > list->
size)
238 else if (index == list->
size)
247 while (idx++ < index)
248 current = current->
next;
252 new_node->
next = current;
253 current->
prev = new_node;
265 if (index >= list->
size)
270 else if (index == list->
size - 1)
277 while (idx++ < index)
278 current = current->
next;
296 if (!list || !elem || !compare_fn)
303 if (compare_fn(current->
data, elem) == 0)
310 current = current->
next;
318 if (!list || !list->
size)
325 current = current->
next;
336 return list ? list->
size : 0;
341 return !list || !list->
size;
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.
CL_Error CL_ListGetLastPtr(const CL_List *const list, void **out_elem)
Gets the last element from the list as a pointer, so the user can modify it.
void CL_ListPopFront(CL_List *const list, void *out_elem)
Removes the first element from the list, optionally returning it.
CL_Error CL_ListRemoveAt(CL_List *const list, u32 index, void *out_elem)
Removes an element at the specified index.
void CL_ListPopBack(CL_List *const list, void *out_elem)
Removes the last element from the list, optionally returning it.
void CL_ListClear(CL_List *const list)
Removes all elements from the list.
CL_Error CL_ListGetLast(const CL_List *const list, void *out_elem)
Gets the last element from the list.
bool CL_ListSearch(const CL_List *const list, const void *const elem, CL_CompareFn compare_fn, u32 *out_index)
Searches for an element in the list.
u32 CL_ListSize(const CL_List *const list)
Gets the number of elements in the list.
CL_Error CL_ListPushBack(CL_List *const list, const void *const elem)
Adds an element at the end of the list.
bool CL_ListIsEmpty(const CL_List *const list)
Checks if the list is empty.
void CL_ListFree(CL_List *const list)
Frees the memory previously assigned to the list.
CL_Error CL_ListGetPtr(const CL_List *const list, u32 index, void **out_elem)
Gets an element at the specified index as a pointer, so the user can modify it.
CL_List * CL_ListAlloc(MEM_Allocator *const alloc, u32 elem_sz)
Initializes a new doubly-linked list with tail, with the allocated memory provided by the user.
CL_Error CL_ListPushFront(CL_List *const list, const void *const elem)
Adds an element at the front of the list.
_PRIVATE struct __ListNode * create_node(CL_List *list, const void *const elem)
CL_Error CL_ListGet(const CL_List *const list, u32 index, void *out_elem)
Gets an element at the specified index.
CL_Error CL_ListInsertAt(CL_List *const list, u32 index, const void *const elem)
Inserts an element at the specified index.
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.
MEM_Allocator * allocator