Add _reverse for I-LIST

This commit is contained in:
Patrick Pelissier committed 2018-10-01 21:22:19 +02:00
1 parent 46c2e33096
commit 4f3dad4bea
2 files changed
+23

No files matched your search

+16
View File
@@ -570,6 +570,22 @@ typedef struct ilist_head_s {
e->name.prev->next = &e->name; \
ILISTI_CONTRACT(name, d); \
ILISTI_CONTRACT(name, e); \
} \
\
static inline void \
M_C(name, _reverse)(list_t list) \
{ \
ILISTI_CONTRACT(name, list); \
struct ilist_head_s *next, *it; \
for(it = list->name.next ; it != &list->name; it = next) { \
next = it->next; \
it->next = it->prev; \
it->prev = next; \
} \
next = it->next; \
it->next = it->prev; \
it->prev = next; \
ILISTI_CONTRACT(name, list); \
} \
#endif
+7
View File
@@ -174,6 +174,13 @@ static void test2(void)
n++;
}
assert (n == NUM);
ilist_tname_reverse(list1);
for M_EACH(item, list1, ILIST_OPLIST(ilist_tname)) {
n--;
assert (n == item->n);
}
assert (n == 0);
}
M_LET(list1, list2, ILIST_OPLIST(ilist_tname)) {
for(int i = 0; i < NUM; i++)