C Container Collection (CCC)
Loading...
Searching...
No Matches
ordered_map.h
Go to the documentation of this file.
1
21#ifndef CCC_ORDERED_MAP_H
22#define CCC_ORDERED_MAP_H
23
25#include <stdbool.h>
26#include <stddef.h>
29#include "impl/impl_ordered_map.h"
30#include "types.h"
31
42typedef union ccc_ordered_map_ ccc_ordered_map;
43
51typedef union ccc_omap_elem_ ccc_omap_elem;
52
57typedef union ccc_omap_entry_ ccc_omap_entry;
58
75#define ccc_om_init(om_name, struct_name, om_elem_field, key_elem_field, \
76 alloc_fn, key_cmp, aux) \
77 ccc_impl_om_init(om_name, struct_name, om_elem_field, key_elem_field, \
78 alloc_fn, key_cmp, aux)
79
90[[nodiscard]] bool ccc_om_contains(ccc_ordered_map *om, void const *key);
91
96[[nodiscard]] void *ccc_om_get_key_val(ccc_ordered_map *om, void const *key);
97
118 ccc_omap_elem *key_val_handle,
119 ccc_omap_elem *tmp);
120
134#define ccc_om_insert_r(ordered_map_ptr, key_val_handle_ptr, tmp_ptr) \
135 &(ccc_entry) \
136 { \
137 ccc_om_insert((ordered_map_ptr), (key_val_handle_ptr), (tmp_ptr)) \
138 .impl_ \
139 }
140
149 ccc_omap_elem *key_val_handle);
150
159#define ccc_om_try_insert_r(ordered_map_ptr, key_val_handle_ptr) \
160 &(ccc_entry) \
161 { \
162 ccc_om_try_insert((ordered_map_ptr), (key_val_handle_ptr)).impl_ \
163 }
164
177#define ccc_om_try_insert_w(ordered_map_ptr, key, lazy_value...) \
178 &(ccc_entry) \
179 { \
180 ccc_impl_om_try_insert_w(ordered_map_ptr, key, lazy_value) \
181 }
182
192 ccc_omap_elem *key_val_handle);
193
206#define ccc_om_insert_or_assign_w(ordered_map_ptr, key, lazy_value...) \
207 &(ccc_entry) \
208 { \
209 ccc_impl_om_insert_or_assign_w(ordered_map_ptr, key, lazy_value) \
210 }
211
228 ccc_omap_elem *out_handle);
229
245#define ccc_om_remove_r(ordered_map_ptr, out_handle_ptr) \
246 &(ccc_entry) \
247 { \
248 ccc_om_remove((ordered_map_ptr), (out_handle_ptr)).impl_ \
249 }
250
265[[nodiscard]] ccc_omap_entry ccc_om_entry(ccc_ordered_map *om, void const *key);
266
282#define ccc_om_entry_r(ordered_map_ptr, key_ptr) \
283 &(ccc_omap_entry) \
284 { \
285 ccc_om_entry((ordered_map_ptr), (key_ptr)).impl_ \
286 }
287
297 ccc_update_fn *fn);
298
307[[nodiscard]] ccc_omap_entry *
309
336#define ccc_om_and_modify_w(ordered_map_entry_ptr, type_name, \
337 closure_over_T...) \
338 &(ccc_omap_entry) \
339 { \
340 ccc_impl_om_and_modify_w(ordered_map_entry_ptr, type_name, \
341 closure_over_T) \
342 }
343
355[[nodiscard]] void *ccc_om_or_insert(ccc_omap_entry const *e,
356 ccc_omap_elem *elem);
357
369#define ccc_om_or_insert_w(ordered_map_entry_ptr, lazy_key_value...) \
370 ccc_impl_om_or_insert_w(ordered_map_entry_ptr, lazy_key_value)
371
379[[nodiscard]] void *ccc_om_insert_entry(ccc_omap_entry const *e,
380 ccc_omap_elem *elem);
381
387#define ccc_om_insert_entry_w(ordered_map_entry_ptr, lazy_key_value...) \
388 ccc_impl_om_insert_entry_w(ordered_map_entry_ptr, lazy_key_value)
389
401
412#define ccc_om_remove_entry_r(ordered_map_entry_ptr) \
413 &(ccc_entry) \
414 { \
415 ccc_om_remove_entry((ordered_map_entry_ptr)).impl_ \
416 }
417
421[[nodiscard]] void *ccc_om_unwrap(ccc_omap_entry const *e);
422
426[[nodiscard]] bool ccc_om_occupied(ccc_omap_entry const *e);
427
432[[nodiscard]] bool ccc_om_insert_error(ccc_omap_entry const *e);
433
444
472 void const *begin_key,
473 void const *end_key);
474
482#define ccc_om_equal_range_r(ordered_map_ptr, begin_and_end_key_ptrs...) \
483 &(ccc_range) \
484 { \
485 ccc_om_equal_range(ordered_map_ptr, begin_and_end_key_ptrs).impl_ \
486 }
487
509 void const *rbegin_key,
510 void const *rend_key);
511
519#define ccc_om_equal_rrange_r(ordered_map_ptr, rbegin_and_rend_key_ptrs...) \
520 &(ccc_rrange) \
521 { \
522 ccc_om_equal_rrange(ordered_map_ptr, rbegin_and_rend_key_ptrs).impl_ \
523 }
524
529[[nodiscard]] void *ccc_om_begin(ccc_ordered_map const *om);
530
535[[nodiscard]] void *ccc_om_rbegin(ccc_ordered_map const *om);
536
542[[nodiscard]] void *ccc_om_next(ccc_ordered_map const *om,
543 ccc_omap_elem const *iter_handle);
544
551[[nodiscard]] void *ccc_om_rnext(ccc_ordered_map const *om,
552 ccc_omap_elem const *iter_handle);
553
557[[nodiscard]] void *ccc_om_end(ccc_ordered_map const *om);
558
562[[nodiscard]] void *ccc_om_rend(ccc_ordered_map const *om);
563
585
595[[nodiscard]] bool ccc_om_is_empty(ccc_ordered_map const *om);
596
600[[nodiscard]] size_t ccc_om_size(ccc_ordered_map const *om);
601
605[[nodiscard]] bool ccc_om_validate(ccc_ordered_map const *om);
606
611#ifdef ORDERED_MAP_USING_NAMESPACE_CCC
612typedef ccc_omap_elem omap_elem;
613typedef ccc_ordered_map ordered_map;
614typedef ccc_omap_entry omap_entry;
615# define om_init(args...) ccc_om_init(args)
616# define om_and_modify_w(args...) ccc_om_and_modify_w(args)
617# define om_or_insert_w(args...) ccc_om_or_insert_w(args)
618# define om_insert_entry_w(args...) ccc_om_insert_entry_w(args)
619# define om_try_insert_w(args...) ccc_om_try_insert_w(args)
620# define om_insert_or_assign_w(args...) ccc_om_insert_or_assign_w(args)
621# define om_insert_r(args...) ccc_om_insert_r(args)
622# define om_remove_r(args...) ccc_om_remove_r(args)
623# define om_remove_entry_r(args...) ccc_om_remove_entry_r(args)
624# define om_entry_r(args...) ccc_om_entry_r(args)
625# define om_and_modify_r(args...) ccc_om_and_modify_r(args)
626# define om_and_modify_aux_r(args...) ccc_om_and_modify_aux_r(args)
627# define om_contains(args...) ccc_om_contains(args)
628# define om_get_key_val(args...) ccc_om_get_key_val(args)
629# define om_get_mut(args...) ccc_om_get_mut(args)
630# define om_insert(args...) ccc_om_insert(args)
631# define om_remove(args...) ccc_om_remove(args)
632# define om_entry(args...) ccc_om_entry(args)
633# define om_remove_entry(args...) ccc_om_remove_entry(args)
634# define om_or_insert(args...) ccc_om_or_insert(args)
635# define om_insert_entry(args...) ccc_om_insert_entry(args)
636# define om_unwrap(args...) ccc_om_unwrap(args)
637# define om_unwrap_mut(args...) ccc_om_unwrap_mut(args)
638# define om_begin(args...) ccc_om_begin(args)
639# define om_next(args...) ccc_om_next(args)
640# define om_rbegin(args...) ccc_om_rbegin(args)
641# define om_rnext(args...) ccc_om_rnext(args)
642# define om_end(args...) ccc_om_end(args)
643# define om_rend(args...) ccc_om_rend(args)
644# define om_size(args...) ccc_om_size(args)
645# define om_is_empty(args...) ccc_om_is_empty(args)
646# define om_clear(args...) ccc_om_clear(args)
647# define om_validate(args...) ccc_om_validate(args)
648#endif
649
650#endif /* CCC_ORDERED_MAP_H */
ccc_entry ccc_om_try_insert(ccc_ordered_map *om, ccc_omap_elem *key_val_handle)
Attempts to insert the key value wrapping key_val_handle.
union ccc_omap_entry_ ccc_omap_entry
A container specific entry used to implement the Entry Interface.
Definition: ordered_map.h:57
ccc_entry ccc_om_insert(ccc_ordered_map *om, ccc_omap_elem *key_val_handle, ccc_omap_elem *tmp)
Invariantly inserts the key value wrapping key_val_handle.
ccc_entry ccc_om_remove(ccc_ordered_map *om, ccc_omap_elem *out_handle)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
ccc_range ccc_om_equal_range(ccc_ordered_map *om, void const *begin_key, void const *end_key)
Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).
void * ccc_om_rend(ccc_ordered_map const *om)
Return the rend of a reverse inorder traversal of the map. O(1).
void * ccc_om_rnext(ccc_ordered_map const *om, ccc_omap_elem const *iter_handle)
Return the rnext element in a reverse inorder traversal of the map. O(1).
ccc_entry_status ccc_om_entry_status(ccc_omap_entry const *e)
Obtain the entry status from a container entry.
size_t ccc_om_size(ccc_ordered_map const *om)
Returns the size of the map.
bool ccc_om_contains(ccc_ordered_map *om, void const *key)
Searches the map for the presence of key.
bool ccc_om_occupied(ccc_omap_entry const *e)
Returns the Vacant or Occupied status of the entry.
void * ccc_om_rbegin(ccc_ordered_map const *om)
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
bool ccc_om_insert_error(ccc_omap_entry const *e)
Provides the status of the entry should an insertion follow.
ccc_entry ccc_om_insert_or_assign(ccc_ordered_map *om, ccc_omap_elem *key_val_handle)
Invariantly inserts or overwrites a user struct into the map.
void * ccc_om_unwrap(ccc_omap_entry const *e)
Unwraps the provided entry to obtain a view into the map element.
void * ccc_om_begin(ccc_ordered_map const *om)
Return the start of an inorder traversal of the map. Amortized O(lg N).
union ccc_omap_elem_ ccc_omap_elem
The intrusive element for the user defined struct being stored in the map.
Definition: ordered_map.h:51
ccc_omap_entry * ccc_om_and_modify(ccc_omap_entry *e, ccc_update_fn *fn)
Modifies the provided entry if it is Occupied.
void * ccc_om_or_insert(ccc_omap_entry const *e, ccc_omap_elem *elem)
Inserts the struct with handle elem if the entry is Vacant.
union ccc_ordered_map_ ccc_ordered_map
A self-optimizing data structure offering amortized O(lg N) search, insert, and erase and pointer sta...
Definition: ordered_map.h:42
void * ccc_om_next(ccc_ordered_map const *om, ccc_omap_elem const *iter_handle)
Return the next element in an inorder traversal of the map. O(1).
ccc_result ccc_om_clear(ccc_ordered_map *om, ccc_destructor_fn *destructor)
Pops every element from the map calling destructor if destructor is non-NULL. O(N).
void * ccc_om_get_key_val(ccc_ordered_map *om, void const *key)
Returns a reference into the map at entry key.
bool ccc_om_is_empty(ccc_ordered_map const *om)
Returns the size status of the map.
ccc_rrange ccc_om_equal_rrange(ccc_ordered_map *om, void const *rbegin_key, void const *rend_key)
Return an iterable rrange of values from [begin_key, end_key). Amortized O(lg N).
void * ccc_om_insert_entry(ccc_omap_entry const *e, ccc_omap_elem *elem)
Inserts the provided entry invariantly.
ccc_omap_entry * ccc_om_and_modify_aux(ccc_omap_entry *e, ccc_update_fn *fn, void *aux)
Modifies the provided entry if it is Occupied.
ccc_entry ccc_om_remove_entry(ccc_omap_entry *e)
Remove the entry from the map if Occupied.
void * ccc_om_end(ccc_ordered_map const *om)
Return the end of an inorder traversal of the map. O(1).
bool ccc_om_validate(ccc_ordered_map const *om)
Validation of invariants for the map.
ccc_omap_entry ccc_om_entry(ccc_ordered_map *om, void const *key)
Obtains an entry for the provided key in the map for future use.
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:65
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:216
union ccc_range_ ccc_range
The result of a range query on iterable containers.
Definition: types.h:30
union ccc_entry_ ccc_entry
An Occupied or Vacant position in a searchable container.
Definition: types.h:47
enum ccc_entry_status_ ccc_entry_status
The status monitoring and entry state once it is obtained.
Definition: types.h:57
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:234
union ccc_rrange_ ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:38