23 #ifndef LELY_UTIL_DLLIST_H_
24 #define LELY_UTIL_DLLIST_H_
31 #ifndef LELY_UTIL_DLLIST_INLINE
32 #define LELY_UTIL_DLLIST_INLINE static inline
105 #define dlnode_foreach(first, node) dlnode_foreach_(__COUNTER__, first, node)
107 #define dlnode_foreach(first, node) dlnode_foreach_(__LINE__, first, node)
109 #define dlnode_foreach_(n, first, node) dlnode_foreach__(n, first, node)
111 #define dlnode_foreach__(n, first, node) \
112 for (struct dlnode *node = (first), \
113 *_dlnode_next_##n = (node) ? (node)->next : NULL; \
114 (node); (node) = _dlnode_next_##n, \
115 _dlnode_next_##n = (node) ? (node)->next : NULL)
232 #define dllist_foreach(list, node) dlnode_foreach (dllist_first(list), node)
234 LELY_UTIL_DLLIST_INLINE
void
243 LELY_UTIL_DLLIST_INLINE
int
256 LELY_UTIL_DLLIST_INLINE
int
269 LELY_UTIL_DLLIST_INLINE
void
280 LELY_UTIL_DLLIST_INLINE
void
289 LELY_UTIL_DLLIST_INLINE
int
297 LELY_UTIL_DLLIST_INLINE
size_t
308 LELY_UTIL_DLLIST_INLINE
void
315 if ((node->
next = list->first))
322 LELY_UTIL_DLLIST_INLINE
void
329 if ((node->
prev = list->last))
336 LELY_UTIL_DLLIST_INLINE
struct dlnode *
341 struct dlnode *node = list->first;
343 if ((list->first = list->first->next))
344 list->first->prev = NULL;
351 LELY_UTIL_DLLIST_INLINE
struct dlnode *
356 struct dlnode *node = list->last;
358 if ((list->last = list->last->prev))
359 list->last->next = NULL;
366 LELY_UTIL_DLLIST_INLINE
void
376 LELY_UTIL_DLLIST_INLINE
void
386 LELY_UTIL_DLLIST_INLINE
void
393 list->first = node->
next;
395 list->last = node->
prev;
399 LELY_UTIL_DLLIST_INLINE
struct dllist *
419 LELY_UTIL_DLLIST_INLINE
struct dlnode *
427 LELY_UTIL_DLLIST_INLINE
struct dlnode *
void dlnode_remove(struct dlnode *node)
Removes node from a doubly-list.
void dllist_push_back(struct dllist *list, struct dlnode *node)
Pushes a node to the back of a doubly-linked list.
int dlnode_insert_before(struct dlnode *next, struct dlnode *node)
Inserts node before next.
struct dlnode * dllist_pop_back(struct dllist *list)
Pops a node from the back of a doubly-linked list.
void dllist_init(struct dllist *list)
Initializes a doubly-linked list.
void dllist_insert_after(struct dllist *list, struct dlnode *prev, struct dlnode *node)
Inserts a node into a doubly-linked list.
int dlnode_insert_after(struct dlnode *prev, struct dlnode *node)
Inserts node after prev.
int dllist_empty(const struct dllist *list)
Returns 1 if the doubly-linked list is empty, and 0 if not.
#define dllist_foreach(list, node)
Iterates in order over each node in a doubly-linked list.
size_t dllist_size(const struct dllist *list)
Returns the size (in number of nodes) of a doubly-linked list.
void dllist_push_front(struct dllist *list, struct dlnode *node)
Pushes a node to the front of a doubly-linked list.
int dllist_contains(const struct dllist *list, const struct dlnode *node)
Checks if a node is part of a doubly-linked list.
struct dlnode * dllist_last(const struct dllist *list)
Returns a pointer to the last node in a doubly-linked list.
void dllist_insert_before(struct dllist *list, struct dlnode *next, struct dlnode *node)
Inserts a node into a doubly-linked list.
struct dlnode * dllist_first(const struct dllist *list)
Returns a pointer to the first node in a doubly-linked list.
struct dllist * dllist_append(struct dllist *dst, struct dllist *src)
Appends the doubly-linked list at src to the one at dst.
struct dlnode * dllist_pop_front(struct dllist *list)
Pops a node from the front of a doubly-linked list.
void dlnode_init(struct dlnode *node)
Initializes a node in a doubly-linked list.
void dllist_remove(struct dllist *list, struct dlnode *node)
Removes a node from a doubly-linked list.
This header file is part of the Lely libraries; it contains the compiler feature definitions.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
struct dlnode * last
A pointer to the last node in the list.
struct dlnode * first
A pointer to the first node in the list.
A node in a doubly-linked list.
struct dlnode * next
A pointer to the next node in the list.
struct dlnode * prev
A pointer to the previous node in the list.