-
Notifications
You must be signed in to change notification settings - Fork 0
/
llist.h
45 lines (38 loc) · 1.01 KB
/
llist.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
#ifndef _LLIST_H
# define _LLIST_H
/*
* Linked list library
* parsa mahmoudy
*/
#define L_LINK(type) struct { type *next; type *prev; }
#define L_LINK_NEXT(o) ((o)->link.next)
#define L_LINK_PREV(o) ((o)->link.prev)
#define L_LINK_SNEXT(s,d) ((s)->link.next = d)
#define L_LINK_SPREV(s,d) ((s)->link.prev = d)
#define L_LINK_RESET(o) { \
o->link.next = o->link.prev = NULL; \
}
#define L_LINK_INSERT(l,n) { \
if (L_LINK_NEXT(l) != NULL) { \
L_LINK_SPREV(L_LINK_NEXT(l), n); \
L_LINK_SNEXT(n,L_LINK_NEXT(l)); \
} \
L_LINK_SPREV(n,l); \
L_LINK_SNEXT(l,n); \
}
#define L_LINK_REMOVE(o) { \
int have_next = L_LINK_NEXT(o) != NULL; \
int have_prev = L_LINK_PREV(o) != NULL; \
if (have_next) { \
if (have_prev) {\
L_LINK_SNEXT(L_LINK_PREV(o),L_LINK_NEXT(o)); \
L_LINK_SPREV(L_LINK_NEXT(o),L_LINK_PREV(o)); \
} else \
L_LINK_SPREV(L_LINK_NEXT(o),NULL); \
} \
if (have_prev && !have_next) \
L_LINK_SNEXT(L_LINK_PREV(o),NULL); \
L_LINK_SNEXT(o,NULL); \
L_LINK_SPREV(o,NULL); \
}
#endif