23 #ifndef LELY_UTIL_SLLIST_H_
24 #define LELY_UTIL_SLLIST_H_
31 #ifndef LELY_UTIL_SLLIST_INLINE
32 #define LELY_UTIL_SLLIST_INLINE static inline
75 #define slnode_foreach(first, node) slnode_foreach_(__COUNTER__, first, node)
77 #define slnode_foreach(first, node) slnode_foreach_(__LINE__, first, node)
79 #define slnode_foreach_(n, first, node) slnode_foreach__(n, first, node)
81 #define slnode_foreach__(n, first, node) \
82 for (struct slnode *node = (first), \
83 *_slnode_next_##n = (node) ? (node)->next : NULL; \
84 (node); (node) = _slnode_next_##n, \
85 _slnode_next_##n = (node) ? (node)->next : NULL)
183 #define sllist_foreach(list, node) slnode_foreach (sllist_first(list), node)
185 LELY_UTIL_SLLIST_INLINE
void
193 LELY_UTIL_SLLIST_INLINE
void
198 *(list->plast = &list->first) = NULL;
201 LELY_UTIL_SLLIST_INLINE
int
209 LELY_UTIL_SLLIST_INLINE
size_t
220 LELY_UTIL_SLLIST_INLINE
void
226 if (!(node->
next = list->first))
227 list->plast = &node->
next;
231 LELY_UTIL_SLLIST_INLINE
void
238 list->plast = &(*list->plast)->
next;
242 LELY_UTIL_SLLIST_INLINE
struct slnode *
247 struct slnode *node = list->first;
249 if (!(list->first = node->
next))
250 list->plast = &list->first;
256 LELY_UTIL_SLLIST_INLINE
struct sllist *
270 LELY_UTIL_SLLIST_INLINE
struct slnode *
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.
int sllist_contains(const struct sllist *list, const struct slnode *node)
Checks if a node is part of a singly-linked list.
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.