![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Doubly linked list base implementation. More...
Go to the source code of this file.
Classes | |
| struct | dlist_node |
| The doubly linked node structure. More... | |
Macros | |
| #define | DLIST_PNODE_INIT_DATA(pnode) (pnode)->next = (pnode)->prev = pnode |
| Initialize node links (pointer version). More... | |
| #define | DLIST_NODE_INIT(node) DLIST_PNODE_INIT_DATA(&(node)) |
| Initialize node links. More... | |
| #define | DLIST_PNODE_INIT(pnode) DLIST_PNODE_INIT_DATA(pnode) |
| Initialize node links (pointer version). More... | |
| #define | dlist_entry(ptr, type, member) ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) |
| get the pointer to the embedding struct for ptr More... | |
| #define | dlist_for_each(pos, head) for(pos = (head)->next; pos != (head); pos = pos->next) |
| iterate over a list More... | |
| #define | dlist_for_each_safe(pos, npos, head) |
| safely iterate over a list More... | |
Typedefs | |
| typedef struct dlist_node | dnode_t |
| The doubly linked node structure. | |
Functions | |
| static void | _dlist_add (dnode_t *node, dnode_t *prev, dnode_t *next) |
| insert a new entry between two known consecutive entries More... | |
| static void | dlist_prepend (dnode_t *node, dnode_t *head) |
| prepend new node to head of list More... | |
| static void | dlist_append (dnode_t *node, dnode_t *head) |
| append a new node to the in of the list More... | |
| static void | _dlist_del (dnode_t *prev, dnode_t *next) |
| delete the node(s) between the prev/next nodes. More... | |
| static void | dlist_delete (dnode_t *node) |
| deletes node from list More... | |
| static int | dlist_is_empty (dnode_t *head) |
| tests whether a list is empty More... | |
| static void | dlist_splice (dnode_t *list, dnode_t *head) |
| prepend new list at head of given list More... | |
Doubly linked list base implementation.
The dlists are intended to be embedded within the parent structure of a specific type. Higher level constructs using the dlist base can build implementations doubly-linked lists, queues, stacks, circular buffers, and binary trees with data of any type.
Some of the internal functions ("_dlist_xxx") are useful when manipulating whole lists rather than single entries, as sometimes we already know the next/prev entries and we can generate better code by using them directly rather than using the generic single-entry routines.
This file has been modified from the original source (see below).
—
Definition in file dlist.h.
| #define dlist_entry | ( | ptr, | |
| type, | |||
| member | |||
| ) | ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) |
| #define dlist_for_each | ( | pos, | |
| head | |||
| ) | for(pos = (head)->next; pos != (head); pos = pos->next) |
| #define dlist_for_each_safe | ( | pos, | |
| npos, | |||
| head | |||
| ) |
safely iterate over a list
| pos | the dnode_t pointer to be use as a loop counter |
| npos | another dnode_t pointer to use as temporary storage |
| head | the head of list to iterate over |
Definition at line 225 of file dlist.h.
Referenced by DListVoidDeleteAllNodes(), DListVoidFindNode(), DListVoidGetNodeAt(), and DListVoidPrint().
| #define DLIST_NODE_INIT | ( | node | ) | DLIST_PNODE_INIT_DATA(&(node)) |
Initialize node links.
| node | dnode_t |
Definition at line 74 of file dlist.h.
Referenced by DListVoidNew().
| #define DLIST_PNODE_INIT | ( | pnode | ) | DLIST_PNODE_INIT_DATA(pnode) |
Initialize node links (pointer version).
| pnode | pointer to dnode_t |
Definition at line 80 of file dlist.h.
Referenced by dlist_delete().
| #define DLIST_PNODE_INIT_DATA | ( | pnode | ) | (pnode)->next = (pnode)->prev = pnode |
insert a new entry between two known consecutive entries
| node | the new node to be inserted |
| prev | previous node to new node |
| next | next node to new node |
Definition at line 92 of file dlist.h.
References dlist_node::next, and dlist_node::prev.
Referenced by dlist_append(), dlist_prepend(), and DListVoidInsert().
delete the node(s) between the prev/next nodes.
| prev | previous node to link to next |
| next | next node to link with previous |
Definition at line 137 of file dlist.h.
References dlist_node::next, and dlist_node::prev.
Referenced by dlist_delete().
append a new node to the in of the list
Insert a new node before the specified head. This is useful for implementing queues.
| node | the new node to be inserted at end of the list |
| head | list head |
Definition at line 123 of file dlist.h.
References _dlist_add(), and dlist_node::prev.
Referenced by DListVoidAppend().
|
inlinestatic |
deletes node from list
| node | the node to delete from the list. |
Note: Deleted node becomes an orphan (i.e. empty) head node.
Definition at line 150 of file dlist.h.
References _dlist_del(), DLIST_PNODE_INIT, dlist_node::next, and dlist_node::prev.
Referenced by DListVoidDeleteNode(), DListVoidUnlinkDataAt(), and DListVoidUnlinkNodeAt().
|
inlinestatic |
tests whether a list is empty
| head | list head |
Definition at line 163 of file dlist.h.
References dlist_node::next.
Referenced by dlist_splice().
prepend new node to head of list
Insert a new node after the specified head. This is good for implementing stacks.
| node | the new node to be inserted at head of the list |
| head | list head |
Definition at line 109 of file dlist.h.
References _dlist_add(), and dlist_node::next.
Referenced by DListVoidPrepend().
prepend new list at head of given list
| list | the new list to add |
| head | list head holding newly spliced lists |
Definition at line 177 of file dlist.h.
References dlist_is_empty(), dlist_node::next, and dlist_node::prev.