1 #define MAIN(x) slist##x
5 static a_size
a_slist_len(a_slist
const *ctx
)
9 A_SLIST_FOREACH(it
, ctx
) { ++count
; }
13 static void test(void)
21 a_slist_node
*it
, *at
;
22 a_slist
*list1
, *list2
, *list3
;
23 list1
= a_new(a_slist
, A_NULL
, 1);
25 for (i
= 0; i
!= 10; ++i
)
27 data
*node
= a_new(data
, A_NULL
, 1);
29 a_slist_add_tail(list1
, &node
->node
);
31 list2
= a_new(a_slist
, A_NULL
, 1);
33 for (i
= 14; i
!= 9; --i
)
35 data
*node
= a_new(data
, A_NULL
, 1);
37 a_slist_add_head(list2
, &node
->node
);
39 list3
= a_new(a_slist
, A_NULL
, 1);
41 for (i
= 15; i
!= 20; ++i
)
43 data
*node
= a_new(data
, A_NULL
, 1);
45 a_slist_add(list3
, list3
->tail
, &node
->node
);
48 a_slist_mov(list2
, list3
, &list3
->head
);
50 a_slist_mov(list3
, list1
, list1
->tail
);
52 A_SLIST_FOREACH(it
, list1
)
54 data
*node
= a_slist_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
55 printf("%i ", node
->data
.i
);
57 printf("%" A_PRIz
"u", a_slist_len(list1
));
58 for (i
= 0; i
!= 10; ++i
)
60 data
*node
= a_slist_entry_next(&list1
->head
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
61 a_slist_del_head(list1
);
64 A_SLIST_FORSAFE(it
, at
, list1
)
66 data
*node
= a_slist_entry(it
, data
, node
); /* NOLINT(performance-no-int-to-ptr) */
67 a_slist_del(list1
, at
);
71 if (list1
->head
.next
== &list1
->head
&&
72 list2
->head
.next
== &list2
->head
&&
73 list3
->head
.next
== &list3
->head
)
83 static void null(void)
85 static a_slist_node node1
= A_SLIST_NODE
;
86 static a_slist_node node2
= A_SLIST_NODE
;
87 static a_slist list1
= A_SLIST_INIT(list1
);
88 static a_slist list2
= A_SLIST_INIT(list2
);
92 a_slist_mov(&list2
, &list1
, &list1
.head
);
93 a_slist_mov(&list2
, &list1
, list1
.tail
);
94 a_slist_del(&list1
, &list1
.head
);
95 a_slist_del(&list1
, list1
.tail
);
96 a_slist_del_head(&list2
);
97 a_slist_del_head(&list2
);
100 a_slist_init(&list2
);
101 a_slist_add(&list1
, &list1
.head
, &node1
);
102 a_slist_add(&list1
, &list1
.head
, &node1
);
103 a_slist_del(&list1
, &node1
);
104 a_slist_add(&list1
, list1
.tail
, &node1
);
105 a_slist_add(&list1
, &node1
, &node1
);
106 a_slist_add_head(&list1
, &node1
);
107 a_slist_add_tail(&list2
, &node2
);
108 a_slist_mov(&list2
, &list1
, &list1
.head
);
109 a_slist_mov(&list2
, &list1
, list1
.tail
);
112 int main(int argc
, char *argv
[]) /* NOLINT(misc-definitions-in-headers) */