C Container Collection (CCC)
Loading...
Searching...
No Matches
singly_linked_list.h
Go to the documentation of this file.
1
26#ifndef CCC_SINGLY_LINKED_LIST_H
27#define CCC_SINGLY_LINKED_LIST_H
28
30#include <stddef.h>
33#include "impl/impl_singly_linked_list.h"
34#include "types.h"
35
45typedef struct ccc_sll_ ccc_singly_linked_list;
46
55typedef struct ccc_sll_elem_ ccc_sll_elem;
56
74#define ccc_sll_init(list_name, struct_name, list_elem_field, alloc_fn, \
75 cmp_fn, aux_data) \
76 ccc_impl_sll_init(list_name, struct_name, list_elem_field, alloc_fn, \
77 cmp_fn, aux_data)
78
95 ccc_sll_elem *elem);
96
108#define ccc_sll_emplace_front(list_ptr, struct_initializer...) \
109 ccc_impl_sll_emplace_front(list_ptr, struct_initializer)
110
116
128 ccc_singly_linked_list *splice_sll,
129 ccc_sll_elem *splice);
130
145 ccc_sll_elem *pos,
146 ccc_singly_linked_list *splice_sll,
147 ccc_sll_elem *begin, ccc_sll_elem *end);
148
160
173 ccc_sll_elem *end);
174
183
195 ccc_sll_elem *end);
196
217
228[[nodiscard]] void *ccc_sll_begin(ccc_singly_linked_list const *sll);
229
235[[nodiscard]] void *ccc_sll_end(ccc_singly_linked_list const *sll);
236
242[[nodiscard]] void *ccc_sll_next(ccc_singly_linked_list const *sll,
243 ccc_sll_elem const *elem);
244
254[[nodiscard]] void *ccc_sll_front(ccc_singly_linked_list const *sll);
255
260[[nodiscard]] ccc_sll_elem *
262
267[[nodiscard]] ccc_sll_elem *
269
273[[nodiscard]] size_t ccc_sll_size(ccc_singly_linked_list const *sll);
274
278[[nodiscard]] bool ccc_sll_is_empty(ccc_singly_linked_list const *sll);
279
283[[nodiscard]] bool ccc_sll_validate(ccc_singly_linked_list const *sll);
284
289#ifdef SINGLY_LINKED_LIST_USING_NAMESPACE_CCC
290typedef ccc_sll_elem sll_elem;
291typedef ccc_singly_linked_list singly_linked_list;
292# define sll_init(args...) ccc_sll_init(args)
293# define sll_emplace_front(args...) ccc_sll_emplace_front(args)
294# define sll_push_front(args...) ccc_sll_push_front(args)
295# define sll_front(args...) ccc_sll_front(args)
296# define sll_pop_front(args...) ccc_sll_pop_front(args)
297# define sll_splice(args...) ccc_sll_splice(args)
298# define sll_splice_range(args...) ccc_sll_splice_range(args)
299# define sll_extract(args...) ccc_sll_extract(args)
300# define sll_extract_range(args...) ccc_sll_extract_range(args)
301# define sll_erase(args...) ccc_sll_erase(args)
302# define sll_erase_range(args...) ccc_sll_erase_range(args)
303# define sll_begin(args...) ccc_sll_begin(args)
304# define sll_end(args...) ccc_sll_end(args)
305# define sll_next(args...) ccc_sll_next(args)
306# define sll_begin_elem(args...) ccc_sll_begin_elem(args)
307# define sll_begin_sentinel(args...) ccc_sll_begin_sentinel(args)
308# define sll_size(args...) ccc_sll_size(args)
309# define sll_is_empty(args...) ccc_sll_is_empty(args)
310# define sll_validate(args...) ccc_sll_validate(args)
311# define sll_clear(args...) ccc_sll_clear(args)
312#endif /* SINGLY_LINKED_LIST_USING_NAMESPACE_CCC */
313
314#endif /* CCC_FORWARD_LIST_H */
ccc_result ccc_sll_splice_range(ccc_singly_linked_list *pos_sll, ccc_sll_elem *pos, ccc_singly_linked_list *splice_sll, ccc_sll_elem *begin, ccc_sll_elem *end)
Inserts the range of spliced elements before pos. O(N).
void * ccc_sll_push_front(ccc_singly_linked_list *sll, ccc_sll_elem *elem)
Push the type wrapping elem to the front of the list. O(1).
void * ccc_sll_erase(ccc_singly_linked_list *sll, ccc_sll_elem *elem)
Erases elem from the list returning the following element. O(N).
ccc_result ccc_sll_pop_front(ccc_singly_linked_list *sll)
Pop the front element from the list. O(1).
void * ccc_sll_end(ccc_singly_linked_list const *sll)
Return the sentinel at the end of the list. Do not access sentinel. O(1).
bool ccc_sll_validate(ccc_singly_linked_list const *sll)
Returns true if the invariants of the list hold.
void * ccc_sll_extract(ccc_singly_linked_list *sll, ccc_sll_elem *elem)
Extracts an element from the list without freeing it. O(N).
bool ccc_sll_is_empty(ccc_singly_linked_list const *sll)
Return true if the list is empty. O(1).
size_t ccc_sll_size(ccc_singly_linked_list const *sll)
Return the size of the list. O(1).
ccc_sll_elem * ccc_sll_begin_sentinel(ccc_singly_linked_list const *sll)
Return a pointer to the first list element in the list. O(1).
void * ccc_sll_erase_range(ccc_singly_linked_list *sll, ccc_sll_elem *begin, ccc_sll_elem *end)
Erases a range from the list returning the element after end. O(N).
struct ccc_sll_ ccc_singly_linked_list
A low overhead front tracking container with efficient push and pop.
Definition: singly_linked_list.h:45
ccc_sll_elem * ccc_sll_begin_elem(ccc_singly_linked_list const *sll)
Return a pointer to the first intrusive handle in the list. O(1).
void * ccc_sll_front(ccc_singly_linked_list const *sll)
Return a pointer to the element at the front of the list. O(1).
ccc_result ccc_sll_clear(ccc_singly_linked_list *sll, ccc_destructor_fn *fn)
Clears the list freeing memory if needed. O(N).
void * ccc_sll_next(ccc_singly_linked_list const *sll, ccc_sll_elem const *elem)
Return the user type following elem in the list. O(1).
void * ccc_sll_begin(ccc_singly_linked_list const *sll)
Return the user type at the front of the list. O(1).
struct ccc_sll_elem_ ccc_sll_elem
A singly linked list intrusive element to embedded in a user type.
Definition: singly_linked_list.h:55
void * ccc_sll_extract_range(ccc_singly_linked_list *sll, ccc_sll_elem *begin, ccc_sll_elem *end)
Extracts a range of elements from the list without freeing them. O(N).
ccc_result ccc_sll_splice(ccc_singly_linked_list *pos_sll, ccc_sll_elem *pos, ccc_singly_linked_list *splice_sll, ccc_sll_elem *splice)
Inserts splice element before pos. O(N).
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:65
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:234