23 #ifndef LELY_UTIL_SLLIST_H_
24 #define LELY_UTIL_SLLIST_H_
30 #ifndef LELY_UTIL_SLLIST_INLINE
31 #define LELY_UTIL_SLLIST_INLINE static inline
74 #define slnode_foreach(first, node) slnode_foreach_(__COUNTER__, first, node)
76 #define slnode_foreach(first, node) slnode_foreach_(__LINE__, first, node)
78 #define slnode_foreach_(n, first, node) slnode_foreach__(n, first, node)
80 #define slnode_foreach__(n, first, node) \
81 for (struct slnode *node = (first), \
82 *_slnode_next_##n = (node) ? (node)->next : NULL; \
83 (node); (node) = _slnode_next_##n, \
84 _slnode_next_##n = (node) ? (node)->next : NULL)
175 #define sllist_foreach(list, node) slnode_foreach (sllist_first(list), node)
186 *(list->plast = &list->first) = NULL;
207 if (!(node->
next = list->first))
208 list->plast = &node->
next;
216 list->plast = &(*list->plast)->
next;
223 struct slnode *node = list->first;
225 if (!(list->first = node->
next))
226 list->plast = &list->first;
This header file is part of the Lely libraries; it contains the compiler feature definitions.
void sllist_init(struct sllist *list)
Initializes a singly-linked list.
struct sllist * sllist_append(struct sllist *dst, struct sllist *src)
Appends the singly-linked list at src to the one at dst.
size_t sllist_size(const struct sllist *list)
Returns the size (in number of nodes) of a singly-linked list.
void sllist_push_front(struct sllist *list, struct slnode *node)
Pushes a node to the front of a singly-linked list.
struct slnode * sllist_remove(struct sllist *list, struct slnode *node)
Removes a node from a singly-linked list.
#define sllist_foreach(list, node)
Iterates in order over each node in a singly-linked list.
void sllist_push_back(struct sllist *list, struct slnode *node)
Pushes a node to the back of a singly-linked list.
struct slnode * sllist_pop_back(struct sllist *list)
Pops a node from the back of a singly-linked list.
void slnode_init(struct slnode *node)
Initializes a node in a singly-linked list.
int sllist_empty(const struct sllist *list)
Returns 1 if the singly-linked list is empty, and 0 if not.
struct slnode * sllist_last(const struct sllist *list)
Returns a pointer to the last node in a singly-linked list.
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
struct slnode * sllist_first(const struct sllist *list)
Returns a pointer to the first node in a singly-linked list.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
struct slnode * first
A pointer to the first node in the list.
struct slnode ** plast
A pointer to the next field of the last node in the list.
A node in a singly-linked list.
struct slnode * next
A pointer to the next node in the list.