nesemu/gui/components/linked_list.h

72 lines
1.6 KiB
C

//
// Created by william on 1/16/24.
//
#include <stdbool.h>
#ifndef NESEMULATOR_LINKED_LIST_H
#define NESEMULATOR_LINKED_LIST_H
typedef struct linked_list_node {
struct linked_list_node *previous;
struct linked_list_node *next;
void *data;
} LinkedListNode;
typedef struct linked_list {
bool circular;
unsigned int size;
LinkedListNode *head;
LinkedListNode *end;
} LinkedList;
typedef struct linked_list_cursor {
LinkedListNode *current;
} LinkedListCursor;
/**
* Initializes a new linked list.
*
* @param circular If the list is circular, meaning that the last node is linked to the first node.
* @return The linked list instance
*/
LinkedList linked_list_create(bool circular);
/**
* Adds data to a linked list.
*
* @param list The linked list
* @param data The data to add
*/
void linked_list_add(LinkedList *list, void *data);
/**
* Destroys a linked list. The data must be freed before.
*
* @param list The list to destroy
*/
void linked_list_destroy(LinkedList *list);
/**
* Creates a read cursor for a linked list.
* @param list The list
* @return A cursor initialized to the first item in the list.
*/
LinkedListCursor linked_list_cursor_create(LinkedList *list);
/**
* Gets the next node in the list.
*
* @param cursor A read cursor for the list
* @return The next node in the list. Can be NULL if the list is empty or depleted.
*/
LinkedListNode *linked_list_cursor_next(LinkedListCursor *cursor);
/**
* Checks if there is nodes remaining after a cursor.
* @param cursor A cursor
*/
bool linked_list_cursor_has_next(LinkedListCursor *cursor);
#endif //NESEMULATOR_LINKED_LIST_H