Skip to content

Commit 4edbc39

Browse files
committed
Add interface for doubly linked list
1 parent 750627c commit 4edbc39

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

kernel/include/list.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef LIST_H_WYVXF5HO
2+
#define LIST_H_WYVXF5HO
3+
4+
#define NULL_NODE (node_t *)0x0
5+
6+
typedef struct _node_t {
7+
struct _node_t *prev;
8+
struct _node_t *next;
9+
void *value;
10+
void *owner; // WHAT IS THIS?
11+
} __attribute__((packed)) node_t;
12+
13+
typedef struct _list_t {
14+
node_t *head;
15+
node_t *tail;
16+
size_t size;
17+
} __attribute__((packed)) list_t;
18+
19+
list_t * list_init (void);
20+
void list_free (list_t *list);
21+
void list_destroy (list_t *list);
22+
23+
node_t * list_insert (list_t *list, node_t *node);
24+
node_t * list_insert_at (list_t *list, size_t index);
25+
26+
void list_remove (list_t *list, node_t *node);
27+
void list_remove_at (list_t *list, size_t index);
28+
29+
node_t * list_node_at (list_t *list, size_t index);
30+
size_t list_index_of (list_t *list, node_t *node);
31+
32+
node_t * list_find_node (list_t *list, void *value);
33+
size_t list_find_index (list_t *list, void *value);
34+
35+
#define list_foreach(item, list) \
36+
for (node_t *item = list->head; item->next != NULL_NODE; item = item->next)
37+
38+
#define list_foreach_rev(item, list) \
39+
for (node_t *item = list->tail; item->prev != NULL_NODE; item = item->prev)
40+
41+
#endif /* end of include guard: LIST_H_WYVXF5HO */

0 commit comments

Comments
 (0)