mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
list: add list definition and drain operation
This commit is contained in:
@@ -10,6 +10,7 @@ typedef struct _list_node {
|
||||
} list_node_t;
|
||||
|
||||
#define LIST_INIT_VALUE(NAME) ((list_node_t) {.prev = &(NAME), .next = &(NAME)})
|
||||
#define LIST_DEFINE(NAME) list_node_t NAME = LIST_INIT_VALUE(NAME)
|
||||
|
||||
static inline void list_init(list_node_t *list) {
|
||||
list->prev = list;
|
||||
@@ -73,4 +74,10 @@ static inline list_node_t *list_pop_back(list_node_t *list) {
|
||||
ITER != (LIST); \
|
||||
ITER = NEXT, NEXT = ITER->next)
|
||||
|
||||
#define list_drain_front(LIST, ITER) \
|
||||
for (list_node_t *ITER = list_pop_front(LIST); ITER != NULL; ITER = list_pop_front(LIST))
|
||||
|
||||
#define list_drain_back(LIST, ITER) \
|
||||
for (list_node_t *ITER = list_pop_back(LIST); ITER != NULL; ITER = list_pop_back(LIST))
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user