forked from vk2tds/libosdp_arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
64 lines (47 loc) · 1.49 KB
/
list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright (c) 2020-2021 Siddharth Chandrasekaran <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#ifndef _UTILS_LIST_H_
#define _UTILS_LIST_H_
#include <stddef.h>
typedef struct node_s node_t;
struct node_s {
node_t *next;
node_t *prev;
};
struct list_s {
node_t *head;
node_t *tail;
};
typedef struct list_s list_t;
#define LIST_FOREACH(list, node) \
for(node_t *node = (list)->head; node != NULL; node = node->next)
void list_init(list_t *list);
void list_append(list_t *list, node_t *node);
void list_appendleft(list_t *list, node_t *node);
int list_pop(list_t *list, node_t **node);
int list_popleft(list_t *list, node_t **node);
void list_remove_node(list_t *list, node_t *node);
int list_remove_nodes(list_t *list, node_t *start, node_t *end);
void list_insert_node(list_t *list, node_t *after, node_t *new);
int list_insert_nodes(list_t *list, node_t *after, node_t *start, node_t *end);
/*--- singly-linked list ---*/
typedef struct snode_s snode_t;
struct snode_s {
snode_t *next;
};
struct slist_s {
snode_t *head;
};
typedef struct slist_s slist_t;
void slist_init(slist_t *list);
void slist_append(slist_t *list, snode_t *after, snode_t *node);
void slist_appendleft(slist_t *list, snode_t *node);
int slist_pop(slist_t *list, snode_t *after, snode_t **node);
int slist_popleft(slist_t *list, snode_t **node);
int slist_remove_node(slist_t *list, snode_t *node);
void slist_insert_node(slist_t *list, snode_t *after, snode_t *new);
#endif /* _UTILS_LIST_H_ */