|
|
@@ -1,9 +1,5 @@ |
|
|
|
#include "IZ_list.h" |
|
|
|
|
|
|
|
bool IZ_ListFindFilterAlwaysTrue(IZ_ListNode** _node, u64 _index, IZ_List* _list) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes a list. |
|
|
|
* @param list - The list to initialize. |
|
|
@@ -20,10 +16,9 @@ void IZ_ListInitialize(IZ_List* list) { |
|
|
|
*/ |
|
|
|
void IZ_ListTeardown(IZ_List* list) { |
|
|
|
while (list->root) { |
|
|
|
IZ_ListDeleteFirstNode(list, IZ_ListFindFilterAlwaysTrue); |
|
|
|
IZ_ListDeleteNode(list, &list->root); |
|
|
|
} |
|
|
|
list->iterator = NULL; |
|
|
|
list->length = 0; |
|
|
|
IZ_free(list); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -54,30 +49,28 @@ IZ_ListNode** IZ_ListAppendNode(IZ_List* list, void* node_value) { |
|
|
|
/** |
|
|
|
* Deletes the first node in the list that matches the filter. |
|
|
|
* @param list - The list to delete from. |
|
|
|
* @param filter - The filter to use to find the node to delete. |
|
|
|
* @param node - The node to delete. |
|
|
|
*/ |
|
|
|
void IZ_ListDeleteFirstNode(IZ_List* list, IZ_ListFindPredicate filter) { |
|
|
|
if (!(list && list->root)) { |
|
|
|
void IZ_ListDeleteNode(IZ_List* list, IZ_ListNode** node) { |
|
|
|
if (!(list && list->root && node)) { |
|
|
|
// should we raise warnings here? |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// FIXME Teardown having problems here |
|
|
|
list->iterator = &list->root; |
|
|
|
IZ_ListNode* previous_node = NULL; |
|
|
|
u64 index = 0; |
|
|
|
IZ_ListNode** previous_node = NULL; |
|
|
|
do { |
|
|
|
if (!filter(list->iterator, index, list)) { |
|
|
|
previous_node = *list->iterator; |
|
|
|
if (list->iterator != node) { |
|
|
|
previous_node = list->iterator; |
|
|
|
list->iterator = &((*list->iterator)->next); |
|
|
|
index += 1; |
|
|
|
// we haven't found the node we're looking for, go to the next one |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (previous_node) { |
|
|
|
// this is not the first node in the list |
|
|
|
previous_node->next = (*list->iterator)->next; |
|
|
|
(*previous_node)->next = (*list->iterator)->next; |
|
|
|
} else { |
|
|
|
// this is the first node, set it as new root |
|
|
|
list->root = (*list->iterator)->next; |
|
|
|