C Container Collection (CCC)
Loading...
Searching...
No Matches
handle_ordered_map.h
Go to the documentation of this file.
1
32#ifndef CCC_HANDLE_ORDERED_MAP_H
33#define CCC_HANDLE_ORDERED_MAP_H
34
36#include <stddef.h>
39#include "impl/impl_handle_ordered_map.h"
40#include "types.h"
41
52typedef struct ccc_homap_ ccc_handle_ordered_map;
53
61typedef struct ccc_homap_elem_ ccc_homap_elem;
62
67typedef union ccc_homap_handle_ ccc_homap_handle;
68
85#define ccc_hom_init(mem_ptr, om_elem_field, key_elem_field, key_cmp, \
86 alloc_fn, aux, capacity) \
87 ccc_impl_hom_init(mem_ptr, om_elem_field, key_elem_field, key_cmp, \
88 alloc_fn, aux, capacity)
89
173 ccc_handle_ordered_map const *src, ccc_alloc_fn *fn);
174
191[[nodiscard]] void *ccc_hom_at(ccc_handle_ordered_map const *h, ccc_handle_i i);
192
199#define ccc_hom_as(handle_ordered_map_ptr, type_name, handle_i...) \
200 ccc_impl_hom_as(handle_ordered_map_ptr, type_name, handle_i)
201
208 void const *key);
209
215 void const *key);
216
235 ccc_homap_elem *out_handle);
236
248#define ccc_hom_swap_handle_r(handle_ordered_map_ptr, out_handle_ptr) \
249 &(ccc_handle) \
250 { \
251 ccc_hom_swap_handle((handle_ordered_map_ptr), (out_handle_ptr)).impl_ \
252 }
253
262 ccc_homap_elem *key_val_handle);
263
271#define ccc_hom_try_insert_r(handle_ordered_map_ptr, key_val_handle_ptr) \
272 &(ccc_handle) \
273 { \
274 ccc_hom_try_insert((handle_ordered_map_ptr), (key_val_handle_ptr)) \
275 .impl_ \
276 }
277
290#define ccc_hom_try_insert_w(handle_ordered_map_ptr, key, lazy_value...) \
291 &(ccc_handle) \
292 { \
293 ccc_impl_hom_try_insert_w(handle_ordered_map_ptr, key, lazy_value) \
294 }
295
304[[nodiscard]] ccc_handle
306 ccc_homap_elem *key_val_handle);
307
320#define ccc_hom_insert_or_assign_w(handle_ordered_map_ptr, key, lazy_value...) \
321 &(ccc_handle) \
322 { \
323 ccc_impl_hom_insert_or_assign_w(handle_ordered_map_ptr, key, \
324 lazy_value) \
325 }
326
338 ccc_homap_elem *out_handle);
339
350#define ccc_hom_remove_r(handle_ordered_map_ptr, out_handle_ptr) \
351 &(ccc_handle) \
352 { \
353 ccc_hom_remove((handle_ordered_map_ptr), (out_handle_ptr)).impl_ \
354 }
355
372 void const *key);
373
389#define ccc_hom_handle_r(handle_ordered_map_ptr, key_ptr) \
390 &(ccc_homap_handle) \
391 { \
392 ccc_hom_handle((handle_ordered_map_ptr), (key_ptr)).impl_ \
393 }
394
404 ccc_update_fn *fn);
405
414[[nodiscard]] ccc_homap_handle *
416
443#define ccc_hom_and_modify_w(handle_ordered_map_handle_ptr, type_name, \
444 closure_over_T...) \
445 &(ccc_homap_handle) \
446 { \
447 ccc_impl_hom_and_modify_w(handle_ordered_map_handle_ptr, type_name, \
448 closure_over_T) \
449 }
450
463 ccc_homap_elem *elem);
464
476#define ccc_hom_or_insert_w(handle_ordered_map_handle_ptr, lazy_key_value...) \
477 ccc_impl_hom_or_insert_w(handle_ordered_map_handle_ptr, lazy_key_value)
478
487 ccc_homap_elem *elem);
488
494#define ccc_hom_insert_handle_w(handle_ordered_map_handle_ptr, \
495 lazy_key_value...) \
496 ccc_impl_hom_insert_handle_w(handle_ordered_map_handle_ptr, lazy_key_value)
497
504
510#define ccc_hom_remove_handle_r(handle_ordered_map_handle_ptr) \
511 &(ccc_handle) \
512 { \
513 ccc_hom_remove_handle((handle_ordered_map_handle_ptr)).impl_ \
514 }
515
520
525
532
542[[nodiscard]] ccc_handle_status
544
572 void const *begin_key,
573 void const *end_key);
574
581#define ccc_hom_equal_range_r(handle_ordered_map_ptr, \
582 begin_and_end_key_ptrs...) \
583 &(ccc_range) \
584 { \
585 ccc_hom_equal_range(handle_ordered_map_ptr, begin_and_end_key_ptrs) \
586 .impl_ \
587 }
588
610 void const *rbegin_key,
611 void const *rend_key);
612
620#define ccc_hom_equal_rrange_r(handle_ordered_map_ptr, \
621 rbegin_and_rend_key_ptrs...) \
622 &(ccc_rrange) \
623 { \
624 ccc_hom_equal_rrange(handle_ordered_map_ptr, rbegin_and_rend_key_ptrs) \
625 .impl_ \
626 }
627
632[[nodiscard]] void *ccc_hom_begin(ccc_handle_ordered_map const *hom);
633
638[[nodiscard]] void *ccc_hom_rbegin(ccc_handle_ordered_map const *hom);
639
645[[nodiscard]] void *ccc_hom_next(ccc_handle_ordered_map const *hom,
646 ccc_homap_elem const *iter_handle);
647
654[[nodiscard]] void *ccc_hom_rnext(ccc_handle_ordered_map const *hom,
655 ccc_homap_elem const *iter_handle);
656
660[[nodiscard]] void *ccc_hom_end(ccc_handle_ordered_map const *hom);
661
665[[nodiscard]] void *ccc_hom_rend(ccc_handle_ordered_map const *hom);
666
681
694
705
710
720[[nodiscard]] void *ccc_hom_data(ccc_handle_ordered_map const *hom);
721
726
732
737#ifdef HANDLE_ORDERED_MAP_USING_NAMESPACE_CCC
738typedef ccc_handle_ordered_map handle_ordered_map;
739typedef ccc_homap_elem homap_elem;
740typedef ccc_homap_handle homap_handle;
741# define hom_at(args...) ccc_hom_at(args)
742# define hom_as(args...) ccc_hom_as(args)
743# define hom_and_modify_w(args...) ccc_hom_and_modify_w(args)
744# define hom_or_insert_w(args...) ccc_hom_or_insert_w(args)
745# define hom_insert_handle_w(args...) ccc_hom_insert_handle_w(args)
746# define hom_try_insert_w(args...) ccc_hom_try_insert_w(args)
747# define hom_insert_or_assign_w(args...) ccc_hom_insert_or_assign_w(args)
748# define hom_init(args...) ccc_hom_init(args)
749# define hom_copy(args...) ccc_hom_copy(args)
750# define hom_contains(args...) ccc_hom_contains(args)
751# define hom_get_key_val(args...) ccc_hom_get_key_val(args)
752# define hom_swap_handle_r(args...) ccc_hom_swap_handle_r(args)
753# define hom_try_insert_r(args...) ccc_hom_try_insert_r(args)
754# define hom_remove_r(args...) ccc_hom_remove_r(args)
755# define hom_remove_handle_r(args...) ccc_hom_remove_handle_r(args)
756# define hom_swap_handle(args...) ccc_hom_swap_handle(args)
757# define hom_try_insert(args...) ccc_hom_try_insert(args)
758# define hom_insert_or_assign(args...) ccc_hom_insert_or_assign(args)
759# define hom_remove(args...) ccc_hom_remove(args)
760# define hom_remove_handle(args...) ccc_hom_remove_handle(args)
761# define hom_handle_r(args...) ccc_hom_handle_r(args)
762# define hom_handle(args...) ccc_hom_handle(args)
763# define hom_and_modify(args...) ccc_hom_and_modify(args)
764# define hom_and_modify_aux(args...) ccc_hom_and_modify_aux(args)
765# define hom_or_insert(args...) ccc_hom_or_insert(args)
766# define hom_insert_handle(args...) ccc_hom_insert_handle(args)
767# define hom_unwrap(args...) ccc_hom_unwrap(args)
768# define hom_insert_error(args...) ccc_hom_insert_error(args)
769# define hom_occupied(args...) ccc_hom_occupied(args)
770# define hom_clear(args...) ccc_hom_clear(args)
771# define hom_clear_and_free(args...) ccc_hom_clear_and_free(args)
772# define hom_begin(args...) ccc_hom_begin(args)
773# define hom_rbegin(args...) ccc_hom_rbegin(args)
774# define hom_end(args...) ccc_hom_end(args)
775# define hom_rend(args...) ccc_hom_rend(args)
776# define hom_next(args...) ccc_hom_next(args)
777# define hom_rnext(args...) ccc_hom_rnext(args)
778# define hom_data(args...) ccc_hom_data(args)
779# define hom_size(args...) ccc_hom_size(args)
780# define hom_is_empty(args...) ccc_hom_is_empty(args)
781# define hom_validate(args...) ccc_hom_validate(args)
782#endif /* HANDLE_ORDERED_MAP_USING_NAMESPACE_CCC */
783
784#endif /* CCC_HANDLE_ORDERED_MAP_H */
union ccc_homap_handle_ ccc_homap_handle
A container specific handle used to implement the Handle Interface.
Definition: handle_ordered_map.h:67
ccc_homap_handle * ccc_hom_and_modify(ccc_homap_handle *h, ccc_update_fn *fn)
Modifies the provided handle if it is Occupied.
void * ccc_hom_data(ccc_handle_ordered_map const *hom)
Return a reference to the base of backing array. O(1).
ccc_tribool ccc_hom_is_empty(ccc_handle_ordered_map const *hom)
Returns the size status of the map.
struct ccc_homap_ ccc_handle_ordered_map
A self-optimizing data structure offering amortized O(lg N) search, insert, and erase.
Definition: handle_ordered_map.h:52
ccc_rrange ccc_hom_equal_rrange(ccc_handle_ordered_map *hom, void const *rbegin_key, void const *rend_key)
Return an iterable rrange of values from [rbegin_key, end_key). Amortized O(lg N).
void * ccc_hom_rbegin(ccc_handle_ordered_map const *hom)
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
ccc_handle_i ccc_hom_insert_handle(ccc_homap_handle const *h, ccc_homap_elem *elem)
Inserts the provided handle invariantly.
ccc_handle_i ccc_hom_get_key_val(ccc_handle_ordered_map *hom, void const *key)
Returns a reference into the map at handle key.
ccc_ucount ccc_hom_capacity(ccc_handle_ordered_map const *hom)
Returns the capacity of the map representing total possible slots.
ccc_handle_status ccc_hom_handle_status(ccc_homap_handle const *h)
Obtain the handle status from a container handle.
void * ccc_hom_begin(ccc_handle_ordered_map const *hom)
Return the start of an inorder traversal of the map. Amortized O(lg N).
ccc_handle_i ccc_hom_unwrap(ccc_homap_handle const *h)
Unwraps the provided handle to obtain a view into the map element.
void * ccc_hom_rend(ccc_handle_ordered_map const *hom)
Return the rend of a reverse inorder traversal of the map. O(1).
ccc_handle_i ccc_hom_or_insert(ccc_homap_handle const *h, ccc_homap_elem *elem)
Inserts the struct with handle elem if the handle is Vacant.
ccc_tribool ccc_hom_validate(ccc_handle_ordered_map const *hom)
Validation of invariants for the map.
void * ccc_hom_at(ccc_handle_ordered_map const *h, ccc_handle_i i)
Returns a reference to the user data at the provided handle.
ccc_handle ccc_hom_swap_handle(ccc_handle_ordered_map *hom, ccc_homap_elem *out_handle)
Invariantly inserts the key value wrapping key_val_handle.
ccc_homap_handle ccc_hom_handle(ccc_handle_ordered_map *hom, void const *key)
Obtains a handle for the provided key in the map for future use.
void * ccc_hom_end(ccc_handle_ordered_map const *hom)
Return the end of an inorder traversal of the map. O(1).
void * ccc_hom_next(ccc_handle_ordered_map const *hom, ccc_homap_elem const *iter_handle)
Return the next element in an inorder traversal of the map. O(1).
ccc_result ccc_hom_clear(ccc_handle_ordered_map *hom, ccc_destructor_fn *fn)
Frees all slots in the map for use without affecting capacity.
ccc_handle ccc_hom_remove(ccc_handle_ordered_map *hom, ccc_homap_elem *out_handle)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
ccc_handle ccc_hom_remove_handle(ccc_homap_handle *h)
Remove the handle from the map if Occupied.
ccc_homap_handle * ccc_hom_and_modify_aux(ccc_homap_handle *h, ccc_update_fn *fn, void *aux)
Modifies the provided handle if it is Occupied.
ccc_handle ccc_hom_try_insert(ccc_handle_ordered_map *hom, ccc_homap_elem *key_val_handle)
Attempts to insert the key value wrapping key_val_handle.
ccc_tribool ccc_hom_insert_error(ccc_homap_handle const *h)
Provides the status of the handle should an insertion follow.
ccc_result ccc_hom_clear_and_free(ccc_handle_ordered_map *hom, ccc_destructor_fn *fn)
Frees all slots in the map and frees the underlying buffer.
struct ccc_homap_elem_ ccc_homap_elem
The intrusive element for the user defined type being stored in the map.
Definition: handle_ordered_map.h:61
ccc_result ccc_hom_copy(ccc_handle_ordered_map *dst, ccc_handle_ordered_map const *src, ccc_alloc_fn *fn)
Copy the map at source to destination.
ccc_range ccc_hom_equal_range(ccc_handle_ordered_map *hom, void const *begin_key, void const *end_key)
Return an iterable range of values from [begin_key, end_key). Amortized O(lg N).
ccc_handle ccc_hom_insert_or_assign(ccc_handle_ordered_map *hom, ccc_homap_elem *key_val_handle)
Invariantly inserts or overwrites a user struct into the map.
ccc_ucount ccc_hom_size(ccc_handle_ordered_map const *hom)
Returns the size of the map representing active slots.
ccc_tribool ccc_hom_occupied(ccc_homap_handle const *h)
Returns the Vacant or Occupied status of the handle.
ccc_tribool ccc_hom_contains(ccc_handle_ordered_map *hom, void const *key)
Searches the map for the presence of key.
void * ccc_hom_rnext(ccc_handle_ordered_map const *hom, ccc_homap_elem const *iter_handle)
Return the rnext element in a reverse inorder traversal of the map. O(1).
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