Lely core libraries
2.2.5
|
Go to the documentation of this file.
23 #ifndef LELY_UTIL_DLLIST_H_
24 #define LELY_UTIL_DLLIST_H_
30 #ifndef LELY_UTIL_DLLIST_INLINE
31 #define LELY_UTIL_DLLIST_INLINE static inline
104 #define dlnode_foreach(first, node) dlnode_foreach_(__COUNTER__, first, node)
106 #define dlnode_foreach(first, node) dlnode_foreach_(__LINE__, first, node)
108 #define dlnode_foreach_(n, first, node) dlnode_foreach__(n, first, node)
110 #define dlnode_foreach__(n, first, node) \
111 for (struct dlnode *node = (first), \
112 *_dlnode_next_##n = (node) ? (node)->next : NULL; \
113 (node); (node) = _dlnode_next_##n, \
114 _dlnode_next_##n = (node) ? (node)->next : NULL)
224 #define dllist_foreach(list, node) dlnode_foreach (dllist_first(list), node)
288 if ((node->
next = list->first))
299 if ((node->
prev = list->last))
309 struct dlnode *node = list->first;
311 if ((list->first = list->first->next))
312 list->first->prev = NULL;
322 struct dlnode *node = list->last;
324 if ((list->last = list->last->prev))
325 list->last->next = NULL;
352 list->first = node->
next;
354 list->last = node->
prev;
391 #endif // !LELY_UTIL_DLLIST_H_
void dllist_init(struct dllist *list)
Initializes 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.
struct dlnode * first
A pointer to the first node in the list.
void dllist_remove(struct dllist *list, struct dlnode *node)
Removes a node from a doubly-linked list.
struct dlnode * last
A pointer to the last node in the list.
struct dlnode * next
A pointer to the next node in the list.
size_t dllist_size(const struct dllist *list)
Returns the size (in number of nodes) of a doubly-linked list.
#define dllist_foreach(list, node)
Iterates in order over each 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_first(const struct dllist *list)
Returns a pointer to the first node in a doubly-linked list.
void dlnode_init(struct dlnode *node)
Initializes a node in a doubly-linked 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.
void dlnode_remove(struct dlnode *node)
Removes node from a doubly-list.
int dlnode_insert_after(struct dlnode *prev, struct dlnode *node)
Inserts node after prev.
struct dlnode * prev
A pointer to the previous node in the list.
struct dlnode * dllist_last(const struct dllist *list)
Returns a pointer to the last node in a doubly-linked list.
struct dlnode * dllist_pop_back(struct dllist *list)
Pops a node from the back of a doubly-linked list.
struct dlnode * dllist_pop_front(struct dllist *list)
Pops a node from the front of a doubly-linked list.
int dllist_empty(const struct dllist *list)
Returns 1 if the doubly-linked list is empty, and 0 if not.
A 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.
void dllist_insert_after(struct dllist *list, struct dlnode *prev, struct dlnode *node)
Inserts a node into a doubly-linked list.