C Container Collection (CCC)
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
handle_realtime_ordered_map.h
Go to the documentation of this file.
1
46#ifndef CCC_HANDLE_REALTIME_ORDERED_MAP_H
47#define CCC_HANDLE_REALTIME_ORDERED_MAP_H
48
50#include <stddef.h>
53#include "impl/impl_handle_realtime_ordered_map.h"
54#include "types.h"
55
66typedef struct ccc_hromap ccc_handle_realtime_ordered_map;
67
73
83
101#define ccc_hrm_init(memory_ptr, hrm_elem_field, key_elem_field, key_cmp_fn, \
102 alloc_fn, aux_data, capacity) \
103 ccc_impl_hrm_init(memory_ptr, hrm_elem_field, key_elem_field, key_cmp_fn, \
104 alloc_fn, aux_data, capacity)
105
190 ccc_any_alloc_fn *fn);
191
210 ccc_any_alloc_fn *fn);
211
228[[nodiscard]] void *ccc_hrm_at(ccc_handle_realtime_ordered_map const *h,
229 ccc_handle_i i);
230
237#define ccc_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i...) \
238 ccc_impl_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i)
239
245[[nodiscard]] ccc_tribool
247
252[[nodiscard]] ccc_handle_i
254 void const *key);
255
273[[nodiscard]] ccc_handle
275 ccc_hromap_elem *out_handle);
276
288#define ccc_hrm_swap_handle_r(handle_realtime_ordered_map_ptr, out_handle_ptr) \
289 &(ccc_handle) \
290 { \
291 ccc_hrm_swap_handle((handle_realtime_ordered_map_ptr), \
292 (out_handle_ptr)) \
293 .impl \
294 }
295
303[[nodiscard]] ccc_handle
305 ccc_hromap_elem *key_val_handle);
306
314#define ccc_hrm_try_insert_r(handle_realtime_ordered_map_ptr, \
315 key_val_handle_ptr) \
316 &(ccc_handle) \
317 { \
318 ccc_hrm_try_insert((handle_realtime_ordered_map_ptr), \
319 (key_val_handle_ptr)) \
320 .impl \
321 }
322
335#define ccc_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, \
336 lazy_value...) \
337 &(ccc_handle) \
338 { \
339 ccc_impl_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, \
340 lazy_value) \
341 }
342
351[[nodiscard]] ccc_handle
353 ccc_hromap_elem *key_val_handle);
354
367#define ccc_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, \
368 lazy_value...) \
369 &(ccc_handle) \
370 { \
371 ccc_impl_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, \
372 lazy_value) \
373 }
374
386 ccc_hromap_elem *out_handle);
387
398#define ccc_hrm_remove_r(handle_realtime_ordered_map_ptr, out_handle_ptr) \
399 &(ccc_handle) \
400 { \
401 ccc_hrm_remove((handle_realtime_ordered_map_ptr), (out_handle_ptr)) \
402 .impl \
403 }
404
420[[nodiscard]] ccc_hromap_handle
422
438#define ccc_hrm_handle_r(handle_realtime_ordered_map_ptr, key_ptr) \
439 &(ccc_hromap_handle) \
440 { \
441 ccc_hrm_handle((handle_realtime_ordered_map_ptr), (key_ptr)).impl \
442 }
443
455
464[[nodiscard]] ccc_hromap_handle *
466 void *aux);
467
495#define ccc_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, \
496 type_name, closure_over_T...) \
497 &(ccc_hromap_handle) \
498 { \
499 ccc_impl_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, \
500 type_name, closure_over_T) \
501 }
502
515 ccc_hromap_elem *elem);
516
529#define ccc_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, \
530 lazy_key_value...) \
531 ccc_impl_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, \
532 lazy_key_value)
533
542 ccc_hromap_elem *elem);
543
550#define ccc_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, \
551 lazy_key_value...) \
552 ccc_impl_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, \
553 lazy_key_value)
554
563
572#define ccc_hrm_remove_handle_r(handle_realtime_ordered_map_handle_ptr) \
573 &(ccc_handle) \
574 { \
575 ccc_hrm_remove_handle((handle_realtime_ordered_map_handle_ptr)).impl \
576 }
577
582
587
594
604[[nodiscard]] ccc_handle_status
606
622
635
664 ccc_any_type_destructor_fn *destructor,
665 ccc_any_alloc_fn *alloc);
666
691[[nodiscard]] ccc_range
693 void const *begin_key, void const *end_key);
694
701#define ccc_hrm_equal_range_r(handle_realtime_ordered_map_ptr, \
702 begin_and_end_key_ptrs...) \
703 &(ccc_range) \
704 { \
705 ccc_hrm_equal_range((handle_realtime_ordered_map_ptr), \
706 (begin_and_end_key_ptrs)) \
707 .impl \
708 }
709
728[[nodiscard]] ccc_rrange
730 void const *rbegin_key, void const *rend_key);
731
739#define ccc_hrm_equal_rrange_r(handle_realtime_ordered_map_ptr, \
740 rbegin_and_rend_key_ptrs...) \
741 &(ccc_rrange) \
742 { \
743 ccc_hrm_equal_rrange((handle_realtime_ordered_map_ptr), \
744 (rbegin_and_rend_key_ptrs)) \
745 .impl \
746 }
747
751[[nodiscard]] void *ccc_hrm_begin(ccc_handle_realtime_ordered_map const *hrm);
752
756[[nodiscard]] void *ccc_hrm_rbegin(ccc_handle_realtime_ordered_map const *hrm);
757
763[[nodiscard]] void *ccc_hrm_next(ccc_handle_realtime_ordered_map const *hrm,
764 ccc_hromap_elem const *iter_handle);
765
772[[nodiscard]] void *ccc_hrm_rnext(ccc_handle_realtime_ordered_map const *hrm,
773 ccc_hromap_elem const *iter_handle);
774
778[[nodiscard]] void *ccc_hrm_end(ccc_handle_realtime_ordered_map const *hrm);
779
783[[nodiscard]] void *ccc_hrm_rend(ccc_handle_realtime_ordered_map const *hrm);
784
794[[nodiscard]] ccc_tribool
796
800[[nodiscard]] ccc_ucount
802
806[[nodiscard]] ccc_ucount
808
816[[nodiscard]] void *ccc_hrm_data(ccc_handle_realtime_ordered_map const *hrm);
817
822[[nodiscard]] ccc_tribool
824
829#ifdef HANDLE_REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC
830typedef ccc_hromap_elem hromap_elem;
831typedef ccc_handle_realtime_ordered_map handle_realtime_ordered_map;
832typedef ccc_hromap_handle hromap_handle;
833# define hrm_at(args...) ccc_hrm_at(args)
834# define hrm_as(args...) ccc_hrm_as(args)
835# define hrm_and_modify_w(args...) ccc_hrm_and_modify_w(args)
836# define hrm_or_insert_w(args...) ccc_hrm_or_insert_w(args)
837# define hrm_insert_handle_w(args...) ccc_hrm_insert_handle_w(args)
838# define hrm_try_insert_w(args...) ccc_hrm_try_insert_w(args)
839# define hrm_insert_or_assign_w(args...) ccc_hrm_insert_or_assign_w(args)
840# define hrm_init(args...) ccc_hrm_init(args)
841# define hrm_copy(args...) ccc_hrm_copy(args)
842# define hrm_reserve(args...) ccc_hrm_reserve(args)
843# define hrm_contains(args...) ccc_hrm_contains(args)
844# define hrm_get_key_val(args...) ccc_hrm_get_key_val(args)
845# define hrm_swap_handle(args...) ccc_hrm_swap_handle(args)
846# define hrm_swap_handle_r(args...) ccc_hrm_swap_handle_r(args)
847# define hrm_begin(args...) ccc_hrm_begin(args)
848# define hrm_rbegin(args...) ccc_hrm_rbegin(args)
849# define hrm_next(args...) ccc_hrm_next(args)
850# define hrm_rnext(args...) ccc_hrm_rnext(args)
851# define hrm_end(args...) ccc_hrm_end(args)
852# define hrm_rend(args...) ccc_hrm_rend(args)
853# define hrm_data(args...) ccc_hrm_data(args)
854# define hrm_is_empty(args...) ccc_hrm_is_empty(args)
855# define hrm_size(args...) ccc_hrm_size(args)
856# define hrm_clear(args...) ccc_hrm_clear(args)
857# define hrm_clear_and_free(args...) ccc_hrm_clear_and_free(args)
858# define hrm_clear_and_free_reserve(args...) \
859 ccc_hrm_clear_and_free_reserve(args)
860# define hrm_validate(args...) ccc_hrm_validate(args)
861#endif /* HANDLE_REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC */
862
863#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(lg N).
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_handle ccc_hrm_remove(ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *out_handle)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
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.
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).
ccc_handle_i ccc_hrm_insert_handle(ccc_hromap_handle const *h, ccc_hromap_elem *elem)
Inserts the provided handle invariantly.
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:66
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.
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_i ccc_hrm_or_insert(ccc_hromap_handle const *h, ccc_hromap_elem *elem)
Inserts the struct with handle elem if the handle is Vacant.
void * ccc_hrm_next(ccc_handle_realtime_ordered_map const *hrm, ccc_hromap_elem const *iter_handle)
Return the next element in an inorder traversal of the map. O(1).
ccc_handle ccc_hrm_insert_or_assign(ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *key_val_handle)
Invariantly inserts or overwrites a user struct into the map.
void * ccc_hrm_rnext(ccc_handle_realtime_ordered_map const *hrm, ccc_hromap_elem const *iter_handle)
Return the rnext element in a reverse inorder traversal of the map. O(1).
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_ucount ccc_hrm_size(ccc_handle_realtime_ordered_map const *hrm)
Returns the size of the map representing active slots.
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_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.
ccc_handle ccc_hrm_swap_handle(ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *out_handle)
Invariantly inserts the key value wrapping key_val_handle.
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_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.
struct ccc_hromap_elem ccc_hromap_elem
The intrusive element for the user defined struct being stored in the map.
Definition: handle_realtime_ordered_map.h:72
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.
ccc_handle ccc_hrm_try_insert(ccc_handle_realtime_ordered_map *hrm, ccc_hromap_elem *key_val_handle)
Attempts to insert the key value wrapping key_val_handle.
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