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
25#ifndef CCC_DOUBLY_LINKED_LIST_H
26#define CCC_DOUBLY_LINKED_LIST_H
27
29#include <stddef.h>
32#include "impl/impl_doubly_linked_list.h"
33#include "types.h"
34
45typedef struct ccc_dll_ ccc_doubly_linked_list;
46
55typedef struct ccc_dll_elem_ ccc_dll_elem;
56
77#define ccc_dll_init(list_name, struct_name, list_elem_field, alloc_fn, \
78 cmp_fn, aux_data) \
79 ccc_impl_dll_init(list_name, struct_name, list_elem_field, alloc_fn, \
80 cmp_fn, aux_data)
81
101#define ccc_dll_emplace_back(list_ptr, type_initializer...) \
102 ccc_impl_dll_emplace_back(list_ptr, type_initializer)
103
117#define ccc_dll_emplace_front(list_ptr, type_initializer...) \
118 ccc_impl_dll_emplace_front(list_ptr, type_initializer)
119
126 ccc_dll_elem *elem);
127
134 ccc_dll_elem *elem);
135
143 ccc_dll_elem *pos_elem, ccc_dll_elem *elem);
144
150
156
166
174
191 ccc_dll_elem *elem_end);
192
208 ccc_dll_elem *elem_end);
209
217 ccc_doubly_linked_list *to_cut_sll,
218 ccc_dll_elem *to_cut);
219
229 ccc_dll_elem *pos,
230 ccc_doubly_linked_list *to_cut_sll,
231 ccc_dll_elem *begin, ccc_dll_elem *end);
232
255
265[[nodiscard]] void *ccc_dll_begin(ccc_doubly_linked_list const *l);
266
270[[nodiscard]] void *ccc_dll_rbegin(ccc_doubly_linked_list const *l);
271
278[[nodiscard]] void *ccc_dll_next(ccc_doubly_linked_list const *l,
279 ccc_dll_elem const *elem);
280
287[[nodiscard]] void *ccc_dll_rnext(ccc_doubly_linked_list const *l,
288 ccc_dll_elem const *elem);
289
293[[nodiscard]] void *ccc_dll_end(ccc_doubly_linked_list const *l);
294
298[[nodiscard]] void *ccc_dll_rend(ccc_doubly_linked_list const *l);
299
309[[nodiscard]] void *ccc_dll_front(ccc_doubly_linked_list const *l);
310
314[[nodiscard]] void *ccc_dll_back(ccc_doubly_linked_list const *l);
315
322
329
334[[nodiscard]] ccc_dll_elem *
336
340[[nodiscard]] size_t ccc_dll_size(ccc_doubly_linked_list const *l);
341
345[[nodiscard]] bool ccc_dll_is_empty(ccc_doubly_linked_list const *l);
346
350[[nodiscard]] bool ccc_dll_validate(ccc_doubly_linked_list const *l);
351
357#ifdef DOUBLY_LINKED_LIST_USING_NAMESPACE_CCC
358typedef ccc_dll_elem dll_elem;
359typedef ccc_doubly_linked_list doubly_linked_list;
360# define dll_init(args...) ccc_dll_init(args)
361# define dll_emplace_back(args...) ccc_dll_emplace_back(args)
362# define dll_emplace_front(args...) ccc_dll_emplace_front(args)
363# define dll_push_front(args...) ccc_dll_push_front(args)
364# define dll_push_back(args...) ccc_dll_push_back(args)
365# define dll_front(args...) ccc_dll_front(args)
366# define dll_back(args...) ccc_dll_back(args)
367# define dll_pop_front(args...) ccc_dll_pop_front(args)
368# define dll_pop_back(args...) ccc_dll_pop_back(args)
369# define dll_extract(args...) ccc_dll_extract(args)
370# define dll_extract_range(args...) ccc_dll_extract_range(args)
371# define dll_erase(args...) ccc_dll_erase(args)
372# define dll_erase_range(args...) ccc_dll_erase_range(args)
373# define dll_splice(args...) ccc_dll_splice(args)
374# define dll_splice_range(args...) ccc_dll_splice_range(args)
375# define dll_begin(args...) ccc_dll_begin(args)
376# define dll_next(args...) ccc_dll_next(args)
377# define dll_rbegin(args...) ccc_dll_rbegin(args)
378# define dll_rnext(args...) ccc_dll_rnext(args)
379# define dll_end(args...) ccc_dll_end(args)
380# define dll_end_elem(args...) ccc_dll_end_elem(args)
381# define dll_rend(args...) ccc_dll_rend(args)
382# define dll_begin_elem(args...) ccc_dll_begin_elem(args)
383# define dll_end_elem(args...) ccc_dll_end_elem(args)
384# define dll_end_sentinel(args...) ccc_dll_end_sentinel(args)
385# define dll_size(args...) ccc_dll_size(args)
386# define dll_is_empty(args...) ccc_dll_is_empty(args)
387# define dll_clear(args...) ccc_dll_clear(args)
388# define dll_validate(args...) ccc_dll_validate(args)
389#endif /* DOUBLY_LINKED_LIST_USING_NAMESPACE_CCC */
390
391#endif /* CCC_LIST_H */
bool ccc_dll_validate(ccc_doubly_linked_list const *l)
Validates internal state of the list.
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).
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...
ccc_result ccc_dll_splice(ccc_doubly_linked_list *pos_sll, ccc_dll_elem *pos, ccc_doubly_linked_list *to_cut_sll, ccc_dll_elem *to_cut)
Repositions to_cut before pos. Only list pointers are modified. O(1).
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).
ccc_result ccc_dll_splice_range(ccc_doubly_linked_list *pos_sll, ccc_dll_elem *pos, ccc_doubly_linked_list *to_cut_sll, ccc_dll_elem *begin, ccc_dll_elem *end)
Repositions begin to end before pos. Only list pointers are modified O(N).
bool 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(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_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_result ccc_dll_pop_front(ccc_doubly_linked_list *l)
Pop the user type at the front of the list. O(1).
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).
struct ccc_dll_ ccc_doubly_linked_list
A container offering bidirectional, insert, removal, and iteration.
Definition: doubly_linked_list.h:45
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).
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).
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).
struct ccc_dll_elem_ ccc_dll_elem
A doubly linked list intrusive element to embedded in a user type.
Definition: doubly_linked_list.h:55
ccc_result ccc_dll_clear(ccc_doubly_linked_list *l, ccc_destructor_fn *fn)
Clear the contents of the list freeing elements, if given allocation permission. 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).
size_t ccc_dll_size(ccc_doubly_linked_list const *l)
Return the size of the list. O(1).
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