C Container Collection (CCC)
Loading...
Searching...
No Matches
impl_singly_linked_list.h
1
16#ifndef CCC_IMPL_SINGLY_LINKED_LIST_H
17#define CCC_IMPL_SINGLY_LINKED_LIST_H
18
20#include <assert.h>
21#include <stddef.h>
24#include "../types.h"
25
26/* NOLINTBEGIN(readability-identifier-naming) */
27
32struct ccc_sll_elem
33{
35 struct ccc_sll_elem *n;
36};
37
47struct ccc_sll
48{
50 struct ccc_sll_elem nil;
52 size_t count;
54 size_t sizeof_type;
56 size_t sll_elem_offset;
60 ccc_any_alloc_fn *alloc;
62 void *aux;
63};
64
65/*========================= Private Interface ============================*/
66
68void ccc_impl_sll_push_front(struct ccc_sll *, struct ccc_sll_elem *);
69
70/*====================== Macro Implementations ========================*/
71
73#define ccc_impl_sll_init(impl_sll_name, impl_struct_name, \
74 impl_sll_elem_field, impl_cmp_fn, impl_alloc_fn, \
75 impl_aux_data) \
76 { \
77 .nil.n = &(impl_sll_name).nil, \
78 .sizeof_type = sizeof(impl_struct_name), \
79 .sll_elem_offset = offsetof(impl_struct_name, impl_sll_elem_field), \
80 .count = 0, \
81 .alloc = (impl_alloc_fn), \
82 .cmp = (impl_cmp_fn), \
83 .aux = (impl_aux_data), \
84 }
85
87#define ccc_impl_sll_emplace_front(list_ptr, struct_initializer...) \
88 (__extension__({ \
89 typeof(struct_initializer) *impl_sll_res = NULL; \
90 struct ccc_sll *impl_sll = (list_ptr); \
91 if (impl_sll) \
92 { \
93 if (!impl_sll->alloc) \
94 { \
95 impl_sll_res = NULL; \
96 } \
97 else \
98 { \
99 impl_sll_res = impl_sll->alloc(NULL, impl_sll->sizeof_type); \
100 if (impl_sll_res) \
101 { \
102 *impl_sll_res = struct_initializer; \
103 ccc_impl_sll_push_front( \
104 impl_sll, ccc_sll_elem_in(impl_sll, impl_sll_res)); \
105 } \
106 } \
107 } \
108 impl_sll_res; \
109 }))
110
111/* NOLINTEND(readability-identifier-naming) */
112
113#endif /* CCC_IMPL_SINGLY_LINKED_LIST_H */
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_threeway_cmp ccc_any_type_cmp_fn(ccc_any_type_cmp)
A callback function for comparing two elements in a container.
Definition: types.h:320
void * ccc_any_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:312