Double linked list implementation in a single header file.
More...
Go to the source code of this file.
|
#define | LIST_HEAD(t, name) |
|
#define | LIST_FIELDS(t, name) |
|
#define | LIST_HEAD_INIT(head) |
|
#define | LIST_INIT(name, item) |
|
#define | LIST_PREPEND(name, head, item) |
|
#define | LIST_APPEND(name, head, item) |
|
#define | LIST_REMOVE(name, head, item) |
|
#define | LIST_FIND_HEAD(name, item, head) |
|
#define | LIST_FIND_TAIL(name, item, tail) |
|
#define | LIST_INSERT_AFTER(name, head, a, b) |
|
#define | LIST_INSERT_BEFORE(name, head, a, b) |
|
#define | LIST_JUST_US(name, item) |
|
#define | LIST_FOREACH(name, i, head) |
|
#define | LIST_FOREACH_SAFE(name, i, n, head) |
|
#define | LIST_FOREACH_BEFORE(name, i, p) |
|
#define | LIST_FOREACH_AFTER(name, i, p) |
|
#define | LIST_FOREACH_OTHERS(name, i, p) |
|
#define | LIST_LOOP_BUT_ONE(name, i, head, p) |
|
#define | LIST_IS_EMPTY(head) |
|
- Copyright
- GNU Lesser General Public License 2.1
Stolen from the systemd project
◆ LIST_HEAD
#define LIST_HEAD |
( |
|
t, |
|
|
|
name |
|
) |
| |
The head of the linked list. Use this in the structure that shall contain the head of the linked list
◆ LIST_FIELDS
#define LIST_FIELDS |
( |
|
t, |
|
|
|
name |
|
) |
| |
The pointers in the linked list's items. Use this in the item structure
◆ LIST_HEAD_INIT
#define LIST_HEAD_INIT |
( |
|
head | ) |
|
Initialize the list's head
- Parameters
-
[in,out] | head | Linked list begin variable |
◆ LIST_INIT
#define LIST_INIT |
( |
|
name, |
|
|
|
item |
|
) |
| |
Initialize a list item
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in,out] | item | The to be initialized item |
◆ LIST_PREPEND
#define LIST_PREPEND |
( |
|
name, |
|
|
|
head, |
|
|
|
item |
|
) |
| |
Prepend an item to the list
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in,out] | head | Linked list begin variable |
[in,out] | item | The to be prepended item |
◆ LIST_APPEND
#define LIST_APPEND |
( |
|
name, |
|
|
|
head, |
|
|
|
item |
|
) |
| |
Append an item to the list
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in,out] | head | Linked list begin variable |
[in,out] | item | The to be appended item |
If the linked list is empty, head gets modified.
◆ LIST_REMOVE
#define LIST_REMOVE |
( |
|
name, |
|
|
|
head, |
|
|
|
item |
|
) |
| |
Remove an item from the list
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in,out] | head | Linked list begin variable |
[in] | item | The to be removed member |
◆ LIST_FIND_HEAD
#define LIST_FIND_HEAD |
( |
|
name, |
|
|
|
item, |
|
|
|
head |
|
) |
| |
Find the head of a list
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in] | item | Member to start the search |
[in] | head | Where to store the pointer to the head element |
const struct A *list_head;
struct A *some_element_in_the_list;
#define LIST_FIND_HEAD(name, item, head)
Definition: list.h:113
◆ LIST_FIND_TAIL
#define LIST_FIND_TAIL |
( |
|
name, |
|
|
|
item, |
|
|
|
tail |
|
) |
| |
Find the tail of a list
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in] | item | Member to start the search |
[in] | tail | Where to store the pointer to the tail element |
const struct A *list_tail;
struct A *some_element_in_the_list;
◆ LIST_INSERT_AFTER
#define LIST_INSERT_AFTER |
( |
|
name, |
|
|
|
head, |
|
|
|
a, |
|
|
|
b |
|
) |
| |
Insert an item after another one (a = where, b = what)
◆ LIST_INSERT_BEFORE
#define LIST_INSERT_BEFORE |
( |
|
name, |
|
|
|
head, |
|
|
|
a, |
|
|
|
b |
|
) |
| |
Insert an item before another one (a = where, b = what)
◆ LIST_JUST_US
#define LIST_JUST_US |
( |
|
name, |
|
|
|
item |
|
) |
| |
Check if the given linked list member is the only member
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[in] | item | The known member |
- Return values
-
true | If this member is the only member |
false | There are more than this member in the linked list |
◆ LIST_FOREACH
#define LIST_FOREACH |
( |
|
name, |
|
|
|
i, |
|
|
|
head |
|
) |
| |
Iterate over all elements of a linked list beginning with head
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[out] | i | A variable to receive a pointer to the current linked structure |
[in] | head | Where everything starts |
- Attention
- This macro creates code to iterate over the list in a read-only manner, e.g. you cannot change the current element. If you want to, refer LIST_FOREACH_SAFE() instead
Example: struct A is the linked list. It has one member defined via LIST_FIELDS, LIST_FIELDS(struct A, list)
;
To iterate over this list:
const struct A *current;
{ read from current; }
#define LIST_FOREACH(name, i, head)
Definition: list.h:229
◆ LIST_FOREACH_SAFE
#define LIST_FOREACH_SAFE |
( |
|
name, |
|
|
|
i, |
|
|
|
n, |
|
|
|
head |
|
) |
| |
Iterate safely over all elements of a linked list beginning with head
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[out] | i | A variable to receive a pointer to the current linked structure |
[out] | n | A variable to receive a pointer to the next linked structure |
[in] | head | Where everything starts |
- Note
- Safely means you can modify the current element (deleting for example) and this loop will still continue
Example: struct A is the linked list. It has one member defined via LIST_FIELDS, LIST_FIELDS(struct A, list)
;
To iterate over this list:
struct A *current;
struct A *next;
{ remove current from list; }
#define LIST_FOREACH_SAFE(name, i, n, head)
Definition: list.h:253
◆ LIST_FOREACH_BEFORE
#define LIST_FOREACH_BEFORE |
( |
|
name, |
|
|
|
i, |
|
|
|
p |
|
) |
| |
Iterate backwards over the list, beginning with the given member
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[out] | i | A variable to receive a pointer to the current linked structure |
[in] | p | A member in the middle of the list |
- Attention
- This macro creates code to iterate over the list in a read-only manner, e.g. you cannot change the current element.
◆ LIST_FOREACH_AFTER
#define LIST_FOREACH_AFTER |
( |
|
name, |
|
|
|
i, |
|
|
|
p |
|
) |
| |
Iterate forwards over the list, beginning with the given member
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[out] | i | A variable to receive a pointer to the current linked structure |
[in] | p | A member in the middle of the list |
- Attention
- This macro creates code to iterate over the list in a read-only manner, e.g. you cannot change the current element.
◆ LIST_FOREACH_OTHERS
#define LIST_FOREACH_OTHERS |
( |
|
name, |
|
|
|
i, |
|
|
|
p |
|
) |
| |
Iterate through all the members of the list p is included in, but skip over p
- Parameters
-
[in] | name | The name of the linked list member in the linked structure |
[out] | i | A variable to receive a pointer to the current linked structure |
[in] | p | A member in the middle of the list |
◆ LIST_LOOP_BUT_ONE
#define LIST_LOOP_BUT_ONE |
( |
|
name, |
|
|
|
i, |
|
|
|
head, |
|
|
|
p |
|
) |
| |
Loop starting from p->next until p->prev. p can be adjusted meanwhile.
◆ LIST_IS_EMPTY
#define LIST_IS_EMPTY |
( |
|
head | ) |
|
Check if the linked list is empty
- Parameters
-
[in] | head | Start of the list |
- Return values
-
true | Linked list is empty |
false | Linked list is filled |