-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsllist.h
50 lines (39 loc) · 2.04 KB
/
sllist.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
#ifndef _SLLIST_H
#define _SLLIST_H
struct sllist {
struct sllist *next;
};
#define sllist_init(list) \
do { \
(list)->next = (list); \
} while (0)
#define sllist_empty(head) ((head)->next == (head))
#define sllist_first(head) (head)->next
#define sllist_for_each(head, e) \
for ((e)=(head)->next; \
(e)!=(head); \
(e)=(e)->next)
#define sllist_for_each_prev(head, e, p) \
for ((p)=(head), (e)=(head)->next; \
(e)!=(head); \
(p)=(e), (e)=(e)->next)
#define sllist_for_each_safe(head, e, t) \
for ((e)=(head)->next, (t)=(head)->next->next; \
(e)!=(head); \
(e)=(t), (t)=(t)->next)
#define sllist_for_each_safe_prev(head, e, p, t) \
for ((p)=(head), (e)=(head)->next, (t)=(head)->next->next; \
(e)!=(head); \
(p)=((t)==(head)->next?(head):(e)), (e)=(t), (t)=(t)->next)
#define sllist_detach(e, p) \
do { \
(p)->next = (e)->next; \
/* safe detach */ \
(e)->next = (e); \
} while (0)
#define sllist_add(head, e) \
do { \
(e)->next = (head)->next; \
(head)->next = (e); \
} while (0)
#endif