|
PebbleOS
|
Intrusive singly linked list. More...
Data Structures | |
| struct | SingleListNode |
| Singly linked list node, embedded in the listed structure. More... | |
Macros | |
| #define | SINGLE_LIST_NODE_NULL {.next = NULL} |
| Initializer of an unlinked node. | |
Typedefs | |
| typedef bool(* | SingleListFilterCallback) (SingleListNode *found_node, void *data) |
| Filter for slist_find(). | |
| typedef bool(* | SingleListForEachCallback) (SingleListNode *node, void *context) |
| Callback for slist_foreach(). | |
Functions | |
| void | slist_init (SingleListNode *node) |
| Initialize a node as unlinked. | |
| SingleListNode * | slist_insert_after (SingleListNode *node, SingleListNode *new_node) |
| Insert a node after another one. | |
| SingleListNode * | slist_prepend (SingleListNode *head, SingleListNode *new_node) |
| Prepend a node to a list. | |
| SingleListNode * | slist_append (SingleListNode *head, SingleListNode *new_node) |
| Append a node to the tail of a list. | |
| SingleListNode * | slist_pop_head (SingleListNode *head) |
| Unlink the head of a list. | |
| void | slist_remove (SingleListNode *node, SingleListNode **head) |
| Unlink a node from a list. | |
| SingleListNode * | slist_get_next (SingleListNode *node) |
| Get the next node. | |
| SingleListNode * | slist_get_tail (SingleListNode *node) |
| Get the tail of a list. | |
| bool | slist_is_tail (const SingleListNode *node) |
| Check whether a node is the tail of its list. | |
| uint32_t | slist_count (SingleListNode *head) |
| Count the nodes of a list. | |
| bool | slist_contains (const SingleListNode *head, const SingleListNode *node) |
| Check whether a list contains a node. | |
| SingleListNode * | slist_find (SingleListNode *head, SingleListFilterCallback filter_callback, void *data) |
| Find the first matching node. | |
| SingleListNode * | slist_sorted_add (SingleListNode *head, SingleListNode *new_node, Comparator comparator, bool ascending) |
| Insert a node into a sorted list, keeping it sorted. | |
| SingleListNode * | slist_concatenate (SingleListNode *list_a, SingleListNode *list_b) |
| Append a list to another one. | |
| void | slist_foreach (SingleListNode *head, SingleListForEachCallback each_cb, void *context) |
| Call a function on each node of a list. | |
| void | slist_debug_dump (SingleListNode *head) |
| Log every node of a list with UTIL_LOG(). | |
Intrusive singly linked list.
Like Linked list with half the per-node overhead, at the cost of linear-time removal. A list is referenced by its head.
| struct SingleListNode |
Singly linked list node, embedded in the listed structure.
| Data Fields | ||
|---|---|---|
| struct SingleListNode * | next | Next node, or NULL. |
| #define SINGLE_LIST_NODE_NULL {.next = NULL} |
Initializer of an unlinked node.
| typedef bool(* SingleListFilterCallback) (SingleListNode *found_node, void *data) |
Filter for slist_find().
| found_node | Node to check. |
| data | Callback data. |
found_node matches. | typedef bool(* SingleListForEachCallback) (SingleListNode *node, void *context) |
Callback for slist_foreach().
The callback may unlink or free node.
| node | Current node. |
| context | Callback data. |
| SingleListNode * slist_append | ( | SingleListNode * | head, |
| SingleListNode * | new_node | ||
| ) |
Append a node to the tail of a list.
| head | Any node in the list, or NULL for an empty list. |
| new_node | Node to append. |
new_node, the new tail. | SingleListNode * slist_concatenate | ( | SingleListNode * | list_a, |
| SingleListNode * | list_b | ||
| ) |
Append a list to another one.
| list_a | Head of the first list, may be NULL. |
| list_b | Head of the list to append, may be NULL. |
| bool slist_contains | ( | const SingleListNode * | head, |
| const SingleListNode * | node | ||
| ) |
Check whether a list contains a node.
| head | Head of the list, may be NULL. |
| node | Node to search for. |
node is in the list. | uint32_t slist_count | ( | SingleListNode * | head | ) |
Count the nodes of a list.
| head | Head of the list, may be NULL. |
| void slist_debug_dump | ( | SingleListNode * | head | ) |
Log every node of a list with UTIL_LOG().
| head | Head of the list. |
| SingleListNode * slist_find | ( | SingleListNode * | head, |
| SingleListFilterCallback | filter_callback, | ||
| void * | data | ||
| ) |
Find the first matching node.
| head | Node to start from, included in the search. May be NULL. |
| filter_callback | Filter. |
| data | Filter data. |
| void slist_foreach | ( | SingleListNode * | head, |
| SingleListForEachCallback | each_cb, | ||
| void * | context | ||
| ) |
Call a function on each node of a list.
| head | Head of the list, may be NULL. |
| each_cb | Callback; it may unlink or free the node it gets. |
| context | Callback data. |
| SingleListNode * slist_get_next | ( | SingleListNode * | node | ) |
Get the next node.
| node | Node, may be NULL. |
| SingleListNode * slist_get_tail | ( | SingleListNode * | node | ) |
Get the tail of a list.
| node | Any node in the list, may be NULL. |
| void slist_init | ( | SingleListNode * | node | ) |
Initialize a node as unlinked.
| [out] | node | Node. |
| SingleListNode * slist_insert_after | ( | SingleListNode * | node, |
| SingleListNode * | new_node | ||
| ) |
Insert a node after another one.
| node | Node to insert after, may be NULL. |
| new_node | Node to insert. |
new_node. | bool slist_is_tail | ( | const SingleListNode * | node | ) |
Check whether a node is the tail of its list.
| node | Node, may be NULL. |
node has no next node, false for NULL. | SingleListNode * slist_pop_head | ( | SingleListNode * | head | ) |
Unlink the head of a list.
| head | Head of the list, may be NULL. |
| SingleListNode * slist_prepend | ( | SingleListNode * | head, |
| SingleListNode * | new_node | ||
| ) |
Prepend a node to a list.
| head | Head of the list, or NULL for an empty list. |
| new_node | Node to prepend, may be NULL. |
| void slist_remove | ( | SingleListNode * | node, |
| SingleListNode ** | head | ||
| ) |
Unlink a node from a list.
Nothing is done if node is not in the list.
| node | Node to remove. | |
| [in,out] | head | Head of the list, updated if it is node. |
| SingleListNode * slist_sorted_add | ( | SingleListNode * | head, |
| SingleListNode * | new_node, | ||
| Comparator | comparator, | ||
| bool | ascending | ||
| ) |
Insert a node into a sorted list, keeping it sorted.
Existing nodes are not sorted. Equal nodes keep their insertion order.
| head | Head of the list, or NULL for an empty list. |
| new_node | Node to insert. |
| comparator | Called with an existing node and new_node; see Comparator. |
| ascending | true to keep the list in ascending order from head to tail. |