C Container Collection (CCC)
Loading...
Searching...
No Matches
ordered_map.h
Go to the documentation of this file.
1
36#ifndef CCC_ORDERED_MAP_H
37#define CCC_ORDERED_MAP_H
38
40#include <stddef.h>
43#include "impl/impl_ordered_map.h"
44#include "types.h"
45
56typedef struct ccc_omap ccc_ordered_map;
57
66
72
89#define ccc_om_init(om_name, struct_name, om_elem_field, key_elem_field, \
90 key_cmp, alloc_fn, aux) \
91 ccc_impl_om_init(om_name, struct_name, om_elem_field, key_elem_field, \
92 key_cmp, alloc_fn, aux)
93
105[[nodiscard]] ccc_tribool ccc_om_contains(ccc_ordered_map *om, void const *key);
106
111[[nodiscard]] void *ccc_om_get_key_val(ccc_ordered_map *om, void const *key);
112
133 ccc_omap_elem *key_val_handle,
134 ccc_omap_elem *tmp);
135
149#define ccc_om_swap_entry_r(ordered_map_ptr, key_val_handle_ptr, tmp_ptr) \
150 &(ccc_entry) \
151 { \
152 ccc_om_swap_entry((ordered_map_ptr), (key_val_handle_ptr), (tmp_ptr)) \
153 .impl \
154 }
155
164 ccc_omap_elem *key_val_handle);
165
174#define ccc_om_try_insert_r(ordered_map_ptr, key_val_handle_ptr) \
175 &(ccc_entry) \
176 { \
177 ccc_om_try_insert((ordered_map_ptr), (key_val_handle_ptr)).impl \
178 }
179
192#define ccc_om_try_insert_w(ordered_map_ptr, key, lazy_value...) \
193 &(ccc_entry) \
194 { \
195 ccc_impl_om_try_insert_w(ordered_map_ptr, key, lazy_value) \
196 }
197
207 ccc_omap_elem *key_val_handle);
208
221#define ccc_om_insert_or_assign_w(ordered_map_ptr, key, lazy_value...) \
222 &(ccc_entry) \
223 { \
224 ccc_impl_om_insert_or_assign_w(ordered_map_ptr, key, lazy_value) \
225 }
226
243 ccc_omap_elem *out_handle);
244
260#define ccc_om_remove_r(ordered_map_ptr, out_handle_ptr) \
261 &(ccc_entry) \
262 { \
263 ccc_om_remove((ordered_map_ptr), (out_handle_ptr)).impl \
264 }
265
280[[nodiscard]] ccc_omap_entry ccc_om_entry(ccc_ordered_map *om, void const *key);
281
297#define ccc_om_entry_r(ordered_map_ptr, key_ptr) \
298 &(ccc_omap_entry) \
299 { \
300 ccc_om_entry((ordered_map_ptr), (key_ptr)).impl \
301 }
302
314
323[[nodiscard]] ccc_omap_entry *
325
352#define ccc_om_and_modify_w(ordered_map_entry_ptr, type_name, \
353 closure_over_T...) \
354 &(ccc_omap_entry) \
355 { \
356 ccc_impl_om_and_modify_w(ordered_map_entry_ptr, type_name, \
357 closure_over_T) \
358 }
359
371[[nodiscard]] void *ccc_om_or_insert(ccc_omap_entry const *e,
372 ccc_omap_elem *elem);
373
385#define ccc_om_or_insert_w(ordered_map_entry_ptr, lazy_key_value...) \
386 ccc_impl_om_or_insert_w(ordered_map_entry_ptr, lazy_key_value)
387
395[[nodiscard]] void *ccc_om_insert_entry(ccc_omap_entry const *e,
396 ccc_omap_elem *elem);
397
403#define ccc_om_insert_entry_w(ordered_map_entry_ptr, lazy_key_value...) \
404 ccc_impl_om_insert_entry_w(ordered_map_entry_ptr, lazy_key_value)
405
417
428#define ccc_om_remove_entry_r(ordered_map_entry_ptr) \
429 &(ccc_entry) \
430 { \
431 ccc_om_remove_entry((ordered_map_entry_ptr)).impl \
432 }
433
437[[nodiscard]] void *ccc_om_unwrap(ccc_omap_entry const *e);
438
443
450
460[[nodiscard]] ccc_entry_status ccc_om_entry_status(ccc_omap_entry const *e);
461
489 void const *begin_key,
490 void const *end_key);
491
499#define ccc_om_equal_range_r(ordered_map_ptr, begin_and_end_key_ptrs...) \
500 &(ccc_range) \
501 { \
502 ccc_om_equal_range(ordered_map_ptr, begin_and_end_key_ptrs).impl \
503 }
504
526 void const *rbegin_key,
527 void const *rend_key);
528
536#define ccc_om_equal_rrange_r(ordered_map_ptr, rbegin_and_rend_key_ptrs...) \
537 &(ccc_rrange) \
538 { \
539 ccc_om_equal_rrange(ordered_map_ptr, rbegin_and_rend_key_ptrs).impl \
540 }
541
546[[nodiscard]] void *ccc_om_begin(ccc_ordered_map const *om);
547
552[[nodiscard]] void *ccc_om_rbegin(ccc_ordered_map const *om);
553
559[[nodiscard]] void *ccc_om_next(ccc_ordered_map const *om,
560 ccc_omap_elem const *iter_handle);
561
568[[nodiscard]] void *ccc_om_rnext(ccc_ordered_map const *om,
569 ccc_omap_elem const *iter_handle);
570
574[[nodiscard]] void *ccc_om_end(ccc_ordered_map const *om);
575
579[[nodiscard]] void *ccc_om_rend(ccc_ordered_map const *om);
580
602 ccc_any_type_destructor_fn *destructor);
603
614
618[[nodiscard]] ccc_ucount ccc_om_size(ccc_ordered_map const *om);
619
625
630#ifdef ORDERED_MAP_USING_NAMESPACE_CCC
631typedef ccc_omap_elem omap_elem;
632typedef ccc_ordered_map ordered_map;
633typedef ccc_omap_entry omap_entry;
634# define om_init(args...) ccc_om_init(args)
635# define om_and_modify_w(args...) ccc_om_and_modify_w(args)
636# define om_or_insert_w(args...) ccc_om_or_insert_w(args)
637# define om_insert_entry_w(args...) ccc_om_insert_entry_w(args)
638# define om_try_insert_w(args...) ccc_om_try_insert_w(args)
639# define om_insert_or_assign_w(args...) ccc_om_insert_or_assign_w(args)
640# define om_swap_entry_r(args...) ccc_om_swap_entry_r(args)
641# define om_remove_r(args...) ccc_om_remove_r(args)
642# define om_remove_entry_r(args...) ccc_om_remove_entry_r(args)
643# define om_entry_r(args...) ccc_om_entry_r(args)
644# define om_and_modify_r(args...) ccc_om_and_modify_r(args)
645# define om_and_modify_aux_r(args...) ccc_om_and_modify_aux_r(args)
646# define om_contains(args...) ccc_om_contains(args)
647# define om_get_key_val(args...) ccc_om_get_key_val(args)
648# define om_get_mut(args...) ccc_om_get_mut(args)
649# define om_swap_entry(args...) ccc_om_swap_entry(args)
650# define om_remove(args...) ccc_om_remove(args)
651# define om_entry(args...) ccc_om_entry(args)
652# define om_remove_entry(args...) ccc_om_remove_entry(args)
653# define om_or_insert(args...) ccc_om_or_insert(args)
654# define om_insert_entry(args...) ccc_om_insert_entry(args)
655# define om_unwrap(args...) ccc_om_unwrap(args)
656# define om_unwrap_mut(args...) ccc_om_unwrap_mut(args)
657# define om_begin(args...) ccc_om_begin(args)
658# define om_next(args...) ccc_om_next(args)
659# define om_rbegin(args...) ccc_om_rbegin(args)
660# define om_rnext(args...) ccc_om_rnext(args)
661# define om_end(args...) ccc_om_end(args)
662# define om_rend(args...) ccc_om_rend(args)
663# define om_size(args...) ccc_om_size(args)
664# define om_is_empty(args...) ccc_om_is_empty(args)
665# define om_clear(args...) ccc_om_clear(args)
666# define om_validate(args...) ccc_om_validate(args)
667#endif
668
669#endif /* CCC_ORDERED_MAP_H */
ccc_tribool ccc_om_validate(ccc_ordered_map const *om)
Validation of invariants for the map.
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.
struct ccc_omap ccc_ordered_map
A self-optimizing data structure offering amortized O(lg N) search, insert, and erase and pointer sta...
Definition: ordered_map.h:56
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).
struct ccc_omap_elem ccc_omap_elem
The intrusive element for the user defined struct being stored in the map.
Definition: ordered_map.h:65
ccc_tribool ccc_om_insert_error(ccc_omap_entry const *e)
Provides the status of the entry should an insertion follow.
void * ccc_om_rend(ccc_ordered_map const *om)
Return the rend of a reverse inorder traversal of the map. O(1).
ccc_result ccc_om_clear(ccc_ordered_map *om, ccc_any_type_destructor_fn *destructor)
Pops every element from the map calling destructor if destructor is non-NULL. O(N).
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_ucount ccc_om_size(ccc_ordered_map const *om)
Returns the size of the map.
ccc_entry_status ccc_om_entry_status(ccc_omap_entry const *e)
Obtain the entry status from a container entry.
ccc_tribool ccc_om_occupied(ccc_omap_entry const *e)
Returns the Vacant or Occupied status of the entry.
ccc_tribool ccc_om_contains(ccc_ordered_map *om, void const *key)
Searches the map for the presence of key.
ccc_omap_entry * ccc_om_and_modify_aux(ccc_omap_entry *e, ccc_any_type_update_fn *fn, void *aux)
Modifies the provided entry if it is Occupied.
void * ccc_om_rbegin(ccc_ordered_map const *om)
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
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).
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.
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_omap_entry * ccc_om_and_modify(ccc_omap_entry *e, ccc_any_type_update_fn *fn)
Modifies the provided entry if it is Occupied.
void * ccc_om_get_key_val(ccc_ordered_map *om, void const *key)
Returns a reference into the map at entry key.
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).
ccc_entry ccc_om_swap_entry(ccc_ordered_map *om, ccc_omap_elem *key_val_handle, ccc_omap_elem *tmp)
Invariantly inserts the key value wrapping key_val_handle.
ccc_tribool ccc_om_is_empty(ccc_ordered_map const *om)
Returns the size status of the map.
void * ccc_om_insert_entry(ccc_omap_entry const *e, ccc_omap_elem *elem)
Inserts the provided entry invariantly.
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).
union ccc_omap_entry ccc_omap_entry
A container specific entry used to implement the Entry Interface.
Definition: ordered_map.h:71
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.
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:187
#define ccc_entry(container_ptr, key_ptr...)
Obtain a container specific entry for the Entry Interface.
Definition: traits.h:141
The C Container Collection Fundamental Types.
ccc_result
A result of actions on containers.
Definition: types.h:132
union ccc_range ccc_range
The result of a range query on iterable containers.
Definition: types.h:44
union ccc_rrange ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:52
ccc_tribool
A three state boolean to allow for an error state. Error is -1, False is 0, and True is 1.
Definition: types.h:117
void ccc_any_type_destructor_fn(ccc_any_type)
A callback function for destroying an element in the container.
Definition: types.h:347
void ccc_any_type_update_fn(ccc_any_type)
A callback function for modifying an element in the container.
Definition: types.h:329