C Container Collection (CCC)
Loading...
Searching...
No Matches
private_singly_linked_list.h
1
16#ifndef CCC_PRIVATE_SINGLY_LINKED_LIST_H
17#define CCC_PRIVATE_SINGLY_LINKED_LIST_H
18
20#include <assert.h>
21#include <stddef.h>
24#include "../types.h"
25
26/* NOLINTBEGIN(readability-identifier-naming) */
27
33{
36};
37
66{
70 size_t count;
80 void *context;
81};
82
83/*========================= Private Interface ============================*/
84
86void
87CCC_private_singly_linked_list_push_front(struct CCC_Singly_linked_list *,
91CCC_private_singly_linked_list_node_in(struct CCC_Singly_linked_list const *,
92 void const *);
93
94/*====================== Macro Implementations ========================*/
95
97#define CCC_private_singly_linked_list_initialize( \
98 private_struct_name, private_singly_linked_list_node_field, \
99 private_compare, private_allocate, private_context_data) \
100 { \
101 .head = NULL, \
102 .sizeof_type = sizeof(private_struct_name), \
103 .type_intruder_offset = offsetof( \
104 private_struct_name, private_singly_linked_list_node_field), \
105 .count = 0, \
106 .allocate = (private_allocate), \
107 .compare = (private_compare), \
108 .context = (private_context_data), \
109 }
110
112#define CCC_private_singly_linked_list_with_allocator( \
113 private_struct_name, private_type_intruder_field, private_compare, \
114 private_allocate) \
115 { \
116 .head = NULL, \
117 .sizeof_type = sizeof(private_struct_name), \
118 .type_intruder_offset \
119 = offsetof(private_struct_name, private_type_intruder_field), \
120 .count = 0, \
121 .allocate = (private_allocate), \
122 .compare = (private_compare), \
123 .context = NULL, \
124 }
125
127#define CCC_private_singly_linked_list_with_context_allocator( \
128 private_struct_name, private_type_intruder_field, private_compare, \
129 private_allocate, private_context) \
130 { \
131 .head = NULL, \
132 .sizeof_type = sizeof(private_struct_name), \
133 .type_intruder_offset \
134 = offsetof(private_struct_name, private_type_intruder_field), \
135 .count = 0, \
136 .allocate = (private_allocate), \
137 .compare = (private_compare), \
138 .context = (private_context), \
139 }
140
142#define CCC_private_singly_linked_list_from( \
143 private_type_intruder_field, private_compare, private_allocate, \
144 private_destroy, private_context_data, private_compound_literal_array...) \
145 (__extension__({ \
146 typeof(*private_compound_literal_array) \
147 *private_singly_linked_list_type_array \
148 = private_compound_literal_array; \
149 struct CCC_Singly_linked_list private_singly_linked_list \
150 = CCC_private_singly_linked_list_initialize( \
151 typeof(*private_singly_linked_list_type_array), \
152 private_type_intruder_field, private_compare, \
153 private_allocate, private_context_data); \
154 if (private_singly_linked_list.allocate) \
155 { \
156 size_t private_count \
157 = sizeof(private_compound_literal_array) \
158 / sizeof(*private_singly_linked_list_type_array); \
159 while (private_count--) \
160 { \
161 typeof(*private_singly_linked_list_type_array) *const \
162 private_new_node \
163 = private_singly_linked_list.allocate( \
164 (CCC_Allocator_context){ \
165 .input = NULL, \
166 .bytes = private_singly_linked_list.sizeof_type, \
167 .context = private_singly_linked_list.context, \
168 }); \
169 if (!private_new_node) \
170 { \
171 CCC_singly_linked_list_clear(&private_singly_linked_list, \
172 private_destroy); \
173 break; \
174 } \
175 *private_new_node \
176 = private_singly_linked_list_type_array[private_count]; \
177 CCC_private_singly_linked_list_push_front( \
178 &private_singly_linked_list, \
179 CCC_private_singly_linked_list_node_in( \
180 &private_singly_linked_list, private_new_node)); \
181 } \
182 } \
183 private_singly_linked_list; \
184 }))
185
187#define CCC_private_singly_linked_list_emplace_front(list_pointer, \
188 struct_initializer...) \
189 (__extension__({ \
190 typeof(struct_initializer) *private_singly_linked_list_res = NULL; \
191 struct CCC_Singly_linked_list *private_singly_linked_list \
192 = (list_pointer); \
193 if (private_singly_linked_list) \
194 { \
195 if (!private_singly_linked_list->allocate) \
196 { \
197 private_singly_linked_list_res = NULL; \
198 } \
199 else \
200 { \
201 private_singly_linked_list_res \
202 = private_singly_linked_list->allocate( \
203 (CCC_Allocator_context){ \
204 .input = NULL, \
205 .bytes = private_singly_linked_list->sizeof_type, \
206 .context = private_singly_linked_list->context, \
207 }); \
208 if (private_singly_linked_list_res) \
209 { \
210 *private_singly_linked_list_res = struct_initializer; \
211 CCC_private_singly_linked_list_push_front( \
212 private_singly_linked_list, \
213 CCC_private_singly_linked_list_node_in( \
214 private_singly_linked_list, \
215 private_singly_linked_list_res)); \
216 } \
217 } \
218 } \
219 private_singly_linked_list_res; \
220 }))
221
222/* NOLINTEND(readability-identifier-naming) */
223
224#endif /* CCC_PRIVATE_SINGLY_LINKED_LIST_H */
Definition: private_singly_linked_list.h:33
struct CCC_Singly_linked_list_node * next
Definition: private_singly_linked_list.h:35
Definition: private_singly_linked_list.h:66
size_t type_intruder_offset
Definition: private_singly_linked_list.h:74
CCC_Allocator * allocate
Definition: private_singly_linked_list.h:78
void * context
Definition: private_singly_linked_list.h:80
struct CCC_Singly_linked_list_node * head
Definition: private_singly_linked_list.h:68
size_t count
Definition: private_singly_linked_list.h:70
CCC_Type_comparator * compare
Definition: private_singly_linked_list.h:76
size_t sizeof_type
Definition: private_singly_linked_list.h:72
CCC_Order CCC_Type_comparator(CCC_Type_comparator_context)
A callback function for comparing two elements in a container.
Definition: types.h:348
void * CCC_Allocator(CCC_Allocator_context)
An allocation function at the core of all containers.
Definition: types.h:340