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 "private/private_array_adaptive_map.h"
65#include "types.h"
66
78
84
135#define CCC_array_adaptive_map_storage_for( \
136 user_type_compound_literal_array, optional_storage_specifier... \
137) \
138 CCC_private_array_adaptive_map_storage_for( \
139 user_type_compound_literal_array, optional_storage_specifier \
140 )
141
147#define CCC_array_adaptive_map_default( \
148 type_name, type_key_field, comparator... \
149) \
150 CCC_private_array_adaptive_map_default( \
151 type_name, type_key_field, comparator \
152 )
153
161#define CCC_array_adaptive_map_for( \
162 type_name, type_key_field, comparator, capacity, memory_pointer \
163) \
164 CCC_private_array_adaptive_map_for( \
165 type_name, type_key_field, comparator, capacity, memory_pointer \
166 )
167
221#define CCC_array_adaptive_map_from( \
222 type_key_field, \
223 comparator, \
224 allocator, \
225 optional_capacity, \
226 type_compound_literal_array... \
227) \
228 CCC_private_array_adaptive_map_from( \
229 type_key_field, \
230 comparator, \
231 allocator, \
232 optional_capacity, \
233 type_compound_literal_array \
234 )
235
277#define CCC_array_adaptive_map_with_capacity( \
278 type_name, type_key_field, comparator, allocator, capacity \
279) \
280 CCC_private_array_adaptive_map_with_capacity( \
281 type_name, type_key_field, comparator, allocator, capacity \
282 )
283
313#define CCC_array_adaptive_map_with_storage( \
314 type_key_field, \
315 comparator, \
316 compound_literal, \
317 optional_storage_specifier... \
318) \
319 CCC_private_array_adaptive_map_with_storage( \
320 type_key_field, \
321 comparator, \
322 compound_literal, \
323 optional_storage_specifier \
324 )
325
397 CCC_Array_adaptive_map *destination,
398 CCC_Array_adaptive_map const *source,
399 CCC_Allocator const *allocator
400);
401
409 CCC_Array_adaptive_map *map, size_t to_add, CCC_Allocator const *allocator
410);
411
429[[nodiscard]] void *CCC_array_adaptive_map_at(
431);
432
439#define CCC_array_adaptive_map_as(map_pointer, type_name, array_index...) \
440 CCC_private_array_adaptive_map_as(map_pointer, type_name, array_index)
441
447[[nodiscard]] CCC_Tribool
449
455 CCC_Array_adaptive_map *map, void const *key
456);
457
478 void *type_output,
479 CCC_Allocator const *allocator
480);
481
494#define CCC_array_adaptive_map_swap_handle_wrap( \
495 map_pointer, type_output_pointer, allocator_pointer... \
496) \
497 &(struct { CCC_Handle private; }){ \
498 CCC_array_adaptive_map_swap_handle( \
499 (map_pointer), (type_output_pointer), allocator_pointer \
500 )} \
501 .private
502
513 void const *type,
514 CCC_Allocator const *allocator
515);
516
525#define CCC_array_adaptive_map_try_insert_wrap( \
526 map_pointer, type_pointer, allocator_pointer... \
527) \
528 &(struct { CCC_Handle private; }){ \
529 CCC_array_adaptive_map_try_insert( \
530 (map_pointer), (type_pointer), allocator_pointer \
531 )} \
532 .private
533
548#define CCC_array_adaptive_map_try_insert_with( \
549 map_pointer, key, allocator_pointer, type_compound_literal... \
550) \
551 &(struct { CCC_Handle private; }){ \
552 CCC_private_array_adaptive_map_try_insert_with( \
553 map_pointer, key, allocator_pointer, type_compound_literal \
554 )} \
555 .private
556
568 void const *type,
569 CCC_Allocator const *allocator
570);
571
581#define CCC_array_adaptive_map_insert_or_assign_wrap( \
582 map_pointer, type_pointer, allocator_pointer... \
583) \
584 &(struct { CCC_Handle private; }){ \
585 CCC_array_adaptive_map_insert_or_assign( \
586 (map_pointer), (type_pointer), allocator_pointer \
587 )} \
588 .private
589
604#define CCC_array_adaptive_map_insert_or_assign_with( \
605 map_pointer, key, allocator_pointer, type_compound_literal... \
606) \
607 &(struct { CCC_Handle private; }){ \
608 CCC_private_array_adaptive_map_insert_or_assign_with( \
609 map_pointer, key, allocator_pointer, type_compound_literal \
610 )} \
611 .private
612
624 CCC_Array_adaptive_map *map, void *type_output
625);
626
638#define CCC_array_adaptive_map_remove_key_value_wrap( \
639 map_pointer, type_output_pointer \
640) \
641 &(struct { CCC_Handle private; }){CCC_array_adaptive_map_remove_key_value( \
642 (map_pointer), (type_output_pointer) \
643 )} \
644 .private
645
663
680#define CCC_array_adaptive_map_handle_wrap(handle_pointer, key_pointer) \
681 &(struct { CCC_Array_adaptive_map_handle private; }){ \
682 CCC_array_adaptive_map_handle((handle_pointer), (key_pointer))} \
683 .private
684
690 CCC_Array_adaptive_map_handle *handle, CCC_Modifier const *modifier
691);
692
728#define CCC_array_adaptive_map_and_modify_with( \
729 handle_pointer, closure_parameter, closure_over_closure_parameter... \
730) \
731 &(struct { CCC_Array_adaptive_map_handle private; }){ \
732 CCC_private_array_adaptive_map_and_modify_with( \
733 handle_pointer, closure_parameter, closure_over_closure_parameter \
734 )} \
735 .private
736
750 CCC_Array_adaptive_map_handle const *handle,
751 void const *type,
752 CCC_Allocator const *allocator
753);
754
767#define CCC_array_adaptive_map_or_insert_with( \
768 handle_pointer, allocator_pointer, type_compound_literal... \
769) \
770 CCC_private_array_adaptive_map_or_insert_with( \
771 handle_pointer, allocator_pointer, type_compound_literal \
772 )
773
783 CCC_Array_adaptive_map_handle const *handle,
784 void const *type,
785 CCC_Allocator const *allocator
786);
787
795#define CCC_array_adaptive_map_insert_handle_with( \
796 handle_pointer, allocator_pointer, type_compound_literal... \
797) \
798 CCC_private_array_adaptive_map_insert_handle_with( \
799 handle_pointer, allocator_pointer, type_compound_literal \
800 )
801
807[[nodiscard]] CCC_Handle
809
815#define CCC_array_adaptive_map_remove_handle_wrap(handle_pointer) \
816 &(struct { CCC_Handle private; }){ \
817 CCC_array_adaptive_map_remove_handle((handle_pointer))} \
818 .private
819
823[[nodiscard]] CCC_Handle_index
825
829[[nodiscard]] CCC_Tribool
831
839);
840
852);
853
882 CCC_Array_adaptive_map *map, void const *begin_key, void const *end_key
883);
884
892#define CCC_array_adaptive_map_equal_range_wrap( \
893 map_pointer, begin_and_end_key_pointers... \
894) \
895 &(struct { CCC_Handle_range private; }){ \
896 CCC_array_adaptive_map_equal_range( \
897 map_pointer, begin_and_end_key_pointers \
898 )} \
899 .private
900
924[[nodiscard]] CCC_Handle_range_reverse
927 void const *reverse_begin_key,
928 void const *reverse_end_key
929);
930
938#define CCC_array_adaptive_map_equal_range_reverse_wrap( \
939 map_pointer, reverse_begin_and_reverse_end_key_pointers... \
940) \
941 &(struct { CCC_Handle_range_reverse private; }){ \
942 CCC_array_adaptive_map_equal_range_reverse( \
943 map_pointer, reverse_begin_and_reverse_end_key_pointers \
944 )} \
945 .private
946
951[[nodiscard]] CCC_Handle_index
953
958[[nodiscard]] CCC_Handle_index
960
968);
969
978);
979
983[[nodiscard]] CCC_Handle_index
985
990[[nodiscard]] CCC_Handle_index
992
1007 CCC_Array_adaptive_map *map, CCC_Destructor const *destructor
1008);
1009
1025 CCC_Destructor const *destructor,
1026 CCC_Allocator const *allocator
1027);
1028
1039[[nodiscard]] CCC_Count
1041
1046[[nodiscard]] CCC_Count
1048
1052[[nodiscard]] CCC_Tribool
1054
1059[[nodiscard]] CCC_Tribool
1061
1066#ifdef ARRAY_ADAPTIVE_MAP_USING_NAMESPACE_CCC
1067/* NOLINTBEGIN(readability-identifier-naming) */
1068typedef CCC_Array_adaptive_map Array_adaptive_map;
1069typedef CCC_Array_adaptive_map_handle Array_adaptive_map_handle;
1070# define array_adaptive_map_storage_for(arguments...) \
1071 CCC_array_adaptive_map_storage_for(arguments)
1072# define array_adaptive_map_default(arguments...) \
1073 CCC_array_adaptive_map_default(arguments)
1074# define array_adaptive_map_for(arguments...) \
1075 CCC_array_adaptive_map_for(arguments)
1076# define array_adaptive_map_from(arguments...) \
1077 CCC_array_adaptive_map_from(arguments)
1078# define array_adaptive_map_with_capacity(arguments...) \
1079 CCC_array_adaptive_map_with_capacity(arguments)
1080# define array_adaptive_map_with_storage(arguments...) \
1081 CCC_array_adaptive_map_with_storage(arguments)
1082# define array_adaptive_map_at(arguments...) \
1083 CCC_array_adaptive_map_at(arguments)
1084# define array_adaptive_map_as(arguments...) \
1085 CCC_array_adaptive_map_as(arguments)
1086# define array_adaptive_map_and_modify_with(arguments...) \
1087 CCC_array_adaptive_map_and_modify_with(arguments)
1088# define array_adaptive_map_or_insert_with(arguments...) \
1089 CCC_array_adaptive_map_or_insert_with(arguments)
1090# define array_adaptive_map_insert_handle_with(arguments...) \
1091 CCC_array_adaptive_map_insert_handle_with(arguments)
1092# define array_adaptive_map_try_insert_with(arguments...) \
1093 CCC_array_adaptive_map_try_insert_with(arguments)
1094# define array_adaptive_map_copy(arguments...) \
1095 CCC_array_adaptive_map_copy(arguments)
1096# define array_adaptive_map_reserve(arguments...) \
1097 CCC_array_adaptive_map_reserve(arguments)
1098# define array_adaptive_map_contains(arguments...) \
1099 CCC_array_adaptive_map_contains(arguments)
1100# define array_adaptive_map_get_key_value(arguments...) \
1101 CCC_array_adaptive_map_get_key_value(arguments)
1102# define array_adaptive_map_swap_handle_wrap(arguments...) \
1103 CCC_array_adaptive_map_swap_handle_wrap(arguments)
1104# define array_adaptive_map_try_insert_wrap(arguments...) \
1105 CCC_array_adaptive_map_try_insert_wrap(arguments)
1106# define array_adaptive_map_remove_key_value_wrap(arguments...) \
1107 CCC_array_adaptive_map_remove_key_value_wrap(arguments)
1108# define array_adaptive_map_remove_handle_wrap(arguments...) \
1109 CCC_array_adaptive_map_remove_handle_wrap(arguments)
1110# define array_adaptive_map_swap_handle(arguments...) \
1111 CCC_array_adaptive_map_swap_handle(arguments)
1112# define array_adaptive_map_try_insert(arguments...) \
1113 CCC_array_adaptive_map_try_insert(arguments)
1114# define array_adaptive_map_insert_or_assign(arguments...) \
1115 CCC_array_adaptive_map_insert_or_assign(arguments)
1116# define array_adaptive_map_insert_or_assign_wrap(arguments...) \
1117 CCC_array_adaptive_map_insert_or_assign_wrap(arguments)
1118# define array_adaptive_map_insert_or_assign_with(arguments...) \
1119 CCC_array_adaptive_map_insert_or_assign_with(arguments)
1120# define array_adaptive_map_remove_key_value(arguments...) \
1121 CCC_array_adaptive_map_remove_key_value(arguments)
1122# define array_adaptive_map_remove_handle(arguments...) \
1123 CCC_array_adaptive_map_remove_handle(arguments)
1124# define array_adaptive_map_handle_wrap(arguments...) \
1125 CCC_array_adaptive_map_handle_wrap(arguments)
1126# define array_adaptive_map_handle(arguments...) \
1127 CCC_array_adaptive_map_handle(arguments)
1128# define array_adaptive_map_and_modify(arguments...) \
1129 CCC_array_adaptive_map_and_modify(arguments)
1130# define array_adaptive_map_or_insert(arguments...) \
1131 CCC_array_adaptive_map_or_insert(arguments)
1132# define array_adaptive_map_insert_handle(arguments...) \
1133 CCC_array_adaptive_map_insert_handle(arguments)
1134# define array_adaptive_map_unwrap(arguments...) \
1135 CCC_array_adaptive_map_unwrap(arguments)
1136# define array_adaptive_map_insert_error(arguments...) \
1137 CCC_array_adaptive_map_insert_error(arguments)
1138# define array_adaptive_map_handle_status(arguments...) \
1139 CCC_array_adaptive_map_handle_status(arguments)
1140# define array_adaptive_map_occupied(arguments...) \
1141 CCC_array_adaptive_map_occupied(arguments)
1142# define array_adaptive_map_clear(arguments...) \
1143 CCC_array_adaptive_map_clear(arguments)
1144# define array_adaptive_map_clear_and_free(arguments...) \
1145 CCC_array_adaptive_map_clear_and_free(arguments)
1146# define array_adaptive_map_begin(arguments...) \
1147 CCC_array_adaptive_map_begin(arguments)
1148# define array_adaptive_map_reverse_begin(arguments...) \
1149 CCC_array_adaptive_map_reverse_begin(arguments)
1150# define array_adaptive_map_end(arguments...) \
1151 CCC_array_adaptive_map_end(arguments)
1152# define array_adaptive_map_reverse_end(arguments...) \
1153 CCC_array_adaptive_map_reverse_end(arguments)
1154# define array_adaptive_map_next(arguments...) \
1155 CCC_array_adaptive_map_next(arguments)
1156# define array_adaptive_map_reverse_next(arguments...) \
1157 CCC_array_adaptive_map_reverse_next(arguments)
1158# define array_adaptive_map_equal_range(arguments...) \
1159 CCC_array_adaptive_map_equal_range(arguments)
1160# define array_adaptive_map_equal_range_wrap(arguments...) \
1161 CCC_array_adaptive_map_equal_range_wrap(arguments)
1162# define array_adaptive_map_equal_range_reverse(arguments...) \
1163 CCC_array_adaptive_map_equal_range_reverse(arguments)
1164# define array_adaptive_map_equal_range_reverse_wrap(arguments...) \
1165 CCC_array_adaptive_map_equal_range_reverse_wrap(arguments)
1166# define array_adaptive_map_count(arguments...) \
1167 CCC_array_adaptive_map_count(arguments)
1168# define array_adaptive_map_capacity(arguments...) \
1169 CCC_array_adaptive_map_capacity(arguments)
1170# define array_adaptive_map_is_empty(arguments...) \
1171 CCC_array_adaptive_map_is_empty(arguments)
1172# define array_adaptive_map_validate(arguments...) \
1173 CCC_array_adaptive_map_validate(arguments)
1174/* NOLINTEND(readability-identifier-naming) */
1175#endif /* ARRAY_ADAPTIVE_MAP_USING_NAMESPACE_CCC */
1176
1177#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 type passed by reference to any container function that may need to allocate memory....
Definition: types.h:376
Definition: private_array_adaptive_map.h:91
size_t index
Definition: private_array_adaptive_map.h:95
struct CCC_Array_adaptive_map * map
Definition: private_array_adaptive_map.h:93
Definition: private_array_adaptive_map.h:68
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:244
The type passed by reference to any container function that may need to destroy elements....
Definition: types.h:464
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:436
The C Container Collection Fundamental Types.
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