C Container Collection (CCC)
Loading...
Searching...
No Matches
singly_linked_list.h
Go to the documentation of this file.
1
41#ifndef CCC_SINGLY_LINKED_LIST_H
42#define CCC_SINGLY_LINKED_LIST_H
43
45#include <stddef.h>
48#include "impl/impl_singly_linked_list.h"
49#include "types.h"
50
60typedef struct ccc_sll ccc_singly_linked_list;
61
71
89#define ccc_sll_init(list_name, struct_name, list_elem_field, cmp_fn, \
90 alloc_fn, aux_data) \
91 ccc_impl_sll_init(list_name, struct_name, list_elem_field, cmp_fn, \
92 alloc_fn, aux_data)
93
110 ccc_sll_elem *elem);
111
123#define ccc_sll_emplace_front(list_ptr, struct_initializer...) \
124 ccc_impl_sll_emplace_front(list_ptr, struct_initializer)
125
131
143 ccc_singly_linked_list *splice_sll,
144 ccc_sll_elem *splice);
145
160 ccc_sll_elem *pos,
161 ccc_singly_linked_list *splice_sll,
162 ccc_sll_elem *begin, ccc_sll_elem *end);
163
175
188 ccc_sll_elem *end);
189
198
210 ccc_sll_elem *end);
211
223
236
246
268
279[[nodiscard]] void *ccc_sll_begin(ccc_singly_linked_list const *sll);
280
286[[nodiscard]] void *ccc_sll_end(ccc_singly_linked_list const *sll);
287
293[[nodiscard]] void *ccc_sll_next(ccc_singly_linked_list const *sll,
294 ccc_sll_elem const *elem);
295
305[[nodiscard]] void *ccc_sll_front(ccc_singly_linked_list const *sll);
306
311[[nodiscard]] ccc_sll_elem *
313
318[[nodiscard]] ccc_sll_elem *
320
325
330
335
340#ifdef SINGLY_LINKED_LIST_USING_NAMESPACE_CCC
341typedef ccc_sll_elem sll_elem;
342typedef ccc_singly_linked_list singly_linked_list;
343# define sll_init(args...) ccc_sll_init(args)
344# define sll_emplace_front(args...) ccc_sll_emplace_front(args)
345# define sll_push_front(args...) ccc_sll_push_front(args)
346# define sll_front(args...) ccc_sll_front(args)
347# define sll_pop_front(args...) ccc_sll_pop_front(args)
348# define sll_splice(args...) ccc_sll_splice(args)
349# define sll_splice_range(args...) ccc_sll_splice_range(args)
350# define sll_extract(args...) ccc_sll_extract(args)
351# define sll_extract_range(args...) ccc_sll_extract_range(args)
352# define sll_erase(args...) ccc_sll_erase(args)
353# define sll_erase_range(args...) ccc_sll_erase_range(args)
354# define sll_sort(args...) ccc_sll_sort(args)
355# define sll_insert_sorted(args...) ccc_sll_insert_sorted(args)
356# define sll_is_sorted(args...) ccc_sll_is_sorted(args)
357# define sll_begin(args...) ccc_sll_begin(args)
358# define sll_end(args...) ccc_sll_end(args)
359# define sll_next(args...) ccc_sll_next(args)
360# define sll_begin_elem(args...) ccc_sll_begin_elem(args)
361# define sll_begin_sentinel(args...) ccc_sll_begin_sentinel(args)
362# define sll_size(args...) ccc_sll_size(args)
363# define sll_is_empty(args...) ccc_sll_is_empty(args)
364# define sll_validate(args...) ccc_sll_validate(args)
365# define sll_clear(args...) ccc_sll_clear(args)
366#endif /* SINGLY_LINKED_LIST_USING_NAMESPACE_CCC */
367
368#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 [begin, end] of spliced elements after 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).
ccc_result ccc_sll_sort(ccc_singly_linked_list *sll)
Sorts the singly linked list in non-decreasing order as defined by the provided comparison function....
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).
ccc_tribool ccc_sll_validate(ccc_singly_linked_list const *sll)
Returns true if the invariants of the list hold.
ccc_tribool ccc_sll_is_empty(ccc_singly_linked_list const *sll)
Return true if the list is empty. O(1).
void * ccc_sll_insert_sorted(ccc_singly_linked_list *sll, ccc_sll_elem *e)
Inserts e in sorted position according to the non-decreasing order of the list determined by the user...
ccc_ucount ccc_sll_size(ccc_singly_linked_list const *sll)
Return the size of the list. O(1).
ccc_tribool ccc_sll_is_sorted(ccc_singly_linked_list const *sll)
Returns true if the list is sorted in non-decreasing order according to the user provided comparison ...
void * ccc_sll_extract(ccc_singly_linked_list *sll, ccc_sll_elem *elem)
Extracts an element from the list without freeing it. O(N).
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).
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_any_type_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 ccc_singly_linked_list
A low overhead front tracking container with efficient push and pop.
Definition: singly_linked_list.h:60
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).
struct ccc_sll_elem ccc_sll_elem
A singly linked list intrusive element to embedded in a user type.
Definition: singly_linked_list.h:70
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 after pos. O(N).
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:187
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:132
ccc_tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:117
void ccc_any_type_destructor_fn(ccc_any_type)
A callback function for destroying an element in the container.
Definition: types.h:347