C Container Collection (CCC)
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
doubly_linked_list.h
Go to the documentation of this file.
1
40#ifndef CCC_DOUBLY_LINKED_LIST_H
41#define CCC_DOUBLY_LINKED_LIST_H
42
44#include <stddef.h>
47#include "impl/impl_doubly_linked_list.h"
48#include "types.h"
49
60typedef struct ccc_dll ccc_doubly_linked_list;
61
71
92#define ccc_dll_init(list_name, struct_name, list_elem_field, cmp_fn, \
93 alloc_fn, aux_data) \
94 ccc_impl_dll_init(list_name, struct_name, list_elem_field, cmp_fn, \
95 alloc_fn, aux_data)
96
116#define ccc_dll_emplace_back(list_ptr, type_initializer...) \
117 ccc_impl_dll_emplace_back(list_ptr, type_initializer)
118
132#define ccc_dll_emplace_front(list_ptr, type_initializer...) \
133 ccc_impl_dll_emplace_front(list_ptr, type_initializer)
134
141 ccc_dll_elem *elem);
142
149 ccc_dll_elem *elem);
150
158 ccc_dll_elem *pos_elem, ccc_dll_elem *elem);
159
165
171
181
189
206 ccc_dll_elem *elem_end);
207
223 ccc_dll_elem *elem_end);
224
232 ccc_doubly_linked_list *to_cut_dll,
233 ccc_dll_elem *to_cut);
234
244 ccc_dll_elem *pos,
245 ccc_doubly_linked_list *to_cut_dll,
246 ccc_dll_elem *begin, ccc_dll_elem *end);
247
259
272
282
306
316[[nodiscard]] void *ccc_dll_begin(ccc_doubly_linked_list const *l);
317
321[[nodiscard]] void *ccc_dll_rbegin(ccc_doubly_linked_list const *l);
322
329[[nodiscard]] void *ccc_dll_next(ccc_doubly_linked_list const *l,
330 ccc_dll_elem const *elem);
331
338[[nodiscard]] void *ccc_dll_rnext(ccc_doubly_linked_list const *l,
339 ccc_dll_elem const *elem);
340
344[[nodiscard]] void *ccc_dll_end(ccc_doubly_linked_list const *l);
345
349[[nodiscard]] void *ccc_dll_rend(ccc_doubly_linked_list const *l);
350
360[[nodiscard]] void *ccc_dll_front(ccc_doubly_linked_list const *l);
361
365[[nodiscard]] void *ccc_dll_back(ccc_doubly_linked_list const *l);
366
373
380
385[[nodiscard]] ccc_dll_elem *
387
392
397
402
408#ifdef DOUBLY_LINKED_LIST_USING_NAMESPACE_CCC
409typedef ccc_dll_elem dll_elem;
410typedef ccc_doubly_linked_list doubly_linked_list;
411# define dll_init(args...) ccc_dll_init(args)
412# define dll_emplace_back(args...) ccc_dll_emplace_back(args)
413# define dll_emplace_front(args...) ccc_dll_emplace_front(args)
414# define dll_push_front(args...) ccc_dll_push_front(args)
415# define dll_push_back(args...) ccc_dll_push_back(args)
416# define dll_front(args...) ccc_dll_front(args)
417# define dll_back(args...) ccc_dll_back(args)
418# define dll_pop_front(args...) ccc_dll_pop_front(args)
419# define dll_pop_back(args...) ccc_dll_pop_back(args)
420# define dll_extract(args...) ccc_dll_extract(args)
421# define dll_extract_range(args...) ccc_dll_extract_range(args)
422# define dll_erase(args...) ccc_dll_erase(args)
423# define dll_erase_range(args...) ccc_dll_erase_range(args)
424# define dll_splice(args...) ccc_dll_splice(args)
425# define dll_splice_range(args...) ccc_dll_splice_range(args)
426# define dll_sort(args...) ccc_dll_sort(args)
427# define dll_insert_sorted(args...) ccc_dll_insert_sorted(args)
428# define dll_is_sorted(args...) ccc_dll_is_sorted(args)
429# define dll_begin(args...) ccc_dll_begin(args)
430# define dll_next(args...) ccc_dll_next(args)
431# define dll_rbegin(args...) ccc_dll_rbegin(args)
432# define dll_rnext(args...) ccc_dll_rnext(args)
433# define dll_end(args...) ccc_dll_end(args)
434# define dll_end_elem(args...) ccc_dll_end_elem(args)
435# define dll_rend(args...) ccc_dll_rend(args)
436# define dll_begin_elem(args...) ccc_dll_begin_elem(args)
437# define dll_end_elem(args...) ccc_dll_end_elem(args)
438# define dll_end_sentinel(args...) ccc_dll_end_sentinel(args)
439# define dll_size(args...) ccc_dll_size(args)
440# define dll_is_empty(args...) ccc_dll_is_empty(args)
441# define dll_clear(args...) ccc_dll_clear(args)
442# define dll_validate(args...) ccc_dll_validate(args)
443#endif /* DOUBLY_LINKED_LIST_USING_NAMESPACE_CCC */
444
445#endif /* CCC_LIST_H */
ccc_result ccc_dll_splice(ccc_doubly_linked_list *pos_dll, ccc_dll_elem *pos, ccc_doubly_linked_list *to_cut_dll, ccc_dll_elem *to_cut)
Repositions to_cut before pos. Only list pointers are modified. O(1).
ccc_dll_elem * ccc_dll_begin_elem(ccc_doubly_linked_list const *l)
Return a handle to the list element at the front of the list which may be the sentinel....
void * ccc_dll_rnext(ccc_doubly_linked_list const *l, ccc_dll_elem const *elem)
Return the user type following the element known to be in the list moving from back to front....
void * ccc_dll_erase(ccc_doubly_linked_list *l, ccc_dll_elem *elem)
Returns the element following an erased element from the list. O(1).
struct ccc_dll ccc_doubly_linked_list
A container offering bidirectional, insert, removal, and iteration.
Definition: doubly_linked_list.h:60
ccc_tribool ccc_dll_is_empty(ccc_doubly_linked_list const *l)
Return if the size of the list is equal to 0. O(1).
void * ccc_dll_extract_range(ccc_doubly_linked_list *l, ccc_dll_elem *elem_begin, ccc_dll_elem *elem_end)
Returns the element following an extracted range of elements from the list without deallocating regar...
void * ccc_dll_push_back(ccc_doubly_linked_list *l, ccc_dll_elem *elem)
Push user type wrapping elem to the back of the list. O(1).
ccc_result ccc_dll_pop_back(ccc_doubly_linked_list *l)
Pop the user type at the back of the list. O(1).
void * ccc_dll_extract(ccc_doubly_linked_list *l, ccc_dll_elem *elem)
Returns the element following an extracted element from the list without deallocating regardless of a...
ccc_dll_elem * ccc_dll_end_elem(ccc_doubly_linked_list const *l)
Return a handle to the list element at the back of the list which may be the sentinel....
void * ccc_dll_front(ccc_doubly_linked_list const *l)
Returns the user type at the front of the list. O(1).
ccc_result ccc_dll_splice_range(ccc_doubly_linked_list *pos_dll, ccc_dll_elem *pos, ccc_doubly_linked_list *to_cut_dll, ccc_dll_elem *begin, ccc_dll_elem *end)
Repositions begin to end before pos. Only list pointers are modified O(N).
ccc_result ccc_dll_sort(ccc_doubly_linked_list *dll)
Sorts the doubly linked list in non-decreasing order as defined by the provided comparison function....
ccc_ucount ccc_dll_size(ccc_doubly_linked_list const *l)
Return the size of the list. O(1).
ccc_dll_elem * ccc_dll_end_sentinel(ccc_doubly_linked_list const *l)
Return a handle to the sentinel at the back of the list. O(1).
void * ccc_dll_begin(ccc_doubly_linked_list const *l)
Return the user type at the start of the list or NULL if empty. O(1).
ccc_tribool ccc_dll_validate(ccc_doubly_linked_list const *l)
Validates internal state of the list.
ccc_result ccc_dll_pop_front(ccc_doubly_linked_list *l)
Pop the user type at the front of the list. O(1).
ccc_tribool ccc_dll_is_sorted(ccc_doubly_linked_list const *dll)
Returns true if the list is sorted in non-decreasing order according to the user provided comparison ...
void * ccc_dll_insert_sorted(ccc_doubly_linked_list *dll, ccc_dll_elem *e)
Inserts e in sorted position according to the non-decreasing order of the list determined by the user...
void * ccc_dll_next(ccc_doubly_linked_list const *l, ccc_dll_elem const *elem)
Return the user type following the element known to be in the list. O(1).
void * ccc_dll_rbegin(ccc_doubly_linked_list const *l)
Return the user type at the end of the list or NULL if empty. O(1).
ccc_result ccc_dll_clear(ccc_doubly_linked_list *l, ccc_any_type_destructor_fn *fn)
Clear the contents of the list freeing elements, if given allocation permission. O(N).
void * ccc_dll_back(ccc_doubly_linked_list const *l)
Returns the user type at the back of the list. O(1).
void * ccc_dll_push_front(ccc_doubly_linked_list *l, ccc_dll_elem *elem)
Push user type wrapping elem to the front of the list. O(1).
void * ccc_dll_rend(ccc_doubly_linked_list const *l)
Return the start sentinel with no accessible fields. O(1).
struct ccc_dll_elem ccc_dll_elem
A doubly linked list intrusive element to embedded in a user type.
Definition: doubly_linked_list.h:70
void * ccc_dll_erase_range(ccc_doubly_linked_list *l, ccc_dll_elem *elem_begin, ccc_dll_elem *elem_end)
Returns the element following an extracted range of elements from the list. O(N).
void * ccc_dll_end(ccc_doubly_linked_list const *l)
Return the end sentinel with no accessible fields. O(1).
void * ccc_dll_insert(ccc_doubly_linked_list *l, ccc_dll_elem *pos_elem, ccc_dll_elem *elem)
Insert user type wrapping elem before pos_elem. O(1).
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