C Container Collection (CCC)
Loading...
Searching...
No Matches
array_adaptive_map.h
Go to the documentation of this file.
1
57#ifndef CCC_ARRAY_ADAPTIVE_MAP_H
58#define CCC_ARRAY_ADAPTIVE_MAP_H
59
61#include <stddef.h>
64#include "../types.h" /* IWYU pragma: export */
66
78
84
109#define CCC_array_adaptive_map_storage_for( \
110 user_type_compound_literal_array, optional_storage_specifier... \
111) \
112 CCC_private_array_adaptive_map_storage_for( \
113 user_type_compound_literal_array, optional_storage_specifier \
114 )
115
121#define CCC_array_adaptive_map_default( \
122 type_name, type_key_field, comparator... \
123) \
124 CCC_private_array_adaptive_map_default( \
125 type_name, type_key_field, comparator \
126 )
127
135#define CCC_array_adaptive_map_for( \
136 type_name, type_key_field, comparator, capacity, memory_pointer \
137) \
138 CCC_private_array_adaptive_map_for( \
139 type_name, type_key_field, comparator, capacity, memory_pointer \
140 )
141
195#define CCC_array_adaptive_map_from( \
196 type_key_field, \
197 comparator, \
198 allocator, \
199 optional_capacity, \
200 type_compound_literal_array... \
201) \
202 CCC_private_array_adaptive_map_from( \
203 type_key_field, \
204 comparator, \
205 allocator, \
206 optional_capacity, \
207 type_compound_literal_array \
208 )
209
251#define CCC_array_adaptive_map_with_capacity( \
252 type_name, type_key_field, comparator, allocator, capacity \
253) \
254 CCC_private_array_adaptive_map_with_capacity( \
255 type_name, type_key_field, comparator, allocator, capacity \
256 )
257
287#define CCC_array_adaptive_map_with_storage( \
288 type_key_field, \
289 comparator, \
290 compound_literal, \
291 optional_storage_specifier... \
292) \
293 CCC_private_array_adaptive_map_with_storage( \
294 type_key_field, \
295 comparator, \
296 compound_literal, \
297 optional_storage_specifier \
298 )
299
311#define CCC_array_adaptive_map_with_allocator_storage( \
312 key_field, comparator, allocator, compound_literal \
313) \
314 CCC_private_array_adaptive_map_with_allocator_storage( \
315 key_field, comparator, allocator, compound_literal \
316 )
317
389 CCC_Array_adaptive_map *destination,
390 CCC_Array_adaptive_map const *source,
391 CCC_Allocator const *allocator
392);
393
401 CCC_Array_adaptive_map *map, size_t to_add, CCC_Allocator const *allocator
402);
403
421[[nodiscard]] void *CCC_array_adaptive_map_at(
423);
424
431#define CCC_array_adaptive_map_as(map_pointer, type_name, array_index...) \
432 CCC_private_array_adaptive_map_as(map_pointer, type_name, array_index)
433
439[[nodiscard]] CCC_Tribool
441
447 CCC_Array_adaptive_map *map, void const *key
448);
449
470 void *type_output,
471 CCC_Allocator const *allocator
472);
473
486#define CCC_array_adaptive_map_swap_handle_wrap( \
487 map_pointer, type_output_pointer, allocator_pointer... \
488) \
489 &(struct { CCC_Handle private; }){ \
490 CCC_array_adaptive_map_swap_handle( \
491 (map_pointer), (type_output_pointer), allocator_pointer \
492 )} \
493 .private
494
505 void const *type,
506 CCC_Allocator const *allocator
507);
508
517#define CCC_array_adaptive_map_try_insert_wrap( \
518 map_pointer, type_pointer, allocator_pointer... \
519) \
520 &(struct { CCC_Handle private; }){ \
521 CCC_array_adaptive_map_try_insert( \
522 (map_pointer), (type_pointer), allocator_pointer \
523 )} \
524 .private
525
540#define CCC_array_adaptive_map_try_insert_with( \
541 map_pointer, key, allocator_pointer, type_compound_literal... \
542) \
543 &(struct { CCC_Handle private; }){ \
544 CCC_private_array_adaptive_map_try_insert_with( \
545 map_pointer, key, allocator_pointer, type_compound_literal \
546 )} \
547 .private
548
560 void const *type,
561 CCC_Allocator const *allocator
562);
563
573#define CCC_array_adaptive_map_insert_or_assign_wrap( \
574 map_pointer, type_pointer, allocator_pointer... \
575) \
576 &(struct { CCC_Handle private; }){ \
577 CCC_array_adaptive_map_insert_or_assign( \
578 (map_pointer), (type_pointer), allocator_pointer \
579 )} \
580 .private
581
596#define CCC_array_adaptive_map_insert_or_assign_with( \
597 map_pointer, key, allocator_pointer, type_compound_literal... \
598) \
599 &(struct { CCC_Handle private; }){ \
600 CCC_private_array_adaptive_map_insert_or_assign_with( \
601 map_pointer, key, allocator_pointer, type_compound_literal \
602 )} \
603 .private
604
616 CCC_Array_adaptive_map *map, void *type_output
617);
618
630#define CCC_array_adaptive_map_remove_key_value_wrap( \
631 map_pointer, type_output_pointer \
632) \
633 &(struct { CCC_Handle private; }){CCC_array_adaptive_map_remove_key_value( \
634 (map_pointer), (type_output_pointer) \
635 )} \
636 .private
637
655
672#define CCC_array_adaptive_map_handle_wrap(handle_pointer, key_pointer) \
673 &(struct { CCC_Array_adaptive_map_handle private; }){ \
674 CCC_array_adaptive_map_handle((handle_pointer), (key_pointer))} \
675 .private
676
682 CCC_Array_adaptive_map_handle *handle, CCC_Modifier const *modifier
683);
684
720#define CCC_array_adaptive_map_and_modify_with( \
721 handle_pointer, closure_parameter, closure_over_closure_parameter... \
722) \
723 &(struct { CCC_Array_adaptive_map_handle private; }){ \
724 CCC_private_array_adaptive_map_and_modify_with( \
725 handle_pointer, closure_parameter, closure_over_closure_parameter \
726 )} \
727 .private
728
742 CCC_Array_adaptive_map_handle const *handle,
743 void const *type,
744 CCC_Allocator const *allocator
745);
746
759#define CCC_array_adaptive_map_or_insert_with( \
760 handle_pointer, allocator_pointer, type_compound_literal... \
761) \
762 CCC_private_array_adaptive_map_or_insert_with( \
763 handle_pointer, allocator_pointer, type_compound_literal \
764 )
765
775 CCC_Array_adaptive_map_handle const *handle,
776 void const *type,
777 CCC_Allocator const *allocator
778);
779
787#define CCC_array_adaptive_map_insert_handle_with( \
788 handle_pointer, allocator_pointer, type_compound_literal... \
789) \
790 CCC_private_array_adaptive_map_insert_handle_with( \
791 handle_pointer, allocator_pointer, type_compound_literal \
792 )
793
799[[nodiscard]] CCC_Handle
801
807#define CCC_array_adaptive_map_remove_handle_wrap(handle_pointer) \
808 &(struct { CCC_Handle private; }){ \
809 CCC_array_adaptive_map_remove_handle((handle_pointer))} \
810 .private
811
815[[nodiscard]] CCC_Handle_index
817
821[[nodiscard]] CCC_Tribool
823
831);
832
844);
845
874 CCC_Array_adaptive_map *map, void const *begin_key, void const *end_key
875);
876
884#define CCC_array_adaptive_map_equal_range_wrap( \
885 map_pointer, begin_and_end_key_pointers... \
886) \
887 &(struct { CCC_Handle_range private; }){ \
888 CCC_array_adaptive_map_equal_range( \
889 map_pointer, begin_and_end_key_pointers \
890 )} \
891 .private
892
916[[nodiscard]] CCC_Handle_range_reverse
919 void const *reverse_begin_key,
920 void const *reverse_end_key
921);
922
930#define CCC_array_adaptive_map_equal_range_reverse_wrap( \
931 map_pointer, reverse_begin_and_reverse_end_key_pointers... \
932) \
933 &(struct { CCC_Handle_range_reverse private; }){ \
934 CCC_array_adaptive_map_equal_range_reverse( \
935 map_pointer, reverse_begin_and_reverse_end_key_pointers \
936 )} \
937 .private
938
943[[nodiscard]] CCC_Handle_index
945
950[[nodiscard]] CCC_Handle_index
952
960);
961
970);
971
975[[nodiscard]] CCC_Handle_index
977
982[[nodiscard]] CCC_Handle_index
984
999 CCC_Array_adaptive_map *map, CCC_Destructor const *destructor
1000);
1001
1017 CCC_Destructor const *destructor,
1018 CCC_Allocator const *allocator
1019);
1020
1031[[nodiscard]] CCC_Count
1033
1038[[nodiscard]] CCC_Count
1040
1044[[nodiscard]] CCC_Tribool
1046
1051[[nodiscard]] CCC_Tribool
1053
1058#ifdef ARRAY_ADAPTIVE_MAP_USING_NAMESPACE_CCC
1059/* NOLINTBEGIN(readability-identifier-naming) */
1060typedef CCC_Array_adaptive_map Array_adaptive_map;
1061typedef CCC_Array_adaptive_map_handle Array_adaptive_map_handle;
1062# define array_adaptive_map_storage_for(arguments...) \
1063 CCC_array_adaptive_map_storage_for(arguments)
1064# define array_adaptive_map_default(arguments...) \
1065 CCC_array_adaptive_map_default(arguments)
1066# define array_adaptive_map_for(arguments...) \
1067 CCC_array_adaptive_map_for(arguments)
1068# define array_adaptive_map_from(arguments...) \
1069 CCC_array_adaptive_map_from(arguments)
1070# define array_adaptive_map_with_capacity(arguments...) \
1071 CCC_array_adaptive_map_with_capacity(arguments)
1072# define array_adaptive_map_with_storage(arguments...) \
1073 CCC_array_adaptive_map_with_storage(arguments)
1074# define array_adaptive_map_with_allocator_storage(arguments...) \
1075 CCC_array_adaptive_map_with_allocator_storage(arguments)
1076# define array_adaptive_map_at(arguments...) \
1077 CCC_array_adaptive_map_at(arguments)
1078# define array_adaptive_map_as(arguments...) \
1079 CCC_array_adaptive_map_as(arguments)
1080# define array_adaptive_map_and_modify_with(arguments...) \
1081 CCC_array_adaptive_map_and_modify_with(arguments)
1082# define array_adaptive_map_or_insert_with(arguments...) \
1083 CCC_array_adaptive_map_or_insert_with(arguments)
1084# define array_adaptive_map_insert_handle_with(arguments...) \
1085 CCC_array_adaptive_map_insert_handle_with(arguments)
1086# define array_adaptive_map_try_insert_with(arguments...) \
1087 CCC_array_adaptive_map_try_insert_with(arguments)
1088# define array_adaptive_map_copy(arguments...) \
1089 CCC_array_adaptive_map_copy(arguments)
1090# define array_adaptive_map_reserve(arguments...) \
1091 CCC_array_adaptive_map_reserve(arguments)
1092# define array_adaptive_map_contains(arguments...) \
1093 CCC_array_adaptive_map_contains(arguments)
1094# define array_adaptive_map_get_key_value(arguments...) \
1095 CCC_array_adaptive_map_get_key_value(arguments)
1096# define array_adaptive_map_swap_handle_wrap(arguments...) \
1097 CCC_array_adaptive_map_swap_handle_wrap(arguments)
1098# define array_adaptive_map_try_insert_wrap(arguments...) \
1099 CCC_array_adaptive_map_try_insert_wrap(arguments)
1100# define array_adaptive_map_remove_key_value_wrap(arguments...) \
1101 CCC_array_adaptive_map_remove_key_value_wrap(arguments)
1102# define array_adaptive_map_remove_handle_wrap(arguments...) \
1103 CCC_array_adaptive_map_remove_handle_wrap(arguments)
1104# define array_adaptive_map_swap_handle(arguments...) \
1105 CCC_array_adaptive_map_swap_handle(arguments)
1106# define array_adaptive_map_try_insert(arguments...) \
1107 CCC_array_adaptive_map_try_insert(arguments)
1108# define array_adaptive_map_insert_or_assign(arguments...) \
1109 CCC_array_adaptive_map_insert_or_assign(arguments)
1110# define array_adaptive_map_insert_or_assign_wrap(arguments...) \
1111 CCC_array_adaptive_map_insert_or_assign_wrap(arguments)
1112# define array_adaptive_map_insert_or_assign_with(arguments...) \
1113 CCC_array_adaptive_map_insert_or_assign_with(arguments)
1114# define array_adaptive_map_remove_key_value(arguments...) \
1115 CCC_array_adaptive_map_remove_key_value(arguments)
1116# define array_adaptive_map_remove_handle(arguments...) \
1117 CCC_array_adaptive_map_remove_handle(arguments)
1118# define array_adaptive_map_handle_wrap(arguments...) \
1119 CCC_array_adaptive_map_handle_wrap(arguments)
1120# define array_adaptive_map_handle(arguments...) \
1121 CCC_array_adaptive_map_handle(arguments)
1122# define array_adaptive_map_and_modify(arguments...) \
1123 CCC_array_adaptive_map_and_modify(arguments)
1124# define array_adaptive_map_or_insert(arguments...) \
1125 CCC_array_adaptive_map_or_insert(arguments)
1126# define array_adaptive_map_insert_handle(arguments...) \
1127 CCC_array_adaptive_map_insert_handle(arguments)
1128# define array_adaptive_map_unwrap(arguments...) \
1129 CCC_array_adaptive_map_unwrap(arguments)
1130# define array_adaptive_map_insert_error(arguments...) \
1131 CCC_array_adaptive_map_insert_error(arguments)
1132# define array_adaptive_map_handle_status(arguments...) \
1133 CCC_array_adaptive_map_handle_status(arguments)
1134# define array_adaptive_map_occupied(arguments...) \
1135 CCC_array_adaptive_map_occupied(arguments)
1136# define array_adaptive_map_clear(arguments...) \
1137 CCC_array_adaptive_map_clear(arguments)
1138# define array_adaptive_map_clear_and_free(arguments...) \
1139 CCC_array_adaptive_map_clear_and_free(arguments)
1140# define array_adaptive_map_begin(arguments...) \
1141 CCC_array_adaptive_map_begin(arguments)
1142# define array_adaptive_map_reverse_begin(arguments...) \
1143 CCC_array_adaptive_map_reverse_begin(arguments)
1144# define array_adaptive_map_end(arguments...) \
1145 CCC_array_adaptive_map_end(arguments)
1146# define array_adaptive_map_reverse_end(arguments...) \
1147 CCC_array_adaptive_map_reverse_end(arguments)
1148# define array_adaptive_map_next(arguments...) \
1149 CCC_array_adaptive_map_next(arguments)
1150# define array_adaptive_map_reverse_next(arguments...) \
1151 CCC_array_adaptive_map_reverse_next(arguments)
1152# define array_adaptive_map_equal_range(arguments...) \
1153 CCC_array_adaptive_map_equal_range(arguments)
1154# define array_adaptive_map_equal_range_wrap(arguments...) \
1155 CCC_array_adaptive_map_equal_range_wrap(arguments)
1156# define array_adaptive_map_equal_range_reverse(arguments...) \
1157 CCC_array_adaptive_map_equal_range_reverse(arguments)
1158# define array_adaptive_map_equal_range_reverse_wrap(arguments...) \
1159 CCC_array_adaptive_map_equal_range_reverse_wrap(arguments)
1160# define array_adaptive_map_count(arguments...) \
1161 CCC_array_adaptive_map_count(arguments)
1162# define array_adaptive_map_capacity(arguments...) \
1163 CCC_array_adaptive_map_capacity(arguments)
1164# define array_adaptive_map_is_empty(arguments...) \
1165 CCC_array_adaptive_map_is_empty(arguments)
1166# define array_adaptive_map_validate(arguments...) \
1167 CCC_array_adaptive_map_validate(arguments)
1168/* NOLINTEND(readability-identifier-naming) */
1169#endif /* ARRAY_ADAPTIVE_MAP_USING_NAMESPACE_CCC */
1170
1171#endif /* CCC_ARRAY_ADAPTIVE_MAP_H */
CCC_Tribool CCC_array_adaptive_map_validate(CCC_Array_adaptive_map const *map)
Validation of invariants for the map.
CCC_Handle CCC_array_adaptive_map_insert_or_assign(CCC_Array_adaptive_map *map, void const *type, CCC_Allocator const *allocator)
Invariantly inserts or overwrites a user struct into the map.
CCC_Tribool CCC_array_adaptive_map_insert_error(CCC_Array_adaptive_map_handle const *handle)
Provides the status of the handle should an insertion follow.
CCC_Result CCC_array_adaptive_map_clear(CCC_Array_adaptive_map *map, CCC_Destructor const *destructor)
Frees all slots in the map for use without affecting capacity.
void * CCC_array_adaptive_map_at(CCC_Array_adaptive_map const *map, CCC_Handle_index index)
Returns a reference to the user data at the provided handle.
CCC_Array_adaptive_map_handle * CCC_array_adaptive_map_and_modify(CCC_Array_adaptive_map_handle *handle, CCC_Modifier const *modifier)
Modifies the provided handle if it is Occupied.
CCC_Result CCC_array_adaptive_map_copy(CCC_Array_adaptive_map *destination, CCC_Array_adaptive_map const *source, CCC_Allocator const *allocator)
Copy the map at source to destination.
CCC_Handle CCC_array_adaptive_map_remove_handle(CCC_Array_adaptive_map_handle *handle)
Remove the handle from the map if Occupied.
CCC_Handle_index CCC_array_adaptive_map_reverse_end(CCC_Array_adaptive_map const *map)
Return the reverse_end of a reverse inorder traversal of the map. O(1).
CCC_Count CCC_array_adaptive_map_count(CCC_Array_adaptive_map const *map)
Returns the count of map occupied slots.
CCC_Handle_status CCC_array_adaptive_map_handle_status(CCC_Array_adaptive_map_handle const *handle)
Obtain the handle status from a container handle.
CCC_Result CCC_array_adaptive_map_clear_and_free(CCC_Array_adaptive_map *map, CCC_Destructor const *destructor, CCC_Allocator const *allocator)
Frees all slots in the map and frees the underlying buffer.
CCC_Handle_index CCC_array_adaptive_map_get_key_value(CCC_Array_adaptive_map *map, void const *key)
Returns a reference into the map at handle key.
CCC_Handle_index CCC_array_adaptive_map_insert_handle(CCC_Array_adaptive_map_handle const *handle, void const *type, CCC_Allocator const *allocator)
Inserts the provided handle invariantly.
CCC_Tribool CCC_array_adaptive_map_is_empty(CCC_Array_adaptive_map const *map)
Returns the size status of the map.
CCC_Handle CCC_array_adaptive_map_remove_key_value(CCC_Array_adaptive_map *map, void *type_output)
Removes the key value in the map storing the old value, if present, in the struct containing type_out...
CCC_Handle CCC_array_adaptive_map_swap_handle(CCC_Array_adaptive_map *map, void *type_output, CCC_Allocator const *allocator)
Invariantly inserts the key value type.
CCC_Handle_index CCC_array_adaptive_map_end(CCC_Array_adaptive_map const *map)
Return the end of an inorder traversal of the map. O(1).
CCC_Handle_index CCC_array_adaptive_map_reverse_begin(CCC_Array_adaptive_map const *map)
Return the start of a reverse inorder traversal of the map. Amortized O(lg N).
CCC_Handle CCC_array_adaptive_map_try_insert(CCC_Array_adaptive_map *map, void const *type, CCC_Allocator const *allocator)
Attempts to insert the key value type.
CCC_Handle_index CCC_array_adaptive_map_unwrap(CCC_Array_adaptive_map_handle const *handle)
Unwraps the provided handle to obtain a view into the map element.
CCC_Handle_range_reverse CCC_array_adaptive_map_equal_range_reverse(CCC_Array_adaptive_map *map, void const *reverse_begin_key, void const *reverse_end_key)
Return an iterable range_reverse of values from [reverse_begin_key, end_key). Amortized O(lg N).
CCC_Result CCC_array_adaptive_map_reserve(CCC_Array_adaptive_map *map, size_t to_add, CCC_Allocator const *allocator)
Reserves space for at least to_add more elements.
CCC_Handle_range CCC_array_adaptive_map_equal_range(CCC_Array_adaptive_map *map, 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_index CCC_array_adaptive_map_or_insert(CCC_Array_adaptive_map_handle const *handle, void const *type, CCC_Allocator const *allocator)
Inserts the struct with user type if the handle is Vacant.
CCC_Tribool CCC_array_adaptive_map_contains(CCC_Array_adaptive_map *map, void const *key)
Searches the map for the presence of key.
CCC_Handle_index CCC_array_adaptive_map_next(CCC_Array_adaptive_map const *map, CCC_Handle_index iterator)
Return the next element in an inorder traversal of the map. O(1).
CCC_Handle_index CCC_array_adaptive_map_begin(CCC_Array_adaptive_map const *map)
Return the start of an inorder traversal of the map. Amortized O(lg N).
CCC_Array_adaptive_map_handle CCC_array_adaptive_map_handle(CCC_Array_adaptive_map *map, void const *key)
Obtains a handle for the provided key in the map for future use.
CCC_Count CCC_array_adaptive_map_capacity(CCC_Array_adaptive_map const *map)
Returns the capacity of the map representing total possible slots.
CCC_Handle_index CCC_array_adaptive_map_reverse_next(CCC_Array_adaptive_map const *map, CCC_Handle_index iterator)
Return the reverse_next element in a reverse inorder traversal of the map. O(1).
CCC_Tribool CCC_array_adaptive_map_occupied(CCC_Array_adaptive_map_handle const *handle)
Returns the Vacant or Occupied status of the handle.
The Private Array Adaptive Map Types and Interface.
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:384
Definition: private_array_adaptive_map.h:108
size_t index
Definition: private_array_adaptive_map.h:112
struct CCC_Array_adaptive_map * map
Definition: private_array_adaptive_map.h:110
Definition: private_array_adaptive_map.h:83
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:243
The type passed by reference to any container function that may need to destroy elements....
Definition: types.h:472
The result of a range_reverse query on iterable containers. Handles are stable indices into an array ...
Definition: types.h:97
The result of a range query on iterable containers. Handles are stable indices into an array until re...
Definition: types.h:82
An Occupied or Vacant handle to a flat searchable container entry.
Definition: types.h:150
The type passed by reference to any container function that may need to modify elements....
Definition: types.h:444
size_t CCC_Handle_index
A stable index to user data in a container that uses a flat array as the underlying storage method.
Definition: types.h:72
CCC_Entry_status
The status monitoring and entry state once it is obtained.
Definition: types.h:112
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:178
CCC_Result
A result of actions on containers.
Definition: types.h:192