diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-09-19 12:14:06 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-09-19 12:14:06 -0400 |
commit | cf2eb17c48a23d49bf517df58e34e30529c16576 (patch) | |
tree | e746c589fb25d62bdc7ea9803a8f2e983b563ba5 /src/list.h | |
parent | 5307ef2ed38b665892798aa10295dd68401a38df (diff) | |
download | bfs-cf2eb17c48a23d49bf517df58e34e30529c16576.tar.xz |
list: New drain_slist() macro
Diffstat (limited to 'src/list.h')
-rw-r--r-- | src/list.h | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -429,6 +429,33 @@ static inline void *slist_remove_impl(void *ret, void *cursor, void *next, size_ item = _next) /** + * Loop over a singly-linked list, popping each item. + * + * @param type + * The list item type. + * @param item + * The induction variable name. + * @param list + * The list to drain. + * @param node (optional) + * If specified, use head->node.next rather than head->next. + */ +#define drain_slist(type, item, ...) \ + drain_slist_(type, item, __VA_ARGS__, ) + +#define drain_slist_(type, item, list, ...) \ + drain_slist__(type, item, (list), LIST_NEXT_(__VA_ARGS__)) + +#define drain_slist__(type, item, list, next) \ + for (type *item = list->head; item && \ + (SLIST_CHECK_(list), \ + list->head = item->next, \ + list->tail = list->head ? list->tail : &list->head, \ + item->next = NULL, \ + true); \ + item = list->head) + +/** * Initialize a doubly-linked list. * * @param list |