px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_link_list.h : Linked List

Description

A double (forward and backward) linked list using pointers.

File(s):

See also
http://en.wikipedia.org/wiki/Linked_list

Example:

No items in list:
[first = NULL] [last = NULL]
One item in list:
[first] -> [prev = NULL][next = NULL] <- [last]
Two items in list:
[first] -> [prev = NULL][next] <-> [prev][next = NULL] <- [last]
Three items in list:
[first] -> [prev = NULL][next] <-> [prev][next] <-> [prev][next = NULL] <- [last]
#define NULL
NULL pointer.
Definition: px_defs.h:49

Data Structures

Functions

void px_link_list_init (px_link_list_t *list, size_t max_nr_of_items)
 Initialises a linked list structure. More...
 
void px_link_list_item_init (px_link_list_t *list, px_link_list_item_t *item)
 Initialises a list item. More...
 
bool px_link_list_is_empty (px_link_list_t *list)
 See if the list is empty. More...
 
bool px_link_list_is_full (px_link_list_t *list)
 See if the list is full. More...
 
size_t px_link_list_get_item_count (px_link_list_t *list)
 Get the number of items in the list. More...
 
px_link_list_item_tpx_link_list_get_item_first (px_link_list_t *list)
 Get a pointer to the first item in the list. More...
 
px_link_list_item_tpx_link_list_get_item_last (px_link_list_t *list)
 Get a pointer to the last item in the list. More...
 
px_link_list_item_tpx_link_list_get_item_next (px_link_list_t *list, px_link_list_item_t *item)
 Get a pointer to the next item in the list (after the specified item). More...
 
px_link_list_item_tpx_link_list_get_item_prev (px_link_list_t *list, px_link_list_item_t *item)
 Get a pointer to the previous item in the list (before the specified item). More...
 
bool px_link_list_insert_item_start (px_link_list_t *list, px_link_list_item_t *item)
 Insert item to the start of the list. More...
 
bool px_link_list_insert_item_end (px_link_list_t *list, px_link_list_item_t *item)
 Add item to the end of the list. More...
 
bool px_link_list_insert_item_before (px_link_list_t *list, px_link_list_item_t *item, px_link_list_item_t *item_pos)
 Insert item before specified item. More...
 
bool px_link_list_insert_item_after (px_link_list_t *list, px_link_list_item_t *item, px_link_list_item_t *item_pos)
 Insert item after specified item. More...
 
px_link_list_item_tpx_link_list_remove_item_first (px_link_list_t *list)
 Remove first item from the list. More...
 
px_link_list_item_tpx_link_list_remove_item_last (px_link_list_t *list)
 Remove last item from the list. More...
 
void px_link_list_remove_item (px_link_list_t *list, px_link_list_item_t *item)
 Remove item from the list. More...
 
bool px_link_list_has_item (px_link_list_t *list, px_link_list_item_t *item)
 See if item is in the list. More...
 

Data Structure Documentation

◆ px_link_list_item_t

struct px_link_list_item_t

Link structure that must be at the head of each item in the list.

Definition at line 69 of file px_link_list.h.

Data Fields
struct px_link_list_item_s * next Pointer to next item in the list.
struct px_link_list_item_s * prev Pointer to previous item in the list.

◆ px_link_list_t

struct px_link_list_t

Linked list structure.

Definition at line 76 of file px_link_list.h.

Data Fields
struct px_link_list_item_s * first Pointer to first item in the list.
struct px_link_list_item_s * last Pointer to last item in the list.
size_t item_count Number of items in the list.
size_t items_max Maximum number of items allowed in list; 0 means no limit.

Function Documentation

◆ px_link_list_init()

void px_link_list_init ( px_link_list_t list,
size_t  max_nr_of_items 
)

Initialises a linked list structure.

Parameters
listPointer to the linked list
max_nr_of_itemsMaximum number of items allowed in list; 0 means no limit

Definition at line 37 of file px_link_list.c.

◆ px_link_list_item_init()

void px_link_list_item_init ( px_link_list_t list,
px_link_list_item_t item 
)

Initialises a list item.

Initialises the item structure to indicate that it is not in the list.

See also
px_link_list_item_in_list()
Parameters
listPointer to the linked list
itemPointer to specified item

Definition at line 46 of file px_link_list.c.

◆ px_link_list_is_empty()

bool px_link_list_is_empty ( px_link_list_t list)

See if the list is empty.

Parameters
listPointer to the linked list
Returns
true List is empty
false List contains one or more items

Definition at line 53 of file px_link_list.c.

◆ px_link_list_is_full()

bool px_link_list_is_full ( px_link_list_t list)

See if the list is full.

