Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
This is a basic doubly linked list data structure. Each entry in the list has a void*
which can point to any data.
Data can be added or removed from the head or tail in O(1) time, making this suitable as a queue or stack.
push() and pop() add and remove from the tail of the list.
unshift() and shift() add and remove from the head of the list.
addIdx() and removeIdx() add and remove from the middle of the list, by index. These run in O(N), not O(1).
removeEntry() can remove a specific entry.
Links are allocated, so when done with a list, be sure to call clear() when done.
Creating an empty list:
Adding values to a list:
Iterating over a list:
Removing values from a list:
Go to the source code of this file.
Data Structures | |
struct | node |
A node in a doubly linked list with pointers to the previous and next values (which may be NULL), and a void* to arbritray data. More... | |
struct | list_t |
A doubly linked list with pointers to the first and last nodes. More... | |
Typedefs | |
typedef struct node | node_t |
A node in a doubly linked list with pointers to the previous and next values (which may be NULL), and a void* to arbritray data. | |
Functions | |
void | push (list_t *list, void *val) |
Add to the end of the list. | |
void * | pop (list_t *list) |
Remove from the end of the list. | |
void | unshift (list_t *list, void *val) |
Add to the front of the list. | |
void * | shift (list_t *list) |
Remove from the front of the list. | |
bool | addIdx (list_t *list, void *val, uint16_t index) |
Add at an index in the list. | |
void | addBefore (list_t *list, void *val, node_t *entry) |
Insert a value into the list immediately before the given node. | |
void | addAfter (list_t *list, void *val, node_t *entry) |
Insert a value into the list immediately after the given node. | |
void * | removeIdx (list_t *list, uint16_t index) |
Remove at an index in the list. | |
void * | removeEntry (list_t *list, node_t *entry) |
void | clear (list_t *list) |
Remove all items from the list. | |
struct node |
struct list_t |
A node in a doubly linked list with pointers to the previous and next values (which may be NULL), and a void*
to arbritray data.
void push | ( | list_t * | list, |
void * | val ) |
Add to the end of the list.
list | The list to add to |
val | The value to be added |
void * pop | ( | list_t * | list | ) |
Remove from the end of the list.
list | The list to remove the last node from |
void unshift | ( | list_t * | list, |
void * | val ) |
Add to the front of the list.
list | The list to add to |
val | The value to add to the list |
void * shift | ( | list_t * | list | ) |
Remove from the front of the list.
list | The list to remove from |
bool addIdx | ( | list_t * | list, |
void * | val, | ||
uint16_t | index ) |
Add at an index in the list.
list | The list to add to |
val | The value to add |
index | The index to add the value at |
Insert a value into the list immediately before the given node.
If the given node is NULL, inserts at the end of the list
list | The list to add the entry to |
val | The new value to add to the list |
entry | The existing entry, after which to insert the value |
Insert a value into the list immediately after the given node.
If the given node is NULL, inserts at the beginning of the list
list | The list to add the entry to |
val | The new value to add to the list |
entry | The existing entry, after which to insert the value |
void * removeIdx | ( | list_t * | list, |
uint16_t | index ) |
Remove at an index in the list.
list | The list to remove from |
index | The index to remove the value from |
Remove a specific entry from the linked list by node_t. This relinks the entry's neighbors, but does not validate that it was part of the given list_t. If the given node_t was not part of the given list_t, the list length will desync.
list | The list to remove an entry from |
entry | The entry to remove |
void clear | ( | list_t * | list | ) |
Remove all items from the list.
list | The list to clear |