C Container Collection (CCC)
Loading...
Searching...
No Matches
handle_realtime_ordered_map.h
Go to the documentation of this file.
1
31#ifndef CCC_HANDLE_REALTIME_ORDERED_MAP_H
32#define CCC_HANDLE_REALTIME_ORDERED_MAP_H
33
35#include <stddef.h>
38#include "impl/impl_handle_realtime_ordered_map.h"
39#include "types.h"
40
51typedef struct ccc_hromap_ ccc_handle_realtime_ordered_map;
52
57typedef struct ccc_hromap_elem_ ccc_hromap_elem;
58
67typedef union ccc_hromap_handle_ ccc_hromap_handle;
68
86#define ccc_hrm_init(memory_ptr, hrm_elem_field, key_elem_field, key_cmp_fn, \
87 alloc_fn, aux_data, capacity) \
88 ccc_impl_hrm_init(memory_ptr, hrm_elem_field, key_elem_field, key_cmp_fn, \
89 alloc_fn, aux_data, capacity)
90
175 ccc_alloc_fn *fn);
176
193[[nodiscard]] void *ccc_hrm_at(ccc_handle_realtime_ordered_map const *h,
194 ccc_handle_i i);
195
202#define ccc_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i...) \
203 ccc_impl_hrm_as(handle_realtime_ordered_map_ptr, type_name, handle_i)
204
210[[nodiscard]] ccc_tribool
212
217[[nodiscard]] ccc_handle_i
219 void const *key);
220
238[[nodiscard]] ccc_handle
240 ccc_hromap_elem *out_handle);
241
253#define ccc_hrm_swap_handle_r(handle_realtime_ordered_map_ptr, out_handle_ptr) \
254 &(ccc_handle) \
255 { \
256 ccc_hrm_swap_handle((handle_realtime_ordered_map_ptr), \
257 (out_handle_ptr)) \
258 .impl_ \
259 }
260
268[[nodiscard]] ccc_handle
270 ccc_hromap_elem *key_val_handle);
271
279#define ccc_hrm_try_insert_r(handle_realtime_ordered_map_ptr, \
280 key_val_handle_ptr) \
281 &(ccc_handle) \
282 { \
283 ccc_hrm_try_insert((handle_realtime_ordered_map_ptr), \
284 (key_val_handle_ptr)) \
285 .impl_ \
286 }
287
300#define ccc_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, \
301 lazy_value...) \
302 &(ccc_handle) \
303 { \
304 ccc_impl_hrm_try_insert_w(handle_realtime_ordered_map_ptr, key, \
305 lazy_value) \
306 }
307
316[[nodiscard]] ccc_handle
318 ccc_hromap_elem *key_val_handle);
319
332#define ccc_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, \
333 lazy_value...) \
334 &(ccc_handle) \
335 { \
336 ccc_impl_hrm_insert_or_assign_w(handle_realtime_ordered_map_ptr, key, \
337 lazy_value) \
338 }
339
351 ccc_hromap_elem *out_handle);
352
363#define ccc_hrm_remove_r(handle_realtime_ordered_map_ptr, out_handle_ptr) \
364 &(ccc_handle) \
365 { \
366 ccc_hrm_remove((handle_realtime_ordered_map_ptr), (out_handle_ptr)) \
367 .impl_ \
368 }
369
385[[nodiscard]] ccc_hromap_handle
387
403#define ccc_hrm_handle_r(handle_realtime_ordered_map_ptr, key_ptr) \
404 &(ccc_hromap_handle) \
405 { \
406 ccc_hrm_handle((handle_realtime_ordered_map_ptr), (key_ptr)).impl_ \
407 }
408
418 ccc_update_fn *fn);
419
428[[nodiscard]] ccc_hromap_handle *
430
458#define ccc_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, \
459 type_name, closure_over_T...) \
460 &(ccc_hromap_handle) \
461 { \
462 ccc_impl_hrm_and_modify_w(handle_realtime_ordered_map_handle_ptr, \
463 type_name, closure_over_T) \
464 }
465
478 ccc_hromap_elem *elem);
479
492#define ccc_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, \
493 lazy_key_value...) \
494 ccc_impl_hrm_or_insert_w(handle_realtime_ordered_map_handle_ptr, \
495 lazy_key_value)
496
505 ccc_hromap_elem *elem);
506
513#define ccc_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, \
514 lazy_key_value...) \
515 ccc_impl_hrm_insert_handle_w(handle_realtime_ordered_map_handle_ptr, \
516 lazy_key_value)
517
526
535#define ccc_hrm_remove_handle_r(handle_realtime_ordered_map_handle_ptr) \
536 &(ccc_handle) \
537 { \
538 ccc_hrm_remove_handle((handle_realtime_ordered_map_handle_ptr)).impl_ \
539 }
540
545
550
557
567[[nodiscard]] ccc_handle_status
569
585
598
623[[nodiscard]] ccc_range
625 void const *begin_key, void const *end_key);
626
633#define ccc_hrm_equal_range_r(handle_realtime_ordered_map_ptr, \
634 begin_and_end_key_ptrs...) \
635 &(ccc_range) \
636 { \
637 ccc_hrm_equal_range((handle_realtime_ordered_map_ptr), \
638 (begin_and_end_key_ptrs)) \
639 .impl_ \
640 }
641
660[[nodiscard]] ccc_rrange
662 void const *rbegin_key, void const *rend_key);
663
671#define ccc_hrm_equal_rrange_r(handle_realtime_ordered_map_ptr, \
672 rbegin_and_rend_key_ptrs...) \
673 &(ccc_rrange) \
674 { \
675 ccc_hrm_equal_rrange((handle_realtime_ordered_map_ptr), \
676 (rbegin_and_rend_key_ptrs)) \
677 .impl_ \
678 }
679
683[[nodiscard]] void *ccc_hrm_begin(ccc_handle_realtime_ordered_map const *hrm);
684
688[[nodiscard]] void *ccc_hrm_rbegin(ccc_handle_realtime_ordered_map const *hrm);
689
695[[nodiscard]] void *ccc_hrm_next(ccc_handle_realtime_ordered_map const *hrm,
696 ccc_hromap_elem const *iter_handle);
697
704[[nodiscard]] void *ccc_hrm_rnext(ccc_handle_realtime_ordered_map const *hrm,
705 ccc_hromap_elem const *iter_handle);
706
710[[nodiscard]] void *ccc_hrm_end(ccc_handle_realtime_ordered_map const *hrm);
711
715[[nodiscard]] void *ccc_hrm_rend(ccc_handle_realtime_ordered_map const *hrm);
716
726[[nodiscard]] ccc_tribool
728
732[[nodiscard]] ccc_ucount
734
738[[nodiscard]] ccc_ucount
740
748[[nodiscard]] void *ccc_hrm_data(ccc_handle_realtime_ordered_map const *hrm);
749
754[[nodiscard]] ccc_tribool
756
761#ifdef HANDLE_REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC
762typedef ccc_hromap_elem hromap_elem;
763typedef ccc_handle_realtime_ordered_map handle_realtime_ordered_map;
764typedef ccc_hromap_handle hromap_handle;
765# define hrm_at(args...) ccc_hrm_at(args)
766# define hrm_as(args...) ccc_hrm_as(args)
767# define hrm_and_modify_w(args...) ccc_hrm_and_modify_w(args)
768# define hrm_or_insert_w(args...) ccc_hrm_or_insert_w(args)
769# define hrm_insert_handle_w(args...) ccc_hrm_insert_handle_w(args)
770# define hrm_try_insert_w(args...) ccc_hrm_try_insert_w(args)
771# define hrm_insert_or_assign_w(args...) ccc_hrm_insert_or_assign_w(args)
772# define hrm_init(args...) ccc_hrm_init(args)
773# define hrm_copy(args...) ccc_hrm_copy(args)
774# define hrm_contains(args...) ccc_hrm_contains(args)
775# define hrm_get_key_val(args...) ccc_hrm_get_key_val(args)
776# define hrm_swap_handle(args...) ccc_hrm_swap_handle(args)
777# define hrm_swap_handle_r(args...) ccc_hrm_swap_handle_r(args)
778# define hrm_begin(args...) ccc_hrm_begin(args)
779# define hrm_rbegin(args...) ccc_hrm_rbegin(args)
780# define hrm_next(args...) ccc_hrm_next(args)
781# define hrm_rnext(args...) ccc_hrm_rnext(args)
782# define hrm_end(args...) ccc_hrm_end(args)
783# define hrm_rend(args...) ccc_hrm_rend(args)
784# define hrm_data(args...) ccc_hrm_data(args)
785# define hrm_is_empty(args...) ccc_hrm_is_empty(args)
786# define hrm_size(args...) ccc_hrm_size(args)
787# define hrm_clear(args...) ccc_hrm_clear(args)
788# define hrm_clear_and_free(args...) ccc_hrm_clear_and_free(args)
789# define hrm_validate(args...) ccc_hrm_validate(args)
790#endif /* HANDLE_REALTIME_ORDERED_MAP_USING_NAMESPACE_CCC */
791
792#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_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_clear_and_free(ccc_handle_realtime_ordered_map *hrm, ccc_destructor_fn *fn)
Frees all slots in the map and frees the underlying buffer.
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.
ccc_hromap_handle * ccc_hrm_and_modify(ccc_hromap_handle *h, ccc_update_fn *fn)
Modifies the provided handle if it is Occupied.
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).
ccc_result ccc_hrm_clear(ccc_handle_realtime_ordered_map *hrm, ccc_destructor_fn *fn)
Frees all slots in the map for use without affecting capacity.
ccc_hromap_handle * ccc_hrm_and_modify_aux(ccc_hromap_handle *h, ccc_update_fn *fn, void *aux)
Modifies the provided handle if it is Occupied.
ccc_result ccc_hrm_copy(ccc_handle_realtime_ordered_map *dst, ccc_handle_realtime_ordered_map const *src, ccc_alloc_fn *fn)
Copy the map at source to destination.
void * ccc_hrm_begin(ccc_handle_realtime_ordered_map const *hrm)
Return the start of an inorder traversal of the map. O(lg N).
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_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_tribool ccc_hrm_contains(ccc_handle_realtime_ordered_map const *hrm, void const *key)
Searches the map for the presence of key.
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.
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:57
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:51
union ccc_hromap_handle_ ccc_hromap_handle
A container specific handle used to implement the Handle Interface.
Definition: handle_realtime_ordered_map.h:67
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.
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:172
The C Container Collection Fundamental Types.
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:300
union ccc_handle_ ccc_handle
An Occupied or Vacant handle to a flat searchable container entry.
Definition: types.h:66
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:78
union ccc_range_ ccc_range
The result of a range query on iterable containers.
Definition: types.h:29
ccc_result
A result of actions on containers.
Definition: types.h:117
enum ccc_entry_status_ ccc_handle_status
The status monitoring and handle state once it is obtained.
Definition: types.h:88
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:102
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:283
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:318
union ccc_rrange_ ccc_rrange
The result of a rrange query on iterable containers.
Definition: types.h:37