|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "IZ_list.h"
-
- bool IZ_ListFindFilterAlwaysTrue(IZ_ListNode* _node, u64 _index) {
- return true;
- }
-
- void IZ_ListInitialize(IZ_List* list) {
- list->root = NULL;
- list->length = 0;
- }
-
- void IZ_ListTeardown(IZ_List* list) {
- while (list->root) {
- _IZ_ListDeleteFirstNode(list, IZ_ListFindFilterAlwaysTrue);
- }
- }
-
- IZ_ListNode* IZ_ListAppendNode(IZ_List* list, void* node_value) {
- IZ_ListNode* new_node = SDL_malloc(sizeof(IZ_ListNode));
- new_node->value = node_value;
- if (!(list->root)) {
- list->root = new_node;
- } else {
- IZ_ListNode *last_node = list->root;
- while (last_node->next) {
- last_node = last_node->next;
- }
- last_node->next = new_node;
- }
- new_node->next = NULL;
- list->length += 1;
- return new_node;
- }
-
- void _IZ_ListDeleteFirstNode(IZ_List* list, IZ_ListFindFilter filter) {
- if (!(list && list->root)) {
- return;
- }
-
- IZ_ListNode* iterator = list->root;
- IZ_ListNode* previous_node = NULL;
- u64 index = 0;
- do {
- if (!filter(iterator, index)) {
- previous_node = iterator;
- iterator = iterator->next;
- index += 1;
- continue;
- }
-
- if (previous_node) {
- previous_node->next = iterator->next;
- } else {
- list->root = iterator->next;
- }
-
- SDL_free(iterator);
- iterator = NULL;
- list->length -= 1;
- return;
- } while (iterator);
- }
-
- IZ_ListNode* _IZ_ListFindFirstNode(IZ_List* list, IZ_ListFindFilter filter) {
- if (!(list && list->root)) {
- return NULL;
- }
-
- IZ_ListNode* iterator = list->root;
- u64 index = 0;
- do {
- if (!filter(iterator, index)) {
- iterator = iterator->next;
- index += 1;
- continue;
- }
- return iterator;
- } while (iterator);
-
- return NULL;
- }
|