C Container Collection (CCC)
Loading...
Searching...
No Matches
handle_realtime_ordered_map.h
Go to the documentation of this file.
1
52#ifndef CCC_HANDLE_REALTIME_ORDERED_MAP_H
53#define CCC_HANDLE_REALTIME_ORDERED_MAP_H
54
56#include <stddef.h>
59#include "impl/impl_handle_realtime_ordered_map.h"
60#include "types.h"
61
72typedef struct ccc_hromap ccc_handle_realtime_ordered_map;
73
83
154#define ccc_hrm_declare_fixed_map(fixed_map_type_name, key_val_type_name, \
155 capacity) \
156 ccc_impl_hrm_declare_fixed_map(fixed_map_type_name, key_val_type_name, \
157 capacity)
158
162#define ccc_hrm_fixed_capacity(fixed_map_type_name) \
163 ccc_impl_hrm_fixed_capacity(fixed_map_type_name)
164
176#define ccc_hrm_init(memory_ptr, any_type_name, key_elem_field, key_cmp_fn, \
177 alloc_fn, aux_data, capacity) \
178 ccc_impl_hrm_init(memory_ptr, any_type_name, key_elem_field, key_cmp_fn, \
179 alloc_fn, aux_data, capacity)
180
277 ccc_any_alloc_fn *fn);
278
297 ccc_any_alloc_fn *fn);
298
315[[nodiscard]] void *ccc_hrm_at(ccc_handle_realtime_ordered_map const *h,
316 ccc_handle_i i);
317
324#define ccc_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i...) \
325 ccc_impl_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i)
326
332[[nodiscard]] ccc_tribool
334
339[[nodiscard]] ccc_handle_i
341 void const *key);
342
359[[nodiscard]] ccc_handle
361 void *key_val_type_output);
362
373#define ccc_hrm_swap_handle_r(handle_realtime_ordered_map_ptr, \
374 key_val_type_output_ptr) \
375 &(ccc_handle) \
376 { \
377 ccc_hrm_swap_handle((handle_realtime_ordered_map_ptr), \
378 (key_val_type_output_ptr)) \
379 .impl \
380 }
381
389[[nodiscard]] ccc_handle
391 void const *key_val_type);
392
400#define ccc_hrm_try_insert_r(handle_realtime_ordered_map_ptr, \
401 key_val_type_ptr) \
402 &(ccc_handle) \
403 { \
404 ccc_hrm_try_insert((handle_realtime_ordered_map_ptr), \
405 (key_val_type_ptr)) \
406 .impl \
407 }
408
421#define ccc_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, \
422 lazy_value...) \
423 &(ccc_handle) \
424 { \
425 ccc_impl_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, \
426 lazy_value) \
427 }
428
437[[nodiscard]] ccc_handle
439 void const *key_val_type);
440
453#define ccc_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, \
454 lazy_value...) \
455 &(ccc_handle) \
456 { \
457 ccc_impl_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, \
458 lazy_value) \
459 }
460
471 void *key_val_type_output);
472
482#define ccc_hrm_remove_r(handle_realtime_ordered_map_ptr, \
483 key_val_type_output_ptr) \
484 &(ccc_handle) \
485 { \
486 ccc_hrm_remove((handle_realtime_ordered_map_ptr), \
487 (key_val_type_output_ptr)) \
488 .impl \
489 }
490
506[[nodiscard]] ccc_hromap_handle
508
524#define ccc_hrm_handle_r(handle_realtime_ordered_map_ptr, key_ptr) \
525 &(ccc_hromap_handle) \
526 { \
527 ccc_hrm_handle((handle_realtime_ordered_map_ptr), (key_ptr)).impl \
528 }
529
541
550[[nodiscard]] ccc_hromap_handle *
552 void *aux);
553
578#define ccc_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, \
579 type_name, closure_over_T...) \
580 &(ccc_hromap_handle) \
581 { \
582 ccc_impl_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, \
583 type_name, closure_over_T) \
584 }
585
598 void const *key_val_type);
599
612#define ccc_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, \
613 lazy_key_value...) \
614 ccc_impl_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, \
615 lazy_key_value)
616
625 void const *key_val_type);
626
633#define ccc_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, \
634 lazy_key_value...) \
635 ccc_impl_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, \
636 lazy_key_value)
637
646
655#define ccc_hrm_remove_handle_r(handle_realtime_ordered_map_handle_ptr) \
656 &(ccc_handle) \
657 { \
658 ccc_hrm_remove_handle((handle_realtime_ordered_map_handle_ptr)).impl \
659 }
660
665
670
677
687[[nodiscard]] ccc_handle_status
689
705
718
747 ccc_any_type_destructor_fn *destructor,
748 ccc_any_alloc_fn *alloc);
749
775[[nodiscard]] ccc_range
777 void const *begin_key, void const *end_key);
778
785#define ccc_hrm_equal_range_r(handle_realtime_ordered_map_ptr, \
786 begin_and_end_key_ptrs...) \
787 &(ccc_range) \
788 { \
789 ccc_hrm_equal_range((handle_realtime_ordered_map_ptr), \
790 (begin_and_end_key_ptrs)) \
791 .impl \
792 }
793
814[[nodiscard]] ccc_rrange
816 void const *rbegin_key, void const *rend_key);
817
825#define ccc_hrm_equal_rrange_r(handle_realtime_ordered_map_ptr, \
826 rbegin_and_rend_key_ptrs...) \
827 &(ccc_rrange) \
828 { \
829 ccc_hrm_equal_rrange((handle_realtime_ordered_map_ptr), \
830 (rbegin_and_rend_key_ptrs)) \
831 .impl \
832 }
833
837[[nodiscard]] void *ccc_hrm_begin(ccc_handle_realtime_ordered_map const *hrm);
838
842[[nodiscard]] void *ccc_hrm_rbegin(ccc_handle_realtime_ordered_map const *hrm);
843
849[[nodiscard]] void *ccc_hrm_next(ccc_handle_realtime_ordered_map const *hrm,
850 void const *key_val_type_iter);
851
858[[nodiscard]] void *ccc_hrm_rnext(ccc_handle_realtime_ordered_map const *hrm,
859 void const *key_val_type_iter);
860
864[[nodiscard]] void *ccc_hrm_end(ccc_handle_realtime_ordered_map const *hrm);
865
869[[nodiscard]] void *ccc_hrm_rend(ccc_handle_realtime_ordered_map const *hrm);
870
880[[nodiscard]] ccc_tribool
882
886[[nodiscard]] ccc_ucount
888
892[[nodiscard]] ccc_ucount
894
902[[nodiscard]] void *ccc_hrm_data(ccc_handle_realtime_ordered_map const *hrm);
903
908[[nodiscard]] ccc_tribool
910
915#ifdef HANDLE_REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC
916typedef ccc_handle_realtime_ordered_map handle_realtime_ordered_map;
917typedef ccc_hromap_handle hromap_handle;
918# define hrm_declare_fixed_map(args...) ccc_hrm_declare_fixed_map(args)
919# define hrm_init(args...) ccc_hrm_init(args)
920# define hrm_fixed_capacity(args...) ccc_hrm_fixed_capacity(args)
921# define hrm_copy(args...) ccc_hrm_copy(args)
922# define hrm_reserve(args...) ccc_hrm_reserve(args)
923# define hrm_at(args...) ccc_hrm_at(args)
924# define hrm_as(args...) ccc_hrm_as(args)
925# define hrm_and_modify_w(args...) ccc_hrm_and_modify_w(args)
926# define hrm_or_insert_w(args...) ccc_hrm_or_insert_w(args)
927# define hrm_insert_handle_w(args...) ccc_hrm_insert_handle_w(args)
928# define hrm_try_insert_w(args...) ccc_hrm_try_insert_w(args)
929# define hrm_insert_or_assign_w(args...) ccc_hrm_insert_or_assign_w(args)
930# define hrm_contains(args...) ccc_hrm_contains(args)
931# define hrm_get_key_val(args...) ccc_hrm_get_key_val(args)
932# define hrm_swap_handle(args...) ccc_hrm_swap_handle(args)
933# define hrm_swap_handle_r(args...) ccc_hrm_swap_handle_r(args)
934# define hrm_begin(args...) ccc_hrm_begin(args)
935# define hrm_rbegin(args...) ccc_hrm_rbegin(args)
936# define hrm_next(args...) ccc_hrm_next(args)
937# define hrm_rnext(args...) ccc_hrm_rnext(args)
938# define hrm_end(args...) ccc_hrm_end(args)
939# define hrm_rend(args...) ccc_hrm_rend(args)
940# define hrm_data(args...) ccc_hrm_data(args)
941# define hrm_is_empty(args...) ccc_hrm_is_empty(args)
942# define hrm_count(args...) ccc_hrm_count(args)
943# define hrm_clear(args...) ccc_hrm_clear(args)
944# define hrm_clear_and_free(args...) ccc_hrm_clear_and_free(args)
945# define hrm_clear_and_free_reserve(args...) \
946 ccc_hrm_clear_and_free_reserve(args)
947# define hrm_validate(args...) ccc_hrm_validate(args)
948#endif /* HANDLE_REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC */
949
950#endif /* CCC_HANDLE_REALTIME_ORDERED_MAP_H */
ccc_ucount ccc_hrm_capacity(ccc_handle_realtime_ordered_map const *hrm)
Returns the capacity of the map representing total available slots.
ccc_range ccc_hrm_equal_range(ccc_handle_realtime_ordered_map const *hrm, void const *begin_key, void const *end_key)
Return an iterable range of values from [begin_key, end_key). O(lgN).
ccc_result ccc_hrm_clear_and_free(ccc_handle_realtime_ordered_map *hrm, ccc_any_type_destructor_fn *fn)
Frees all slots in the map and frees the underlying buffer.
ccc_handle_i ccc_hrm_unwrap(ccc_hromap_handle const *h)
Unwraps the provided handle to obtain a view into the map element.
ccc_result ccc_hrm_copy(ccc_handle_realtime_ordered_map *dst, ccc_handle_realtime_ordered_map const *src, ccc_any_alloc_fn *fn)
Copy the map at source to destination.
ccc_handle ccc_hrm_insert_or_assign(ccc_handle_realtime_ordered_map *hrm, void const *key_val_type)
Invariantly inserts or overwrites a user struct into the map.
void * ccc_hrm_rend(ccc_handle_realtime_ordered_map const *hrm)
Return the rend of a reverse inorder traversal of the map. O(1).
ccc_rrange ccc_hrm_equal_rrange(ccc_handle_realtime_ordered_map const *hrm, void const *rbegin_key, void const *rend_key)
Return an iterable rrange of values from [begin_key, end_key). O(lg N).
struct ccc_hromap ccc_handle_realtime_ordered_map
A handle realtime ordered map offers O(lg N) search and erase, and amortized O(lg N) insert.
Definition: handle_realtime_ordered_map.h:72
ccc_hromap_handle ccc_hrm_handle(ccc_handle_realtime_ordered_map const *hrm, void const *key)
Obtains a handle for the provided key in the map for future use.
ccc_handle_i ccc_hrm_or_insert(ccc_hromap_handle const *h, void const *key_val_type)
Inserts the provided user type if the handle is Vacant.
void * ccc_hrm_data(ccc_handle_realtime_ordered_map const *hrm)
Return a reference to the base of backing array. O(1).
void * ccc_hrm_begin(ccc_handle_realtime_ordered_map const *hrm)
Return the start of an inorder traversal of the map. O(lg N).
ccc_hromap_handle * ccc_hrm_and_modify(ccc_hromap_handle *h, ccc_any_type_update_fn *fn)
Modifies the provided handle if it is Occupied.
void * ccc_hrm_end(ccc_handle_realtime_ordered_map const *hrm)
Return the end of an inorder traversal of the map. O(1).
ccc_handle ccc_hrm_remove(ccc_handle_realtime_ordered_map *hrm, void *key_val_type_output)
Removes the key value in the map storing the old value, if present, in the struct containing key_val_...
ccc_ucount ccc_hrm_count(ccc_handle_realtime_ordered_map const *hrm)
Returns the count of map occupied slots.
void * ccc_hrm_at(ccc_handle_realtime_ordered_map const *h, ccc_handle_i i)
Returns a reference to the user data at the provided handle.
ccc_result ccc_hrm_reserve(ccc_handle_realtime_ordered_map *hrm, size_t to_add, ccc_any_alloc_fn *fn)
Reserves space for at least to_add more elements.
ccc_handle ccc_hrm_swap_handle(ccc_handle_realtime_ordered_map *hrm, void *key_val_type_output)
Invariantly inserts the key value in key_val_type_output.
void * ccc_hrm_next(ccc_handle_realtime_ordered_map const *hrm, void const *key_val_type_iter)
Return the next element in an inorder traversal of the map. O(1).
void * ccc_hrm_rbegin(ccc_handle_realtime_ordered_map const *hrm)
Return the start of a reverse inorder traversal of the map. O(lg N).
ccc_handle_i ccc_hrm_insert_handle(ccc_hromap_handle const *h, void const *key_val_type)
Inserts the provided user type invariantly.
ccc_result ccc_hrm_clear_and_free_reserve(ccc_handle_realtime_ordered_map *hrm, ccc_any_type_destructor_fn *destructor, ccc_any_alloc_fn *alloc)
Frees all slots in the hrm and frees the underlying buffer that was previously dynamically reserved w...
ccc_tribool ccc_hrm_contains(ccc_handle_realtime_ordered_map const *hrm, void const *key)
Searches the map for the presence of key.
union ccc_hromap_handle ccc_hromap_handle
A container specific handle used to implement the Handle Interface.
Definition: handle_realtime_ordered_map.h:82
ccc_result ccc_hrm_clear(ccc_handle_realtime_ordered_map *hrm, ccc_any_type_destructor_fn *fn)
Frees all slots in the map for use without affecting capacity.
void * ccc_hrm_rnext(ccc_handle_realtime_ordered_map const *hrm, void const *key_val_type_iter)
Return the rnext element in a reverse inorder traversal of the map. O(1).
ccc_handle ccc_hrm_remove_handle(ccc_hromap_handle const *h)
Remove the handle from the map if Occupied.
ccc_tribool ccc_hrm_occupied(ccc_hromap_handle const *h)
Returns the Vacant or Occupied status of the handle.
ccc_handle_status ccc_hrm_handle_status(ccc_hromap_handle const *h)
Obtain the handle status from a container handle.
ccc_tribool ccc_hrm_validate(ccc_handle_realtime_ordered_map const *hrm)
Validation of invariants for the map.
ccc_tribool ccc_hrm_is_empty(ccc_handle_realtime_ordered_map const *hrm)
Returns the size status of the map.
ccc_handle ccc_hrm_try_insert(ccc_handle_realtime_ordered_map *hrm, void const *key_val_type)
Attempts to insert the key value in key_val_type.
ccc_hromap_handle * ccc_hrm_and_modify_aux(ccc_hromap_handle *h, ccc_any_type_update_fn *fn, void *aux)
Modifies the provided handle if it is Occupied.
ccc_tribool ccc_hrm_insert_error(ccc_hromap_handle const *h)
Provides the status of the handle should an insertion follow.
ccc_handle_i ccc_hrm_get_key_val(ccc_handle_realtime_ordered_map const *hrm, void const *key)
Returns a reference into the map at handle key.
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:187
#define ccc_handle(container_ptr, key_ptr...)
Obtain a container specific handle for the handle Interface.
Definition: traits.h:150
The C Container Collection Fundamental Types.
size_t ccc_handle_i
A stable index to user data in a container that uses a flat array as the underlying storage method.
Definition: types.h:93
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
enum ccc_entry_status ccc_handle_status
The status monitoring and handle state once it is obtained.
Definition: types.h:103
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