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

An intrusive circular doubly linked list. More...

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

Go to the source code of this file.

Data Structures

struct  list_element
 list element state More...
 
struct  list
 list state More...
 
struct  list_iterator
 list iterator state More...
 

Macros

#define LIST_INIT(list)   { .head.prev = &(list).head, .head.next = &(list).head }
 allows static initialization of a list More...
 

Functions

int list_element_init (struct list_element *element)
 initialize a list_element More...
 
int list_element_in_list (struct list_element *element, bool *in_list)
 checks if an element is in a list More...
 
int list_element_insert_after (struct list_element *after, struct list_element *element)
 insert an element after another More...
 
int list_element_insert_before (struct list_element *before, struct list_element *element)
 insert an element before another More...
 
int list_element_remove (struct list_element *element)
 removes element from a list More...
 
int list_init (struct list *list)
 initialize a list More...
 
int list_is_empty (struct list *list, bool *is_empty)
 checks if a list is empty More...
 
int list_prepend (struct list *list, struct list_element *element)
 prepends an element to a list More...
 
int list_append (struct list *list, struct list_element *element)
 appends an element to a list More...
 
int list_remove (struct list *list, struct list_element *element)
 removes an element from a list More...
 
int list_iterator_init (struct list_iterator *it, struct list *list)
 initialize a list iterator More...
 
int list_iterator_next (struct list_iterator *it, struct list_element **element)
 gets the next element from an iterator More...
 
int list_iterator_previous (struct list_iterator *it, struct list_element **element)
 gets the previous element from an iterator More...
 
bool list_contains (struct list *list, struct list_element *element)
 checks if an element is contained in a list More...
 
int list_clear (struct list *list)
 removes all elments from a list More...
 

Detailed Description

An intrusive circular doubly linked list.

Macro Definition Documentation

◆ LIST_INIT

#define LIST_INIT (   list)    { .head.prev = &(list).head, .head.next = &(list).head }

allows static initialization of a list

struct list my_list = LIST_INIT(my_list);

Function Documentation

◆ list_append()

int list_append ( struct list list,
struct list_element element 
)

appends an element to a list

Parameters
listpointer to the list to append to
elementpointer to the element to append
Returns
0 if successful

◆ list_clear()

int list_clear ( struct list list)

removes all elments from a list

Parameters
listthe list to clear
Returns
0 if all elements were removed

◆ list_contains()

bool list_contains ( struct list list,
struct list_element element 
)

checks if an element is contained in a list

Parameters
listthe list to check
elementthe element to look for
Returns
true if element is in list, false otherwise

◆ list_element_in_list()

int list_element_in_list ( struct list_element element,
bool *  in_list 
)

checks if an element is in a list

Parameters
elementthe element to check for list membership
[out]in_listpointer to location where result should be written
Returns
0 if successful

◆ list_element_init()

int list_element_init ( struct list_element element)

initialize a list_element

Parameters
elementpointer to list_element
Returns
0 if successful

◆ list_element_insert_after()

int list_element_insert_after ( struct list_element after,
struct list_element element 
)

insert an element after another

Parameters
afterlist element after which to insert
elementelement to insert returns 0 if the insert was successful

◆ list_element_insert_before()

int list_element_insert_before ( struct list_element before,
struct list_element element 
)

insert an element before another

Parameters
beforeelement before which to insert
elementelement to insert returns 0 if the insert was successful

◆ list_element_remove()

int list_element_remove ( struct list_element element)

removes element from a list

Parameters
elementlist_element to remove
Returns
0 if successful

◆ list_init()

int list_init ( struct list list)

initialize a list

Parameters
listpointer to list
Returns
0 if successful

◆ list_is_empty()

int list_is_empty ( struct list list,
bool *  is_empty 
)

checks if a list is empty

Parameters
listpointer to initialized list
[out]is_emptypointer to location where result should be written
Returns
0 if the check was successful

◆ list_iterator_init()

int list_iterator_init ( struct list_iterator it,
struct list list 
)

initialize a list iterator

the iterator will point to one before the first element of list or, equivalently, to one after the last element of list

Parameters
itpointer to the iterator to initialize
listpointer to the list over which to iterate
Returns
0 if successful

◆ list_iterator_next()

int list_iterator_next ( struct list_iterator it,
struct list_element **  element 
)

gets the next element from an iterator

Parameters
itthe iterator from which to get the next element
[out]elementpointer to a location where the next element pointer should be written
Returns
0 if successful

◆ list_iterator_previous()

int list_iterator_previous ( struct list_iterator it,
struct list_element **  element 
)

gets the previous element from an iterator

Parameters
itthe iterator from which to get the previous element
[out]elementpointer to a location where the previous element pointer should be written
Returns
0 if successful

◆ list_prepend()

int list_prepend ( struct list list,
struct list_element element 
)

prepends an element to a list

Parameters
listpointer to the list on which to prepend
elementpointer to element to prepend
Returns
0 if successful

◆ list_remove()

int list_remove ( struct list list,
struct list_element element 
)

removes an element from a list

Note
removing the current element of an iterator will invalidate that iterator
Parameters
listthe list from which to remove
elementthe element to remove
Returns
0 if successful