-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
69 lines (46 loc) · 2 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
65
66
67
68
69
#ifndef LIST_H
#define LIST_H
#include <stddef.h>
#define container_of(ptr, type, member) \
((type *)((void *)(ptr) - offsetof (type, member)))
#define attr_nonnull(...) __attribute__ ((nonnull (__VA_ARGS__)))
typedef struct list_t list_t;
typedef struct list_node_t list_node_t;
struct list_node_t
{
list_node_t *prev;
list_node_t *next;
};
struct list_t
{
size_t size;
list_node_t *head;
list_node_t *tail;
};
#define LIST_INIT \
(list_t) {}
extern list_node_t *list_at (const list_t *list, size_t index)
attr_nonnull (1);
extern void list_push_front (list_t *list, list_node_t *node)
attr_nonnull (1, 2);
extern void list_push_back (list_t *list, list_node_t *node)
attr_nonnull (1, 2);
extern void list_insert_at (list_t *list, size_t index, list_node_t *node)
attr_nonnull (1, 3);
extern void list_insert_front (list_t *list, list_node_t *pos,
list_node_t *node) attr_nonnull (1, 2, 3);
extern void list_insert_back (list_t *list, list_node_t *pos,
list_node_t *node) attr_nonnull (1, 2, 3);
extern void list_erase (list_t *list, list_node_t *node) attr_nonnull (1, 2);
extern void list_erase_at (list_t *list, size_t index) attr_nonnull (1);
extern void list_pop_front (list_t *list) attr_nonnull (1);
extern void list_pop_back (list_t *list) attr_nonnull (1);
/* **************************************************************** */
/* ext */
/* **************************************************************** */
typedef void list_visit_t (list_node_t *n);
typedef int list_comp_t (const list_node_t *a, const list_node_t *b);
extern list_node_t *list_find (const list_t *list, const list_node_t *target,
list_comp_t *comp) attr_nonnull (1, 2, 3);
extern void list_visit (list_t *list, list_visit_t *visit) attr_nonnull (1, 2);
#endif