#ifndef IZ_LIST_H #define IZ_LIST_H #include "../../common/IZ_common.h" #include "SDL_stdinc.h" /** * A node in a linked list. */ typedef struct IZ_ListNode { /** * The value of the node. */ void* value; /** * The next node in the list. */ struct IZ_ListNode* next; } IZ_ListNode; /** * A singly-linked list. */ typedef struct { /** * The first node in the list. */ IZ_ListNode* root; /** * The number of nodes in the list. */ u64 length; /** * The iterator for traversing the list. */ IZ_ListNode** iterator; /** * The custom data for use in matching for the find predicate. */ void* find_predicate_userdata; } IZ_List; /** * Predicate for finding a node in a list. */ typedef bool IZ_ListFindPredicate(IZ_ListNode**, u64, IZ_List*); /** * Comparator callback for sorting a list. Returns a positive value if a > b, a negative value if a < b, and 0 if a == b. */ typedef i64 IZ_ListSortComparatorPredicate(IZ_ListNode**, IZ_ListNode**, u64, IZ_List*); /** * Initializes a list. */ void IZ_ListInitialize(IZ_List*); /** * Performs cleanup on a list. */ void IZ_ListTeardown(IZ_List*); /** * Appends a node to the end of the list. * @return Pointer to the newly created node. */ IZ_ListNode** IZ_ListAppendNode(IZ_List*, void*); /** * Inserts a node at the specified index in the list. * @return Pointer to the newly created node. */ IZ_ListNode** IZ_ListInsertNodeAtIndex(IZ_List*, void*, u64); /** * Deletes the first node in the list that matches the filter. */ void IZ_ListDeleteFirstNode(IZ_List*, IZ_ListFindPredicate); /** * Finds the first node in the list that matches the filter. * @return Pointer to the node that matches the filter. */ IZ_ListNode** IZ_ListFindFirstNode(IZ_List*, IZ_ListFindPredicate); /** * Creates a new list that contains the nodes that match the filter. */ void IZ_ListFilter(IZ_List*, IZ_ListFindPredicate, IZ_List* out1); /** * Creates a new list that contains the sorted nodes from the original list. */ void IZ_ListSort(IZ_List*, IZ_ListSortComparatorPredicate, IZ_List* out1); #endif