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_from( \
113 private_type_intruder_field, private_compare, private_allocate, \
114 private_destroy, private_context_data, private_compound_literal_array...) \
115 (__extension__({ \
116 typeof(*private_compound_literal_array) \
117 *private_singly_linked_list_type_array \
118 = private_compound_literal_array; \
119 struct CCC_Singly_linked_list private_singly_linked_list \
120 = CCC_private_singly_linked_list_initialize( \
121 typeof(*private_singly_linked_list_type_array), \
122 private_type_intruder_field, private_compare, \
123 private_allocate, private_context_data); \
124 if (private_singly_linked_list.allocate) \
125 { \
126 size_t private_count \
127 = sizeof(private_compound_literal_array) \
128 / sizeof(*private_singly_linked_list_type_array); \
129 while (private_count--) \
130 { \
131 typeof(*private_singly_linked_list_type_array) *const \
132 private_new_node \
133 = private_singly_linked_list.allocate( \
134 (CCC_Allocator_context){ \
135 .input = NULL, \
136 .bytes = private_singly_linked_list.sizeof_type, \
137 .context = private_singly_linked_list.context, \
138 }); \
139 if (!private_new_node) \
140 { \
141 CCC_singly_linked_list_clear(&private_singly_linked_list, \
142 private_destroy); \
143 break; \
144 } \
145 *private_new_node \
146 = private_singly_linked_list_type_array[private_count]; \
147 CCC_private_singly_linked_list_push_front( \
148 &private_singly_linked_list, \
149 CCC_private_singly_linked_list_node_in( \
150 &private_singly_linked_list, private_new_node)); \
151 } \
152 } \
153 private_singly_linked_list; \
154 }))
155
157#define CCC_private_singly_linked_list_emplace_front(list_pointer, \
158 struct_initializer...) \
159 (__extension__({ \
160 typeof(struct_initializer) *private_singly_linked_list_res = NULL; \
161 struct CCC_Singly_linked_list *private_singly_linked_list \
162 = (list_pointer); \
163 if (private_singly_linked_list) \
164 { \
165 if (!private_singly_linked_list->allocate) \
166 { \
167 private_singly_linked_list_res = NULL; \
168 } \
169 else \
170 { \
171 private_singly_linked_list_res \
172 = private_singly_linked_list->allocate( \
173 (CCC_Allocator_context){ \
174 .input = NULL, \
175 .bytes = private_singly_linked_list->sizeof_type, \
176 .context = private_singly_linked_list->context, \
177 }); \
178 if (private_singly_linked_list_res) \
179 { \
180 *private_singly_linked_list_res = struct_initializer; \
181 CCC_private_singly_linked_list_push_front( \
182 private_singly_linked_list, \
183 CCC_private_singly_linked_list_node_in( \
184 private_singly_linked_list, \
185 private_singly_linked_list_res)); \
186 } \
187 } \
188 } \
189 private_singly_linked_list_res; \
190 }))
191
192/* NOLINTEND(readability-identifier-naming) */
193
194#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