16#ifndef CCC_IMPL_REALTIME_ORDERED_MAP_H
17#define CCC_IMPL_REALTIME_ORDERED_MAP_H
25#include "impl_types.h"
64 size_t node_elem_offset;
81 struct ccc_romap *rom;
96 struct ccc_rtree_entry impl;
102void *ccc_impl_rom_key_in_slot(
struct ccc_romap
const *rom,
void const *slot);
104struct ccc_romap_elem *ccc_impl_romap_elem_in_slot(
struct ccc_romap
const *rom,
107struct ccc_rtree_entry ccc_impl_rom_entry(struct ccc_romap const *rom,
110void *ccc_impl_rom_insert(
struct ccc_romap *rom,
struct ccc_romap_elem *parent,
112 struct ccc_romap_elem *out_handle);
117#define ccc_impl_rom_init(impl_map_name, impl_struct_name, \
118 impl_node_elem_field, impl_key_elem_field, \
119 impl_key_cmp_fn, impl_alloc_fn, impl_aux_data) \
121 .root = &(impl_map_name).end, \
122 .end = {.parity = 1, \
123 .parent = &(impl_map_name).end, \
124 .branch = {&(impl_map_name).end, &(impl_map_name).end}}, \
126 .key_offset = offsetof(impl_struct_name, impl_key_elem_field), \
127 .node_elem_offset = offsetof(impl_struct_name, impl_node_elem_field), \
128 .sizeof_type = sizeof(impl_struct_name), \
129 .alloc = (impl_alloc_fn), \
130 .cmp = (impl_key_cmp_fn), \
131 .aux = (impl_aux_data), \
137#define ccc_impl_rom_new(realtime_ordered_map_entry) \
139 void *impl_rom_ins_alloc_ret = NULL; \
140 if ((realtime_ordered_map_entry)->rom->alloc) \
142 impl_rom_ins_alloc_ret \
143 = (realtime_ordered_map_entry) \
146 (realtime_ordered_map_entry)->rom->sizeof_type, \
147 (realtime_ordered_map_entry)->rom->aux); \
149 impl_rom_ins_alloc_ret; \
153#define ccc_impl_rom_insert_key_val(realtime_ordered_map_entry, new_mem, \
158 *new_mem = lazy_key_value; \
159 new_mem = ccc_impl_rom_insert( \
160 (realtime_ordered_map_entry)->rom, \
161 ccc_impl_romap_elem_in_slot( \
162 (realtime_ordered_map_entry)->rom, \
163 (realtime_ordered_map_entry)->entry.e), \
164 (realtime_ordered_map_entry)->last_cmp, \
165 ccc_impl_romap_elem_in_slot((realtime_ordered_map_entry)->rom, \
171#define ccc_impl_rom_insert_and_copy_key( \
172 rom_insert_entry, rom_insert_entry_ret, key, lazy_value...) \
174 typeof(lazy_value) *impl_rom_new_ins_base \
175 = ccc_impl_rom_new((&rom_insert_entry)); \
176 rom_insert_entry_ret = (struct ccc_ent){ \
177 .e = impl_rom_new_ins_base, \
178 .stats = CCC_ENTRY_INSERT_ERROR, \
180 if (impl_rom_new_ins_base) \
182 *impl_rom_new_ins_base = lazy_value; \
183 *((typeof(key) *)ccc_impl_rom_key_in_slot(rom_insert_entry.rom, \
184 impl_rom_new_ins_base)) \
186 (void)ccc_impl_rom_insert( \
187 rom_insert_entry.rom, \
188 ccc_impl_romap_elem_in_slot(rom_insert_entry.rom, \
189 rom_insert_entry.entry.e), \
190 rom_insert_entry.last_cmp, \
191 ccc_impl_romap_elem_in_slot(rom_insert_entry.rom, \
192 impl_rom_new_ins_base)); \
199#define ccc_impl_rom_and_modify_w(realtime_ordered_map_entry_ptr, type_name, \
202 __auto_type impl_rom_ent_ptr = (realtime_ordered_map_entry_ptr); \
203 struct ccc_rtree_entry impl_rom_mod_ent \
204 = {.entry = {.stats = CCC_ENTRY_ARG_ERROR}}; \
205 if (impl_rom_ent_ptr) \
207 impl_rom_mod_ent = impl_rom_ent_ptr->impl; \
208 if (impl_rom_mod_ent.entry.stats & CCC_ENTRY_OCCUPIED) \
210 type_name *const T = impl_rom_mod_ent.entry.e; \
221#define ccc_impl_rom_or_insert_w(realtime_ordered_map_entry_ptr, \
224 __auto_type impl_or_ins_entry_ptr = (realtime_ordered_map_entry_ptr); \
225 typeof(lazy_key_value) *impl_rom_or_ins_ret = NULL; \
226 if (impl_or_ins_entry_ptr) \
228 if (impl_or_ins_entry_ptr->impl.entry.stats == CCC_ENTRY_OCCUPIED) \
230 impl_rom_or_ins_ret = impl_or_ins_entry_ptr->impl.entry.e; \
234 impl_rom_or_ins_ret \
235 = ccc_impl_rom_new(&impl_or_ins_entry_ptr->impl); \
236 ccc_impl_rom_insert_key_val(&impl_or_ins_entry_ptr->impl, \
237 impl_rom_or_ins_ret, \
241 impl_rom_or_ins_ret; \
245#define ccc_impl_rom_insert_entry_w(realtime_ordered_map_entry_ptr, \
248 __auto_type impl_ins_entry_ptr = (realtime_ordered_map_entry_ptr); \
249 typeof(lazy_key_value) *impl_rom_ins_ent_ret = NULL; \
250 if (impl_ins_entry_ptr) \
252 if (!(impl_ins_entry_ptr->impl.entry.stats & CCC_ENTRY_OCCUPIED)) \
254 impl_rom_ins_ent_ret \
255 = ccc_impl_rom_new(&impl_ins_entry_ptr->impl); \
256 ccc_impl_rom_insert_key_val(&impl_ins_entry_ptr->impl, \
257 impl_rom_ins_ent_ret, \
260 else if (impl_ins_entry_ptr->impl.entry.stats \
261 == CCC_ENTRY_OCCUPIED) \
263 struct ccc_romap_elem impl_ins_ent_saved \
264 = *ccc_impl_romap_elem_in_slot( \
265 impl_ins_entry_ptr->impl.rom, \
266 impl_ins_entry_ptr->impl.entry.e); \
267 *((typeof(impl_rom_ins_ent_ret)) \
268 impl_ins_entry_ptr->impl.entry.e) \
270 *ccc_impl_romap_elem_in_slot(impl_ins_entry_ptr->impl.rom, \
271 impl_ins_entry_ptr->impl.entry.e) \
272 = impl_ins_ent_saved; \
273 impl_rom_ins_ent_ret = impl_ins_entry_ptr->impl.entry.e; \
276 impl_rom_ins_ent_ret; \
280#define ccc_impl_rom_try_insert_w(realtime_ordered_map_ptr, key, \
283 struct ccc_romap *const impl_try_ins_map_ptr \
284 = (realtime_ordered_map_ptr); \
285 struct ccc_ent impl_rom_try_ins_ent_ret \
286 = {.stats = CCC_ENTRY_ARG_ERROR}; \
287 if (impl_try_ins_map_ptr) \
289 __auto_type impl_rom_key = (key); \
290 struct ccc_rtree_entry impl_rom_try_ins_ent = ccc_impl_rom_entry( \
291 impl_try_ins_map_ptr, (void *)&impl_rom_key); \
292 if (!(impl_rom_try_ins_ent.entry.stats & CCC_ENTRY_OCCUPIED)) \
294 ccc_impl_rom_insert_and_copy_key(impl_rom_try_ins_ent, \
295 impl_rom_try_ins_ent_ret, \
296 impl_rom_key, lazy_value); \
298 else if (impl_rom_try_ins_ent.entry.stats == CCC_ENTRY_OCCUPIED) \
300 impl_rom_try_ins_ent_ret = impl_rom_try_ins_ent.entry; \
303 impl_rom_try_ins_ent_ret; \
307#define ccc_impl_rom_insert_or_assign_w(realtime_ordered_map_ptr, key, \
310 struct ccc_romap *const impl_ins_or_assign_map_ptr \
311 = (realtime_ordered_map_ptr); \
312 struct ccc_ent impl_rom_ins_or_assign_ent_ret \
313 = {.stats = CCC_ENTRY_ARG_ERROR}; \
314 if (impl_ins_or_assign_map_ptr) \
316 __auto_type impl_rom_key = (key); \
317 struct ccc_rtree_entry impl_rom_ins_or_assign_ent \
318 = ccc_impl_rom_entry(impl_ins_or_assign_map_ptr, \
319 (void *)&impl_rom_key); \
320 if (!(impl_rom_ins_or_assign_ent.entry.stats \
321 & CCC_ENTRY_OCCUPIED)) \
323 ccc_impl_rom_insert_and_copy_key( \
324 impl_rom_ins_or_assign_ent, \
325 impl_rom_ins_or_assign_ent_ret, impl_rom_key, lazy_value); \
327 else if (impl_rom_ins_or_assign_ent.entry.stats \
328 == CCC_ENTRY_OCCUPIED) \
330 struct ccc_romap_elem impl_ins_ent_saved \
331 = *ccc_impl_romap_elem_in_slot( \
332 impl_rom_ins_or_assign_ent.rom, \
333 impl_rom_ins_or_assign_ent.entry.e); \
334 *((typeof(lazy_value) *)impl_rom_ins_or_assign_ent.entry.e) \
336 *ccc_impl_romap_elem_in_slot( \
337 impl_rom_ins_or_assign_ent.rom, \
338 impl_rom_ins_or_assign_ent.entry.e) \
339 = impl_ins_ent_saved; \
340 impl_rom_ins_or_assign_ent_ret \
341 = impl_rom_ins_or_assign_ent.entry; \
342 *((typeof(impl_rom_key) *)ccc_impl_rom_key_in_slot( \
343 impl_rom_ins_or_assign_ent.rom, \
344 impl_rom_ins_or_assign_ent_ret.e)) \
348 impl_rom_ins_or_assign_ent_ret; \
union ccc_romap_entry ccc_romap_entry
A container specific entry used to implement the Entry Interface.
Definition: realtime_ordered_map.h:69
struct ccc_romap_elem ccc_romap_elem
The intrusive element of the user defined struct being stored in the map.
Definition: realtime_ordered_map.h:63
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
ccc_threeway_cmp ccc_any_key_cmp_fn(ccc_any_key_cmp)
A callback function for three-way comparing two stored keys.
Definition: types.h:362
ccc_threeway_cmp
A three-way comparison for comparison functions.
Definition: types.h:153