|
PebbleOS
|
Intrusive doubly linked list. More...
Data Structures | |
| struct | ListNode |
| List node, embedded in the listed structure. More... | |
Macros | |
| #define | LIST_NODE_NULL {.next = NULL, .prev = NULL} |
| Initializer of an unlinked node. | |
Typedefs | |
| typedef bool(* | ListFilterCallback) (ListNode *found_node, void *data) |
| Filter for list_find() and its variants. | |
| typedef bool(* | ListForEachCallback) (ListNode *node, void *context) |
| Callback for list_foreach(). | |
Functions | |
| void | list_init (ListNode *head) |
| Initialize a node as unlinked. | |
| ListNode * | list_insert_after (ListNode *node, ListNode *new_node) |
| Insert a node after another one. | |
| ListNode * | list_insert_before (ListNode *node, ListNode *new_node) |
| Insert a node before another one. | |
| ListNode * | list_pop_head (ListNode *node) |
| Unlink the head of a list. | |
| ListNode * | list_pop_tail (ListNode *node) |
| Unlink the tail of a list. | |
| void | list_remove (ListNode *node, ListNode **head, ListNode **tail) |
| Unlink a node from its list. | |
| ListNode * | list_append (ListNode *node, ListNode *new_node) |
| Append a node to the tail of a list. | |
| ListNode * | list_prepend (ListNode *node, ListNode *new_node) |
| Prepend a node to the head of a list. | |
| ListNode * | list_get_next (ListNode *node) |
| Get the next node. | |
| ListNode * | list_get_prev (ListNode *node) |
| Get the previous node. | |
| ListNode * | list_get_tail (ListNode *node) |
| Get the tail of a list. | |
| ListNode * | list_get_head (ListNode *node) |
| Get the head of a list. | |
| bool | list_is_head (const ListNode *node) |
| Check whether a node is the head of its list. | |
| bool | list_is_tail (const ListNode *node) |
| Check whether a node is the tail of its list. | |
| uint32_t | list_count_to_tail_from (ListNode *node) |
| Count the nodes from a node to the tail. | |
| uint32_t | list_count_to_head_from (ListNode *node) |
| Count the nodes from a node to the head. | |
| uint32_t | list_count (ListNode *node) |
| Count the nodes of a list. | |
| ListNode * | list_get_at (ListNode *node, int32_t index) |
| Get the node at a distance from another one. | |
| ListNode * | list_sorted_add (ListNode *head, ListNode *new_node, Comparator comparator, bool ascending) |
| Insert a node into a sorted list, keeping it sorted. | |
| bool | list_contains (const ListNode *head, const ListNode *node) |
| Check whether a list contains a node. | |
| ListNode * | list_find (ListNode *node, ListFilterCallback filter_callback, void *data) |
| Find the first matching node, from a node towards the tail. | |
| ListNode * | list_find_next (ListNode *node, ListFilterCallback filter_callback, bool wrap_around, void *data) |
| Find the next matching node after a node. | |
| ListNode * | list_find_prev (ListNode *node, ListFilterCallback filter_callback, bool wrap_around, void *data) |
| Find the previous matching node before a node. | |
| ListNode * | list_concatenate (ListNode *list_a, ListNode *list_b) |
| Append a list to another one. | |
| void | list_foreach (ListNode *head, ListForEachCallback each_cb, void *context) |
| Call a function on each node, from a node to the tail. | |
| void | list_debug_dump (ListNode *head) |
| Log every node from a node to the tail with UTIL_LOG(). | |
Intrusive doubly linked list.
A list is a chain of ListNode embedded in the caller's structures; there is no separate list object, a list is referenced by any of its nodes, usually its head. Functions that take "any node" walk to the head or tail as needed. Nothing is allocated and there is no locking.
| struct ListNode |
| #define LIST_NODE_NULL {.next = NULL, .prev = NULL} |
Initializer of an unlinked node.
| typedef bool(* ListFilterCallback) (ListNode *found_node, void *data) |
Filter for list_find() and its variants.
| found_node | Node to check. |
| data | Callback data. |
found_node matches. | typedef bool(* ListForEachCallback) (ListNode *node, void *context) |
Callback for list_foreach().
The callback may unlink or free node.
| node | Current node. |
| context | Callback data. |
Append a node to the tail of a list.
| node | Any node in the list, or NULL for an empty list. |
| new_node | Node to append. |
new_node, the new tail. Append a list to another one.
Nothing is done when both nodes are already in the same list.
| list_a | Any node of the first list, may be NULL. |
| list_b | Any node of the list to append, may be NULL. |
Check whether a list contains a node.
| head | Head of the list, may be NULL. |
| node | Node to search for. |
node is at or after head. | uint32_t list_count | ( | ListNode * | node | ) |
Count the nodes of a list.
| node | Any node in the list, may be NULL. |
| uint32_t list_count_to_head_from | ( | ListNode * | node | ) |
Count the nodes from a node to the head.
| node | Starting node, counted. May be NULL. |
| uint32_t list_count_to_tail_from | ( | ListNode * | node | ) |
Count the nodes from a node to the tail.
| node | Starting node, counted. May be NULL. |
| void list_debug_dump | ( | ListNode * | head | ) |
Log every node from a node to the tail with UTIL_LOG().
| head | Starting node. |
| ListNode * list_find | ( | ListNode * | node, |
| ListFilterCallback | filter_callback, | ||
| void * | data | ||
| ) |
Find the first matching node, from a node towards the tail.
| node | Node to start from, included in the search. May be NULL. |
| filter_callback | Filter. |
| data | Filter data. |
| ListNode * list_find_next | ( | ListNode * | node, |
| ListFilterCallback | filter_callback, | ||
| bool | wrap_around, | ||
| void * | data | ||
| ) |
Find the next matching node after a node.
| node | Node to start after. May be NULL. |
| filter_callback | Filter. |
| wrap_around | Continue from the head after reaching the tail, up to and including node. |
| data | Filter data. |
| ListNode * list_find_prev | ( | ListNode * | node, |
| ListFilterCallback | filter_callback, | ||
| bool | wrap_around, | ||
| void * | data | ||
| ) |
Find the previous matching node before a node.
| node | Node to start before. May be NULL. |
| filter_callback | Filter. |
| wrap_around | Continue from the tail after reaching the head, up to and including node. |
| data | Filter data. |
| void list_foreach | ( | ListNode * | head, |
| ListForEachCallback | each_cb, | ||
| void * | context | ||
| ) |
Call a function on each node, from a node to the tail.
| head | Starting node, may be NULL. |
| each_cb | Callback; it may unlink or free the node it gets. |
| context | Callback data. |
Get the node at a distance from another one.
| node | Starting node. |
| index | Number of nodes to move, towards the tail if positive, the head if negative. |
Get the head of a list.
| node | Any node in the list, may be NULL. |
Get the next node.
| node | Node, may be NULL. |
Get the previous node.
| node | Node, may be NULL. |
Get the tail of a list.
| node | Any node in the list, may be NULL. |
| void list_init | ( | ListNode * | head | ) |
Initialize a node as unlinked.
| [out] | head | Node. |
Insert a node after another one.
| node | Node to insert after, may be NULL. |
| new_node | Node to insert. |
new_node. Insert a node before another one.
| node | Node to insert before, may be NULL. |
| new_node | Node to insert. |
new_node, which is the new head only when node was the head. | bool list_is_head | ( | const ListNode * | node | ) |
Check whether a node is the head of its list.
| node | Node, may be NULL. |
node has no previous node, false for NULL. | bool list_is_tail | ( | const ListNode * | node | ) |
Check whether a node is the tail of its list.
| node | Node, may be NULL. |
node has no next node, false for NULL. Unlink the head of a list.
| node | Any node in the list, may be NULL. |
Unlink the tail of a list.
| node | Any node in the list, may be NULL. |
Prepend a node to the head of a list.
| node | Any node in the list, or NULL for an empty list. |
| new_node | Node to prepend. |
new_node, the new head. Unlink a node from its list.
| node | Node to remove, may be NULL. | |
| [in,out] | head | Head of the list, updated if it is node. May be NULL. |
| [in,out] | tail | Tail of the list, updated if it is node. May be NULL. |
| ListNode * list_sorted_add | ( | ListNode * | head, |
| ListNode * | new_node, | ||
| Comparator | comparator, | ||
| bool | ascending | ||
| ) |
Insert a node into a sorted list, keeping it sorted.
Existing nodes are not sorted. The node goes before the first node that sorts after it, so 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. |