-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.h
63 lines (55 loc) · 1.52 KB
/
queue.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
/**
* Contains useful macros (GNU C only) to manipulate doubly-linked lists.
*
* These macros are type-independant. The names of 'prev' and 'next'
* fields are given as parameters.
*/
#ifndef QUEUE_H
#define QUEUE_H
#define dlist_is_empty_generic(list) \
((list) == NULL)
#define dlist_is_singleton_generic(list, prev, next) \
((list)->next == NULL)
#define dlist_push_head_generic(list, el, prev, next) ({ \
if(!dlist_is_empty_generic((list))) \
{ \
(list)->prev = (el); \
} \
(el)->prev = NULL; \
(el)->next = (list); \
(list) = (el); \
})
#define dlist_delete_head_generic(list, head, prev, next) ({ \
if(dlist_is_singleton_generic(list,prev,next)) \
{ \
(list) = NULL; \
} \
else \
{ \
(list) = (head)->next; \
(list)->prev = NULL; \
(head)->prev = NULL; \
(head)->next = NULL; \
} \
})
#define dlist_pop_head_generic(list, prev, next) ({ \
typeof(list) __el2pop = (list); \
dlist_delete_head_generic(list, __el2pop, prev, next); \
__el2pop; \
})
#define dlist_delete_el_generic(list, el, prev, next) ({ \
if((list) != (el)) \
{ \
(el)->prev->next = (el)->next; \
if((el)->next != NULL) \
{ \
(el)->next->prev = (el)->prev; \
} \
(el)->prev = NULL; \
(el)->next = NULL; \
} \
else{ \
dlist_delete_head_generic(list,el,prev,next); \
} \
})
#endif