C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_hash_map.h
Go to the documentation of this file.
1
86#ifndef CCC_FLAT_HASH_MAP_H
87#define CCC_FLAT_HASH_MAP_H
88
90#include <stddef.h>
93#include "private/private_flat_hash_map.h" /* IWYU pragma: export */
94#include "types.h" /* IWYU pragma: export */
95
106
112
140#define CCC_flat_hash_map_storage_for( \
141 user_type_compound_literal_array, optional_storage_specifier... \
142) \
143 CCC_private_flat_hash_map_storage_for( \
144 user_type_compound_literal_array, optional_storage_specifier \
145 )
146
154#define CCC_flat_hash_map_default(type_name, key_field, hasher...) \
155 CCC_private_flat_hash_map_default(type_name, key_field, hasher)
156
187#define CCC_flat_hash_map_for( \
188 type_name, key_field, hasher, capacity, map_pointer \
189) \
190 CCC_private_flat_hash_map_for( \
191 type_name, key_field, hasher, capacity, map_pointer \
192 )
193
249#define CCC_flat_hash_map_from( \
250 key_field, hasher, allocator, optional_capacity, array_compound_literal... \
251) \
252 CCC_private_flat_hash_map_from( \
253 key_field, \
254 hasher, \
255 allocator, \
256 optional_capacity, \
257 array_compound_literal \
258 )
259
303#define CCC_flat_hash_map_with_capacity( \
304 type_name, key_field, hasher, allocator, capacity \
305) \
306 CCC_private_flat_hash_map_with_capacity( \
307 type_name, key_field, hasher, allocator, capacity \
308 )
309
344#define CCC_flat_hash_map_with_storage( \
345 key_field, hasher, compound_literal, optional_storage_specifier... \
346) \
347 CCC_private_flat_hash_map_with_storage( \
348 key_field, hasher, compound_literal, optional_storage_specifier \
349 )
350
362#define CCC_flat_hash_map_with_allocator_storage( \
363 key_field, hasher, allocator, compound_literal \
364) \
365 CCC_private_flat_hash_map_with_allocator_storage( \
366 key_field, hasher, allocator, compound_literal \
367 )
368
436 CCC_Flat_hash_map *destination,
437 CCC_Flat_hash_map const *source,
438 CCC_Allocator const *allocator
439);
440
452 CCC_Flat_hash_map *map, size_t to_add, CCC_Allocator const *allocator
453);
454
466[[nodiscard]] CCC_Tribool
468
473[[nodiscard]] void *
475
504 CCC_Flat_hash_map *map, void const *key, CCC_Allocator const *allocator
505);
506
528#define CCC_flat_hash_map_entry_wrap( \
529 map_pointer, key_pointer, allocator_pointer... \
530) \
531 &(struct { CCC_Flat_hash_map_entry private; }){ \
532 CCC_flat_hash_map_entry(map_pointer, key_pointer, allocator_pointer)} \
533 .private
534
540 CCC_Flat_hash_map_entry *entry, CCC_Modifier const *modifier
541);
542
578#define CCC_flat_hash_map_and_modify_with( \
579 map_entry_pointer, closure_parameter, closure_over_closure_parameter... \
580) \
581 &( \
582 struct { CCC_Flat_hash_map_entry private; } \
583 ){CCC_private_flat_hash_map_and_modify_with( \
584 map_entry_pointer, closure_parameter, closure_over_closure_parameter \
585 )} \
586 .private
587
597[[nodiscard]] void *CCC_flat_hash_map_or_insert(
598 CCC_Flat_hash_map_entry const *entry, void const *type
599);
600
612#define CCC_flat_hash_map_or_insert_with( \
613 map_entry_pointer, type_compound_literal... \
614) \
615 CCC_private_flat_hash_map_or_insert_with( \
616 map_entry_pointer, type_compound_literal \
617 )
618
631 CCC_Flat_hash_map_entry const *entry, void const *type
632);
633
640#define CCC_flat_hash_map_insert_entry_with( \
641 map_entry_pointer, type_compound_literal... \
642) \
643 CCC_private_flat_hash_map_insert_entry_with( \
644 map_entry_pointer, type_compound_literal \
645 )
646
658[[nodiscard]]
660 CCC_Flat_hash_map *map, void *type_output, CCC_Allocator const *allocator
661);
662
677#define CCC_flat_hash_map_swap_entry_wrap( \
678 map_pointer, type_pointer, allocator_pointer \
679) \
680 &(struct { CCC_Entry private; }){ \
681 CCC_flat_hash_map_swap_entry( \
682 map_pointer, type_pointer, allocator_pointer \
683 )} \
684 .private
685
690[[nodiscard]] CCC_Entry
692
698#define CCC_flat_hash_map_remove_entry_wrap(map_entry_pointer) \
699 &(struct { CCC_Entry private; }){ \
700 CCC_flat_hash_map_remove_entry(map_entry_pointer)} \
701 .private
702
713[[nodiscard]]
715 CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator
716);
717
730#define CCC_flat_hash_map_try_insert_wrap( \
731 map_pointer, type_pointer, allocator_pointer... \
732) \
733 &(struct { CCC_Entry private; }){ \
734 CCC_flat_hash_map_try_insert( \
735 map_pointer, type_pointer, allocator_pointer \
736 )} \
737 .private
738
757#define CCC_flat_hash_map_try_insert_with( \
758 map_pointer, key, allocator_pointer, type_compound_literal... \
759) \
760 &(struct { CCC_Entry private; }){ \
761 CCC_private_flat_hash_map_try_insert_with( \
762 map_pointer, key, allocator_pointer, type_compound_literal \
763 )} \
764 .private
765
775[[nodiscard]]
777 CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator
778);
779
790#define CCC_flat_hash_map_insert_or_assign_wrap( \
791 map_pointer, type_pointer, allocator_pointer... \
792) \
793 &(struct { CCC_Entry private; }){ \
794 CCC_flat_hash_map_insert_or_assign( \
795 map_pointer, type_pointer, allocator_pointer \
796 )} \
797 .private
798
813#define CCC_flat_hash_map_insert_or_assign_with( \
814 map_pointer, key, allocator_pointer, type_compound_literal... \
815) \
816 &(struct { CCC_Entry private; }){ \
817 CCC_private_flat_hash_map_insert_or_assign_with( \
818 map_pointer, key, allocator_pointer, type_compound_literal \
819 )} \
820 .private
821
834[[nodiscard]] CCC_Entry
836
850#define CCC_flat_hash_map_remove_key_value_wrap( \
851 map_pointer, type_output_pointer \
852) \
853 &(struct { CCC_Entry private; }){ \
854 CCC_flat_hash_map_remove_key_value(map_pointer, type_output_pointer)} \
855 .private
856
860[[nodiscard]] void *
862
866[[nodiscard]] CCC_Tribool
868
884[[nodiscard]] CCC_Tribool
886
896[[nodiscard]] CCC_Entry_status
898
910 CCC_Flat_hash_map *map, CCC_Destructor const *destructor
911);
912
922 CCC_Destructor const *destructor,
923 CCC_Allocator const *allocator
924);
925
941
948[[nodiscard]] void *
949CCC_flat_hash_map_next(CCC_Flat_hash_map const *map, void const *type_iterator);
950
955[[nodiscard]] void *CCC_flat_hash_map_end(CCC_Flat_hash_map const *map);
956
966[[nodiscard]] CCC_Tribool
968
973
977[[nodiscard]] CCC_Count
979
984[[nodiscard]] CCC_Tribool
986
991#ifdef FLAT_HASH_MAP_USING_NAMESPACE_CCC
992/* NOLINTBEGIN(readability-identifier-naming) */
993typedef CCC_Flat_hash_map Flat_hash_map;
994typedef CCC_Flat_hash_map_entry Flat_hash_map_entry;
995# define flat_hash_map_storage_for(arguments...) \
996 CCC_flat_hash_map_storage_for(arguments)
997# define flat_hash_map_reserve(arguments...) \
998 CCC_flat_hash_map_reserve(arguments)
999# define flat_hash_map_default(arguments...) \
1000 CCC_flat_hash_map_default(arguments)
1001# define flat_hash_map_for(arguments...) CCC_flat_hash_map_for(arguments)
1002# define flat_hash_map_from(arguments...) CCC_flat_hash_map_from(arguments)
1003# define flat_hash_map_with_capacity(arguments...) \
1004 CCC_flat_hash_map_with_capacity(arguments)
1005# define flat_hash_map_with_storage(arguments...) \
1006 CCC_flat_hash_map_with_storage(arguments)
1007# define flat_hash_map_with_allocator_storage(arguments...) \
1008 CCC_flat_hash_map_with_allocator_storage(arguments)
1009# define flat_hash_map_copy(arguments...) CCC_flat_hash_map_copy(arguments)
1010# define flat_hash_map_and_modify_with(arguments...) \
1011 CCC_flat_hash_map_and_modify_with(arguments)
1012# define flat_hash_map_or_insert_with(arguments...) \
1013 CCC_flat_hash_map_or_insert_with(arguments)
1014# define flat_hash_map_insert_entry_with(arguments...) \
1015 CCC_flat_hash_map_insert_entry_with(arguments)
1016# define flat_hash_map_try_insert_with(arguments...) \
1017 CCC_flat_hash_map_try_insert_with(arguments)
1018# define flat_hash_map_insert_or_assign_with(arguments...) \
1019 CCC_flat_hash_map_insert_or_assign_with(arguments)
1020# define flat_hash_map_contains(arguments...) \
1021 CCC_flat_hash_map_contains(arguments)
1022# define flat_hash_map_get_key_value(arguments...) \
1023 CCC_flat_hash_map_get_key_value(arguments)
1024# define flat_hash_map_remove_key_value_wrap(arguments...) \
1025 CCC_flat_hash_map_remove_key_value_wrap(arguments)
1026# define flat_hash_map_swap_entry_wrap(arguments...) \
1027 CCC_flat_hash_map_swap_entry_wrap(arguments)
1028# define flat_hash_map_try_insert_wrap(arguments...) \
1029 CCC_flat_hash_map_try_insert_wrap(arguments)
1030# define flat_hash_map_insert_or_assign_wrap(arguments...) \
1031 CCC_flat_hash_map_insert_or_assign_wrap(arguments)
1032# define flat_hash_map_remove_entry_wrap(arguments...) \
1033 CCC_flat_hash_map_remove_entry_wrap(arguments)
1034# define flat_hash_map_remove_key_value(arguments...) \
1035 CCC_flat_hash_map_remove_key_value(arguments)
1036# define flat_hash_map_swap_entry(arguments...) \
1037 CCC_flat_hash_map_swap_entry(arguments)
1038# define flat_hash_map_try_insert(arguments...) \
1039 CCC_flat_hash_map_try_insert(arguments)
1040# define flat_hash_map_insert_or_assign(arguments...) \
1041 CCC_flat_hash_map_insert_or_assign(arguments)
1042# define flat_hash_map_remove_entry(arguments...) \
1043 CCC_flat_hash_map_remove_entry(arguments)
1044# define flat_hash_map_entry_wrap(arguments...) \
1045 CCC_flat_hash_map_entry_wrap(arguments)
1046# define flat_hash_map_entry(arguments...) CCC_flat_hash_map_entry(arguments)
1047# define flat_hash_map_and_modify(arguments...) \
1048 CCC_flat_hash_map_and_modify(arguments)
1049# define flat_hash_map_or_insert(arguments...) \
1050 CCC_flat_hash_map_or_insert(arguments)
1051# define flat_hash_map_insert_entry(arguments...) \
1052 CCC_flat_hash_map_insert_entry(arguments)
1053# define flat_hash_map_unwrap(arguments...) \
1054 CCC_flat_hash_map_unwrap(arguments)
1055# define flat_hash_map_occupied(arguments...) \
1056 CCC_flat_hash_map_occupied(arguments)
1057# define flat_hash_map_insert_error(arguments...) \
1058 CCC_flat_hash_map_insert_error(arguments)
1059# define flat_hash_map_begin(arguments...) CCC_flat_hash_map_begin(arguments)
1060# define flat_hash_map_next(arguments...) CCC_flat_hash_map_next(arguments)
1061# define flat_hash_map_end(arguments...) CCC_flat_hash_map_end(arguments)
1062# define flat_hash_map_is_empty(arguments...) \
1063 CCC_flat_hash_map_is_empty(arguments)
1064# define flat_hash_map_count(arguments...) CCC_flat_hash_map_count(arguments)
1065# define flat_hash_map_clear(arguments...) CCC_flat_hash_map_clear(arguments)
1066# define flat_hash_map_clear_and_free(arguments...) \
1067 CCC_flat_hash_map_clear_and_free(arguments)
1068# define flat_hash_map_capacity(arguments...) \
1069 CCC_flat_hash_map_capacity(arguments)
1070# define flat_hash_map_validate(arguments...) \
1071 CCC_flat_hash_map_validate(arguments)
1072/* NOLINTEND(readability-identifier-naming) */
1073#endif /* FLAT_HASH_MAP_USING_NAMESPACE_CCC */
1074
1075#endif /* CCC_FLAT_HASH_MAP_H */
CCC_Result CCC_flat_hash_map_clear(CCC_Flat_hash_map *map, CCC_Destructor const *destructor)
Frees all slots in the table for use without affecting capacity.
CCC_Entry CCC_flat_hash_map_remove_entry(CCC_Flat_hash_map_entry const *entry)
Remove the entry from the table if Occupied.
CCC_Entry CCC_flat_hash_map_try_insert(CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator)
Attempts to insert the key value wrapping key_val_handle.
void * CCC_flat_hash_map_get_key_value(CCC_Flat_hash_map const *map, void const *key)
Returns a reference into the table at entry key.
CCC_Result CCC_flat_hash_map_clear_and_free(CCC_Flat_hash_map *map, CCC_Destructor const *destructor, CCC_Allocator const *allocator)
Frees all slots in the table and frees the underlying buffer.
CCC_Entry_status CCC_flat_hash_map_entry_status(CCC_Flat_hash_map_entry const *entry)
Obtain the entry status from a container entry.
void * CCC_flat_hash_map_begin(CCC_Flat_hash_map const *map)
Obtains a pointer to the first element in the table.
CCC_Entry CCC_flat_hash_map_remove_key_value(CCC_Flat_hash_map *map, void *type_output)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
void * CCC_flat_hash_map_end(CCC_Flat_hash_map const *map)
Check the current iterator against the end for loop termination.
CCC_Entry CCC_flat_hash_map_insert_or_assign(CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator)
Invariantly inserts or overwrites a user struct into the table.
void * CCC_flat_hash_map_next(CCC_Flat_hash_map const *map, void const *type_iterator)
Advances the iterator to the next occupied table slot.
void * CCC_flat_hash_map_or_insert(CCC_Flat_hash_map_entry const *entry, void const *type)
Inserts the struct with handle elem if the entry is Vacant.
CCC_Tribool CCC_flat_hash_map_is_empty(CCC_Flat_hash_map const *map)
Returns the size status of the table.
CCC_Tribool CCC_flat_hash_map_validate(CCC_Flat_hash_map const *map)
Validation of invariants for the hash table.
CCC_Result CCC_flat_hash_map_copy(CCC_Flat_hash_map *destination, CCC_Flat_hash_map const *source, CCC_Allocator const *allocator)
Copy the map at source to destination.
CCC_Tribool CCC_flat_hash_map_contains(CCC_Flat_hash_map const *map, void const *key)
Searches the table for the presence of key.
CCC_Flat_hash_map_entry * CCC_flat_hash_map_and_modify(CCC_Flat_hash_map_entry *entry, CCC_Modifier const *modifier)
Modifies the provided entry if it is Occupied.
void * CCC_flat_hash_map_insert_entry(CCC_Flat_hash_map_entry const *entry, void const *type)
Inserts the provided entry invariantly.
void * CCC_flat_hash_map_unwrap(CCC_Flat_hash_map_entry const *entry)
Unwraps the provided entry to obtain a view into the table element.
CCC_Result CCC_flat_hash_map_reserve(CCC_Flat_hash_map *map, size_t to_add, CCC_Allocator const *allocator)
Reserve space required to add a specified number of elements to the map. If the current capacity is s...
CCC_Flat_hash_map_entry CCC_flat_hash_map_entry(CCC_Flat_hash_map *map, void const *key, CCC_Allocator const *allocator)
Obtains an entry for the provided key in the table for future use.
CCC_Tribool CCC_flat_hash_map_occupied(CCC_Flat_hash_map_entry const *entry)
Returns the Vacant or Occupied status of the entry.
CCC_Count CCC_flat_hash_map_capacity(CCC_Flat_hash_map const *map)
Return the full capacity of the backing storage.
CCC_Entry CCC_flat_hash_map_swap_entry(CCC_Flat_hash_map *map, void *type_output, CCC_Allocator const *allocator)
Invariantly inserts the key value wrapping out_handle.
CCC_Count CCC_flat_hash_map_count(CCC_Flat_hash_map const *map)
Returns the count of table occupied slots.
CCC_Tribool CCC_flat_hash_map_insert_error(CCC_Flat_hash_map_entry const *entry)
Provides the status of the entry should an insertion follow.
The Private Flat Hash Map Types and Interface.
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:384
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
An Occupied or Vacant position in a searchable container.
Definition: types.h:135
Definition: private_flat_hash_map.h:178
struct CCC_Flat_hash_map * map
Definition: private_flat_hash_map.h:180
Definition: private_flat_hash_map.h:152
The type passed by reference to any container function that may need to modify elements....
Definition: types.h:444
The C Container Collection Fundamental Types.
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