MOS Source Code
Loading...
Searching...
No Matches
list.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
4
5// Note: The nullability of each parameter is not checked, because results will be the same no matter what.
6// (i.e. kernel panic / process termination)
7
15void linked_list_init(list_node_t *node)
16{
17 node->prev = node;
18 node->next = node;
19}
20
21bool list_is_empty(const list_node_t *head)
22{
23 return head->next == head;
24}
25
26void list_node_remove(list_node_t *node)
27{
28 node->prev->next = node->next;
29 node->next->prev = node->prev;
30
31 // detach the node from the list
32 node->next = node;
33 node->prev = node;
34}
35
36// ! Internal API
48static void list_node_insert(list_node_t *prev, list_node_t *new_node, list_node_t *next)
49{
50 new_node->prev = prev;
51 new_node->next = next;
52 prev->next = new_node;
53 next->prev = new_node;
54}
55
56list_node_t *list_node_pop(list_node_t *head)
57{
58 list_node_t *node = head->next;
59 list_node_remove(node);
60 return node;
61}
62
63void list_node_prepend(list_node_t *head, list_node_t *item)
64{
65 list_node_insert(head, item, head->next);
66}
67
68void list_node_append(list_node_t *head, list_node_t *item)
69{
70 // The list is circular, so accessing the list tail is like the prev of its head.
71 list_node_insert(head->prev, item, head);
72}
73
74void list_node_insert_before(list_node_t *element, list_node_t *item)
75{
76 list_node_insert(element->prev, item, element);
77}
78
79void list_node_insert_after(list_node_t *element, list_node_t *item)
80{
81 list_node_insert(element, item, element->next);
82}
void linked_list_init(list_node_t *node)
Initialise a circular double linked list.
Definition list.c:15
list_node_t * list_node_pop(list_node_t *head)
Definition list.c:56
void list_node_append(list_node_t *head, list_node_t *item)
Definition list.c:68
void list_node_insert_before(list_node_t *element, list_node_t *item)
Definition list.c:74
void list_node_prepend(list_node_t *head, list_node_t *item)
Definition list.c:63
bool list_is_empty(const list_node_t *head)
Definition list.c:21
void list_node_remove(list_node_t *node)
Definition list.c:26
void list_node_insert_after(list_node_t *element, list_node_t *item)
Definition list.c:79
static void list_node_insert(list_node_t *prev, list_node_t *new_node, list_node_t *next)
Insert a node into a list.
Definition list.c:48