GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1
12#ifndef LIST_H
13#define LIST_H
14
15#include <stdbool.h>
16
24#define MAX_LIST_NODES 128
25
29// clang-format off
30#define LIST_DEFAULT { .head = NULL, .tail = NULL, .len = 0 }
31// clang-format on
32
33typedef struct ListNode ListNode;
34
39{
45
50
54 void* data;
55};
56
60typedef struct List
61{
66
71
75 int len;
77
82{
83 LIST_ITR_FORWARD,
84 LIST_ITR_REVERSE,
85};
86
114
125List list_init(void);
126
137void list_clear(List* list);
138
146bool list_is_empty(const List* list);
147
154void list_push_front(List* list, void* data);
155
162void list_push_back(List* list, void* data);
163
200void list_insert(List* list, void* data, unsigned int idx);
201
213bool list_swap(List* list, unsigned int idx_a, unsigned int idx_b);
214
223void* list_get_at_idx(List* list, unsigned int idx);
224
233bool list_remove_at_idx(List* list, unsigned int idx);
234
245bool list_remove_data(List* list, void* data);
246
254int list_get_len(const List* list);
255
264
273
281void* list_itr_next(ListItr* itr);
282
295
296#endif
bool list_swap(List *list, unsigned int idx_a, unsigned int idx_b)
Definition list.c:148
bool list_is_empty(const List *list)
Definition list.c:62
List list_init(void)
Definition list.c:38
void * list_get_at_idx(List *list, unsigned int idx)
Definition list.c:219
void list_insert(List *list, void *data, unsigned int idx)
Definition list.c:110
int list_get_len(const List *list)
Definition list.c:214
void list_push_front(List *list, void *data)
Definition list.c:67
ListItr rev_list_itr_create(List *list)
Definition list.c:269
void list_clear(List *list)
Definition list.c:44
void list_itr_remove_current_node(ListItr *itr)
Definition list.c:307
ListItrDirection
ListItr direction
Definition list.h:82
void * list_itr_next(ListItr *itr)
Definition list.c:281
bool list_remove_data(List *list, void *data)
Definition list.c:316
bool list_remove_at_idx(List *list, unsigned int idx)
Definition list.c:237
void list_push_back(List *list, void *data)
Definition list.c:89
ListItr list_itr_create(List *list)
Definition list.c:257
An iterator into a list.
Definition list.h:91
ListNode * current_node
The current node in the list iterator.
Definition list.h:107
ListNode * next_node
The next node in the list.
Definition list.h:100
enum ListItrDirection direction
The direction of the iterator.
Definition list.h:112
List * list
A pointer to the List this is iterating through.
Definition list.h:95
A single entry in a List.
Definition list.h:39
void * data
Pointer to generic data stored in this node.
Definition list.h:54
ListNode * prev
The previous ListNode in the associated List, NULL if at the head of the list.
Definition list.h:44
ListNode * next
The next ListNode in the associated List, NULL if at the tail of the list.
Definition list.h:49
A doubly-linked list.
Definition list.h:61
ListNode * head
The first entry in the list.
Definition list.h:65
ListNode * tail
The last entry in the list.
Definition list.h:70
int len
Number of elements in list.
Definition list.h:75