Parameters
listPointer to the linked list
Return values
trueThe list is full
falseThe list is not full, or there is no limit (max_nr_of_items = 0)

Definition at line 65 of file px_link_list.c.

◆ px_link_list_get_item_count()

size_t px_link_list_get_item_count ( px_link_list_t list)

Get the number of items in the list.

Parameters
listPointer to the linked list
Returns
size_t The number of items in the list

Definition at line 82 of file px_link_list.c.

◆ px_link_list_get_item_first()

px_link_list_item_t * px_link_list_get_item_first ( px_link_list_t list)

Get a pointer to the first item in the list.

Parameters
listPointer to the linked list
Returns
px_link_list_item_t * Pointer to the first item in the list; NULL will be returned if the list is empty.

Definition at line 87 of file px_link_list.c.

◆ px_link_list_get_item_last()

px_link_list_item_t * px_link_list_get_item_last ( px_link_list_t list)

Get a pointer to the last item in the list.

Parameters
listPointer to the linked list
Returns
px_link_list_item_t * Pointer to the last item in the list; NULL will be returned if the list is empty.

Definition at line 92 of file px_link_list.c.

◆ px_link_list_get_item_next()

px_link_list_item_t * px_link_list_get_item_next ( px_link_list_t list,
px_link_list_item_t item 
)

Get a pointer to the next item in the list (after the specified item).

Parameters
listPointer to the linked list
itemCurrent item
Returns
px_link_list_item_t * Pointer to the next item in the list; NULL will be returned if the specified item is the last one in the list.

Definition at line 97 of file px_link_list.c.

◆ px_link_list_get_item_prev()

px_link_list_item_t * px_link_list_get_item_prev ( px_link_list_t list,
px_link_list_item_t item 
)

Get a pointer to the previous item in the list (before the specified item).

Parameters
listPointer to the linked list
itemCurrent item
Returns
px_link_list_item_t * Pointer to the next item in the list; NULL will be returned if the specified item is the first one in the list.

Definition at line 103 of file px_link_list.c.

◆ px_link_list_insert_item_start()

bool px_link_list_insert_item_start ( px_link_list_t list,
px_link_list_item_t item 
)

Insert item to the start of the list.

Parameters
listPointer to the linked list
itemItem to be inserted
Return values
trueItem has been inserted
falseList is full

Definition at line 109 of file px_link_list.c.

◆ px_link_list_insert_item_end()

bool px_link_list_insert_item_end ( px_link_list_t list,
px_link_list_item_t item 
)

Add item to the end of the list.

Parameters
listPointer to the linked list
itemItem to be inserted
Return values
trueItem has been inserted
falseList is full

Definition at line 138 of file px_link_list.c.

◆ px_link_list_insert_item_before()

bool px_link_list_insert_item_before ( px_link_list_t list,
px_link_list_item_t item,
px_link_list_item_t item_pos 
)

Insert item before specified item.

Parameters
listPointer to the linked list
itemItem to be inserted
item_posInsert before this item
Return values
trueItem has been inserted
falseList is full

Definition at line 167 of file px_link_list.c.

◆ px_link_list_insert_item_after()

bool px_link_list_insert_item_after ( px_link_list_t list,
px_link_list_item_t item,
px_link_list_item_t item_pos 
)

Insert item after specified item.

Parameters
listPointer to the linked list
itemItem to be inserted
item_posInsert after this item
Return values
trueItem has been inserted
falseList is full

Definition at line 209 of file px_link_list.c.

◆ px_link_list_remove_item_first()

px_link_list_item_t * px_link_list_remove_item_first ( px_link_list_t list)

Remove first item from the list.

Parameters
listPointer to the linked list
Returns
px_link_list_item_t * Pointer to the (old) first item; NULL will be returned if the list is empty.

Definition at line 251 of file px_link_list.c.

◆ px_link_list_remove_item_last()

px_link_list_item_t * px_link_list_remove_item_last ( px_link_list_t list)

Remove last item from the list.

Parameters
listPointer to the linked list
Returns
px_link_list_item_t * Pointer to the (old) last item; NULL will be returned if the list is empty.

Definition at line 281 of file px_link_list.c.

◆ px_link_list_remove_item()

void px_link_list_remove_item ( px_link_list_t list,
px_link_list_item_t item 
)

Remove item from the list.

Parameters
listPointer to the linked list
itemItem to be removed from the list

Definition at line 311 of file px_link_list.c.

◆ px_link_list_has_item()

bool px_link_list_has_item ( px_link_list_t list,
px_link_list_item_t item 
)

See if item is in the list.

Parameters
listPointer to the linked list
itemPointer to specified item
Return values
trueItem is in the list
falseItem is not in the list

Definition at line 342 of file px_link_list.c.