-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxqx_dllist.h
65 lines (58 loc) · 1.43 KB
/
xqx_dllist.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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2006-2008 Ondrej 'SanTiago' Zajicek
* Copyright (c) 2021 Cyril Hrubis <[email protected]>
*/
#ifndef XQX_DLLIST_H__
#define XQX_DLLIST_H__
#include <stddef.h>
#define DLL_REMOVE(HEAD,FIRST,LAST,NODE,PREV,NEXT) \
do { \
if (!(NODE)->NEXT) \
(HEAD)->LAST = (NODE)->PREV; \
else \
(NODE)->NEXT->PREV = (NODE)->PREV; \
\
if (!(NODE)->PREV) \
(HEAD)->FIRST = (NODE)->NEXT; \
else \
(NODE)->PREV->NEXT = (NODE)->NEXT; \
\
(NODE)->PREV = NULL; \
(NODE)->NEXT = NULL; \
\
} while(0)
#define DLL_PREPEND(HEAD,FIRST,LAST,NODE,PREV,NEXT) \
do { \
(NODE)->PREV = NULL; \
(NODE)->NEXT = (HEAD)->FIRST; \
\
if (!(HEAD)->FIRST) { \
(HEAD)->FIRST = NODE; \
(HEAD)->LAST = NODE; \
} else { \
(HEAD)->FIRST->PREV = NODE; \
(HEAD)->FIRST = NODE; \
} \
} while(0)
#define DLL_APPEND(HEAD,FIRST,LAST,NODE,PREV,NEXT) \
do { \
(NODE)->PREV = (HEAD)->LAST; \
(NODE)->NEXT = NULL; \
\
if (!(HEAD)->FIRST) { \
(HEAD)->FIRST = NODE; \
(HEAD)->LAST = NODE; \
} else { \
(HEAD)->LAST->NEXT = NODE; \
(HEAD)->LAST = NODE; \
} \
} while(0)
#define DLL_INSERT_AFTER(WHERE,NODE,PREV,NEXT) \
do { \
(NODE)->PREV = WHERE; \
(NODE)->NEXT = WHERE->NEXT; \
(WHERE)->NEXT = NODE; \
(NODE)->NEXT->PREV = NODE; \
} while(0)
#endif /* XQX_DLLIST_H__ */