utils
utilities in C for microcontrollers
Data Structures | Functions
slist.h File Reference

An intrusive singly linked list. More...

#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  slist_element
 slist element state More...
 
struct  slist
 slist state More...
 
struct  slist_iterator
 slist iterator state More...
 

Functions

int slist_element_init (struct slist_element *element)
 initialize a slist_element More...
 
int slist_element_insert_after (struct slist_element *after, struct slist_element *element)
 insert an element after another More...
 
int slist_element_remove_after (struct slist_element *after)
 removes an element following another More...
 
int slist_init (struct slist *list)
 initialize an slist More...
 
int slist_is_empty (struct slist *list, bool *is_empty)
 checks if a list is empty More...
 
int slist_prepend (struct slist *list, struct slist_element *element)
 prepends element to list More...
 
int slist_append (struct slist *list, struct slist_element *element)
 appends an element to a list More...
 
int slist_remove (struct slist *list, struct slist_element *element)
 removes an element from a list More...
 
int slist_remove_head (struct slist *list, struct slist_element **element)
 removes the first element from a list More...
 
int slist_iterator_init (struct slist_iterator *it, struct slist *list)
 initialize a list iterator More...
 
int slist_iterator_next (struct slist_iterator *it, struct slist_element **element)
 gets the next element from an iterator More...
 

Detailed Description

An intrusive singly linked list.

Function Documentation

◆ slist_append()

int slist_append ( struct slist list,
struct slist_element element 
)

appends an element to a list

Parameters
listthe list on which to append
elementthe element to append
Returns
0 if successful

If element is part of a list then that list will be corrupted. The runtime of this function is linear in the length of list.

◆ slist_element_init()

int slist_element_init ( struct slist_element element)

initialize a slist_element

Parameters
elementpointer to element to initialize
Returns
0 if successful

◆ slist_element_insert_after()

int slist_element_insert_after ( struct slist_element after,
struct slist_element element 
)

insert an element after another

Parameters
afterthe element after which to insert
elementthe element to insert
Returns
0 if the insert was successful

◆ slist_element_remove_after()

int slist_element_remove_after ( struct slist_element after)

removes an element following another

Parameters
afterthe element after which to remove
Returns
0 if an element was removed

◆ slist_init()

int slist_init ( struct slist list)

initialize an slist

Parameters
listthe slist to initialize
Returns
0 if successful

◆ slist_is_empty()

int slist_is_empty ( struct slist list,
bool *  is_empty 
)

checks if a list is empty

Parameters
listthe list to check
[out]is_emptypointer to location where result should be stored
Returns
0 if the check was successful

◆ slist_iterator_init()

int slist_iterator_init ( struct slist_iterator it,
struct slist list 
)

initialize a list iterator

Parameters
itthe iterator to initialize
listthe list over which to iterate
Returns
0 if successful

◆ slist_iterator_next()

int slist_iterator_next ( struct slist_iterator it,
struct slist_element **  element 
)

gets the next element from an iterator

Parameters
itthe iterator from which to get the next element
[out]elementthe location at which to store the next element
Returns
0 if successful

◆ slist_prepend()

int slist_prepend ( struct slist list,
struct slist_element element 
)

prepends element to list

Parameters
listthe list on which to prepend
elementthe element to prepend
Returns
0 if successful

If element is part of a list then that list will be corrupted.

◆ slist_remove()

int slist_remove ( struct slist list,
struct slist_element element 
)

removes an element from a list

Parameters
listthe list from which to remove
elementthe element to remove
Returns
0 if successful

If element is a member of a list other than list then the other list will be corrupted. The runtime of this function is linear in the length of list.

◆ slist_remove_head()

int slist_remove_head ( struct slist list,
struct slist_element **  element 
)

removes the first element from a list

Parameters
listthe list from which to remove
[out]elementlocation where the removed element should be stored
Returns
0 if an element was removed