C Container Collection (CCC)
Loading...
Searching...
No Matches
private_flat_priority_queue.h
1
16#ifndef CCC_PRIVATE_FLAT_PRIORITY_QUEUE_H
17#define CCC_PRIVATE_FLAT_PRIORITY_QUEUE_H
18
20#include <stddef.h>
23#include "../buffer.h"
24#include "../types.h"
25
26/* NOLINTBEGIN(readability-identifier-naming) */
27
42};
43
44/*======================== Private Interface =========================*/
45
47size_t CCC_private_flat_priority_queue_bubble_up(
48 struct CCC_Flat_priority_queue *, void *, size_t
49);
51void CCC_private_flat_priority_queue_heap_order(
52 struct CCC_Flat_priority_queue *, void *
53);
55void *CCC_private_flat_priority_queue_update_fixup(
56 struct CCC_Flat_priority_queue *, void *, void *
57);
58
59/*====================== Macro Implementations ========================*/
60
62#define CCC_private_flat_priority_queue_default( \
63 private_type_name, private_order, private_comparator... \
64) \
65 (struct CCC_Flat_priority_queue) { \
66 .buffer = CCC_buffer_default(private_type_name), \
67 .order = (private_order), .comparator = private_comparator, \
68 }
69
71#define CCC_private_flat_priority_queue_for( \
72 private_type_name, \
73 private_order, \
74 private_comparator, \
75 private_capacity, \
76 private_data_pointer \
77) \
78 (struct CCC_Flat_priority_queue) { \
79 .buffer = CCC_buffer_for( \
80 private_type_name, private_capacity, 0, private_data_pointer \
81 ), \
82 .order = (private_order), .comparator = (private_comparator), \
83 }
84
86#define CCC_private_flat_priority_queue_heapify( \
87 private_type_name, \
88 private_order, \
89 private_comparator, \
90 private_capacity, \
91 private_size, \
92 private_data_pointer... \
93) \
94 (struct { struct CCC_Flat_priority_queue private; }){(__extension__({ \
95 typeof(*( \
96 private_data_pointer \
97 )) *private_flat_priority_queue_heapify_data = private_data_pointer; \
98 struct CCC_Flat_priority_queue private_flat_priority_queue_heapify_res \
99 = CCC_private_flat_priority_queue_for( \
100 private_type_name, \
101 private_order, \
102 private_comparator, \
103 private_capacity, \
104 private_flat_priority_queue_heapify_data \
105 ); \
106 private_flat_priority_queue_heapify_res.buffer.count = (private_size); \
107 CCC_private_flat_priority_queue_heap_order( \
108 &private_flat_priority_queue_heapify_res, &(private_type_name){} \
109 ); \
110 private_flat_priority_queue_heapify_res; \
111 }))}.private
112
114#define CCC_private_flat_priority_queue_from( \
115 private_order, \
116 private_comparator, \
117 private_allocator, \
118 private_optional_capacity, \
119 private_compound_literal_array... \
120) \
121 (struct { struct CCC_Flat_priority_queue private; }){(__extension__({ \
122 struct CCC_Flat_priority_queue private_flat_priority_queue = { \
123 .buffer = CCC_buffer_from( \
124 private_allocator, \
125 private_optional_capacity, \
126 private_compound_literal_array \
127 ), \
128 .order = (private_order), \
129 .comparator = (private_comparator), \
130 }; \
131 if (private_flat_priority_queue.buffer.count) { \
132 CCC_private_flat_priority_queue_heap_order( \
133 &private_flat_priority_queue, \
134 &(typeof(*private_compound_literal_array)){} \
135 ); \
136 } \
137 private_flat_priority_queue; \
138 }))}.private
139
141#define CCC_private_flat_priority_queue_with_capacity( \
142 private_type_name, \
143 private_order, \
144 private_comparator, \
145 private_allocator, \
146 private_capacity \
147) \
148 (struct { struct CCC_Flat_priority_queue private; }){(__extension__({ \
149 struct CCC_Flat_priority_queue private_flat_priority_queue = { \
150 .buffer = CCC_buffer_with_capacity( \
151 private_type_name, private_allocator, private_capacity \
152 ), \
153 .order = (private_order), \
154 .comparator = (private_comparator), \
155 }; \
156 private_flat_priority_queue; \
157 }))}.private
158
163#if defined(__clang__) || defined(__llvm__)
164# define CCC_private_flat_priority_queue_with_storage( \
165 private_order, private_comparator, private_compound_literal \
166 ) \
167 (struct { \
168 static_assert( \
169 (private_order) == CCC_ORDER_LESSER \
170 || (private_order) == CCC_ORDER_GREATER, \
171 "flat priority queue must be a min or max priority queue" \
172 ); \
173 struct CCC_Flat_priority_queue private; \
174 }){{ \
175 .buffer = CCC_buffer_with_storage(0, private_compound_literal), \
176 .order = (private_order), \
177 .comparator = (private_comparator), \
178 }} \
179 .private
180#else
182# define CCC_private_flat_priority_queue_with_storage( \
183 private_order, private_comparator, private_compound_literal \
184 ) \
185 (struct CCC_Flat_priority_queue) { \
186 .buffer = CCC_buffer_with_storage(0, private_compound_literal), \
187 .order = (private_order), .comparator = (private_comparator), \
188 }
189#endif
190
194#define CCC_private_flat_priority_queue_emplace( \
195 flat_priority_queue, private_allocator_pointer, type_compound_literal... \
196) \
197 (__extension__({ \
198 struct CCC_Flat_priority_queue *private_flat_priority_queue \
199 = (flat_priority_queue); \
200 typeof(type_compound_literal) *private_flat_priority_queue_res \
201 = CCC_buffer_allocate_back( \
202 &private_flat_priority_queue->buffer, \
203 private_allocator_pointer \
204 ); \
205 if (private_flat_priority_queue_res) { \
206 *private_flat_priority_queue_res = type_compound_literal; \
207 if (private_flat_priority_queue->buffer.count > 1) { \
208 private_flat_priority_queue_res = CCC_buffer_at( \
209 &private_flat_priority_queue->buffer, \
210 CCC_private_flat_priority_queue_bubble_up( \
211 private_flat_priority_queue, \
212 &(typeof(type_compound_literal)){}, \
213 private_flat_priority_queue->buffer.count - 1 \
214 ) \
215 ); \
216 } else { \
217 private_flat_priority_queue_res \
218 = CCC_buffer_at(&private_flat_priority_queue->buffer, 0); \
219 } \
220 } \
221 private_flat_priority_queue_res; \
222 }))
223
226#define CCC_private_flat_priority_queue_update_with( \
227 flat_priority_queue_pointer, \
228 closure_parameter, \
229 update_closure_over_closure_parameter... \
230) \
231 (__extension__({ \
232 struct CCC_Flat_priority_queue *const private_flat_priority_queue \
233 = (flat_priority_queue_pointer); \
234 typeof(*closure_parameter) * \
235 private_flat_priority_queue_updated_element = (closure_parameter); \
236 if (private_flat_priority_queue \
237 && !CCC_buffer_is_empty(&private_flat_priority_queue->buffer)) { \
238 {update_closure_over_closure_parameter}; \
239 private_flat_priority_queue_updated_element \
240 = CCC_private_flat_priority_queue_update_fixup( \
241 private_flat_priority_queue, \
242 private_flat_priority_queue_updated_element, \
243 &(typeof(*closure_parameter)){} \
244 ); \
245 } \
246 private_flat_priority_queue_updated_element; \
247 }))
248
250#define CCC_private_flat_priority_queue_increase_with( \
251 flat_priority_queue_pointer, \
252 closure_parameter, \
253 increase_closure_over_closure_parameter... \
254) \
255 CCC_private_flat_priority_queue_update_with( \
256 flat_priority_queue_pointer, \
257 closure_parameter, \
258 increase_closure_over_closure_parameter \
259 )
260
262#define CCC_private_flat_priority_queue_decrease_with( \
263 flat_priority_queue_pointer, \
264 closure_parameter, \
265 decrease_closure_over_closure_parameter... \
266) \
267 CCC_private_flat_priority_queue_update_with( \
268 flat_priority_queue_pointer, \
269 closure_parameter, \
270 decrease_closure_over_closure_parameter \
271 )
272
273/* NOLINTEND(readability-identifier-naming) */
274
275#endif /* CCC_PRIVATE_FLAT_PRIORITY_QUEUE_H */
Definition: private_buffer.h:32
The type passed by reference to any container function that may need to compare elements....
Definition: types.h:416
Definition: private_flat_priority_queue.h:34
CCC_Comparator comparator
Definition: private_flat_priority_queue.h:41
CCC_Buffer buffer
Definition: private_flat_priority_queue.h:36
CCC_Order order
Definition: private_flat_priority_queue.h:39
CCC_Order
A three-way comparison for comparison functions.
Definition: types.h:214