Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
linked_list.c File Reference

Macros

#define VALIDATE_LIST(func, line, nl, list, target)
 

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.
 

Macro Definition Documentation

◆ VALIDATE_LIST

#define VALIDATE_LIST ( func,
line,
nl,
list,
target )

Function Documentation

◆ push()

void push ( list_t * list,
void * val )

Add to the end of the list.

Parameters
listThe list to add to
valThe value to be added

◆ pop()

void * pop ( list_t * list)

Remove from the end of the list.

Parameters
listThe list to remove the last node from
Returns
The value from the last node

◆ unshift()

void unshift ( list_t * list,
void * val )

Add to the front of the list.

Parameters
listThe list to add to
valThe value to add to the list

◆ shift()

void * shift ( list_t * list)

Remove from the front of the list.

Parameters
listThe list to remove from
Returns
The value from the first node

◆ addIdx()

bool addIdx ( list_t * list,
void * val,
uint16_t index )

Add at an index in the list.

Parameters
listThe list to add to
valThe value to add
indexThe index to add the value at
Returns
true if the value was added, false if the index was invalid

◆ addBefore()

void addBefore ( list_t * list,
void * val,
node_t * entry )

Insert a value into the list immediately before the given node.

If the given node is NULL, inserts at the end of the list

Parameters
listThe list to add the entry to
valThe new value to add to the list
entryThe existing entry, after which to insert the value

◆ addAfter()

void addAfter ( list_t * list,
void * val,
node_t * entry )

Insert a value into the list immediately after the given node.

If the given node is NULL, inserts at the beginning of the list

Parameters
listThe list to add the entry to
valThe new value to add to the list
entryThe existing entry, after which to insert the value

◆ removeIdx()

void * removeIdx ( list_t * list,
uint16_t index )

Remove at an index in the list.

Parameters
listThe list to remove from
indexThe index to remove the value from
Returns
The value that was removed. May be NULL if the index was invalid

◆ removeEntry()

void * removeEntry ( list_t * list,
node_t * entry )

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.

Parameters
listThe list to remove an entry from
entryThe entry to remove
Returns
The removed value from the entry, may be NULL if the entry was invalid

◆ clear()

void clear ( list_t * list)

Remove all items from the list.

Parameters
listThe list to clear