• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* List definitions. */
2 #define	ql_head(a_type)							\
3 struct {								\
4 	a_type *qlh_first;						\
5 }
6 
7 #define	ql_head_initializer(a_head) {NULL}
8 
9 #define	ql_elm(a_type)	qr(a_type)
10 
11 /* List functions. */
12 #define	ql_new(a_head) do {						\
13 	(a_head)->qlh_first = NULL;					\
14 } while (0)
15 
16 #define	ql_elm_new(a_elm, a_field) qr_new((a_elm), a_field)
17 
18 #define	ql_first(a_head) ((a_head)->qlh_first)
19 
20 #define	ql_last(a_head, a_field)					\
21 	((ql_first(a_head) != NULL)					\
22 	    ? qr_prev(ql_first(a_head), a_field) : NULL)
23 
24 #define	ql_next(a_head, a_elm, a_field)					\
25 	((ql_last(a_head, a_field) != (a_elm))				\
26 	    ? qr_next((a_elm), a_field)	: NULL)
27 
28 #define	ql_prev(a_head, a_elm, a_field)					\
29 	((ql_first(a_head) != (a_elm)) ? qr_prev((a_elm), a_field)	\
30 				       : NULL)
31 
32 #define	ql_before_insert(a_head, a_qlelm, a_elm, a_field) do {		\
33 	qr_before_insert((a_qlelm), (a_elm), a_field);			\
34 	if (ql_first(a_head) == (a_qlelm)) {				\
35 		ql_first(a_head) = (a_elm);				\
36 	}								\
37 } while (0)
38 
39 #define	ql_after_insert(a_qlelm, a_elm, a_field)			\
40 	qr_after_insert((a_qlelm), (a_elm), a_field)
41 
42 #define	ql_head_insert(a_head, a_elm, a_field) do {			\
43 	if (ql_first(a_head) != NULL) {					\
44 		qr_before_insert(ql_first(a_head), (a_elm), a_field);	\
45 	}								\
46 	ql_first(a_head) = (a_elm);					\
47 } while (0)
48 
49 #define	ql_tail_insert(a_head, a_elm, a_field) do {			\
50 	if (ql_first(a_head) != NULL) {					\
51 		qr_before_insert(ql_first(a_head), (a_elm), a_field);	\
52 	}								\
53 	ql_first(a_head) = qr_next((a_elm), a_field);			\
54 } while (0)
55 
56 #define	ql_remove(a_head, a_elm, a_field) do {				\
57 	if (ql_first(a_head) == (a_elm)) {				\
58 		ql_first(a_head) = qr_next(ql_first(a_head), a_field);	\
59 	}								\
60 	if (ql_first(a_head) != (a_elm)) {				\
61 		qr_remove((a_elm), a_field);				\
62 	} else {							\
63 		ql_first(a_head) = NULL;				\
64 	}								\
65 } while (0)
66 
67 #define	ql_head_remove(a_head, a_type, a_field) do {			\
68 	a_type *t = ql_first(a_head);					\
69 	ql_remove((a_head), t, a_field);				\
70 } while (0)
71 
72 #define	ql_tail_remove(a_head, a_type, a_field) do {			\
73 	a_type *t = ql_last(a_head, a_field);				\
74 	ql_remove((a_head), t, a_field);				\
75 } while (0)
76 
77 #define	ql_foreach(a_var, a_head, a_field)				\
78 	qr_foreach((a_var), ql_first(a_head), a_field)
79 
80 #define	ql_reverse_foreach(a_var, a_head, a_field)			\
81 	qr_reverse_foreach((a_var), ql_first(a_head), a_field)
82