#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;
} IZ_List;

typedef bool IZ_ListFindPredicate(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*);

/**
 * 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);

#endif
