C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_hash_map.h
Go to the documentation of this file.
1
93#ifndef CCC_FLAT_HASH_MAP_H
94#define CCC_FLAT_HASH_MAP_H
95
97#include <stddef.h>
101#include "types.h"
102
113
119
174#define CCC_flat_hash_map_storage_for( \
175 user_type_compound_literal_array, optional_storage_specifier... \
176) \
177 CCC_private_flat_hash_map_storage_for( \
178 user_type_compound_literal_array, optional_storage_specifier \
179 )
180
188#define CCC_flat_hash_map_default(type_name, key_field, hasher...) \
189 CCC_private_flat_hash_map_default(type_name, key_field, hasher)
190
221#define CCC_flat_hash_map_for( \
222 type_name, key_field, hasher, capacity, map_pointer \
223) \
224 CCC_private_flat_hash_map_for( \
225 type_name, key_field, hasher, capacity, map_pointer \
226 )
227
283#define CCC_flat_hash_map_from( \
284 key_field, hasher, allocator, optional_capacity, array_compound_literal... \
285) \
286 CCC_private_flat_hash_map_from( \
287 key_field, \
288 hasher, \
289 allocator, \
290 optional_capacity, \
291 array_compound_literal \
292 )
293
337#define CCC_flat_hash_map_with_capacity( \
338 type_name, key_field, hasher, allocator, capacity \
339) \
340 CCC_private_flat_hash_map_with_capacity( \
341 type_name, key_field, hasher, allocator, capacity \
342 )
343
378#define CCC_flat_hash_map_with_storage( \
379 key_field, hasher, compound_literal, optional_storage_specifier... \
380) \
381 CCC_private_flat_hash_map_with_storage( \
382 key_field, hasher, compound_literal, optional_storage_specifier \
383 )
384
452 CCC_Flat_hash_map *destination,
453 CCC_Flat_hash_map const *source,
454 CCC_Allocator const *allocator
455);
456
468 CCC_Flat_hash_map *map, size_t to_add, CCC_Allocator const *allocator
469);
470
482[[nodiscard]] CCC_Tribool
484
489[[nodiscard]] void *
491
520 CCC_Flat_hash_map *map, void const *key, CCC_Allocator const *allocator
521);
522
544#define CCC_flat_hash_map_entry_wrap( \
545 map_pointer, key_pointer, allocator_pointer... \
546) \
547 &(struct { CCC_Flat_hash_map_entry private; }){ \
548 CCC_flat_hash_map_entry(map_pointer, key_pointer, allocator_pointer)} \
549 .private
550
556 CCC_Flat_hash_map_entry *entry, CCC_Modifier const *modifier
557);
558
594#define CCC_flat_hash_map_and_modify_with( \
595 map_entry_pointer, closure_parameter, closure_over_closure_parameter... \
596) \
597 &( \
598 struct { CCC_Flat_hash_map_entry private; } \
599 ){CCC_private_flat_hash_map_and_modify_with( \
600 map_entry_pointer, closure_parameter, closure_over_closure_parameter \
601 )} \
602 .private
603
613[[nodiscard]] void *CCC_flat_hash_map_or_insert(
614 CCC_Flat_hash_map_entry const *entry, void const *type
615);
616
628#define CCC_flat_hash_map_or_insert_with( \
629 map_entry_pointer, type_compound_literal... \
630) \
631 CCC_private_flat_hash_map_or_insert_with( \
632 map_entry_pointer, type_compound_literal \
633 )
634
647 CCC_Flat_hash_map_entry const *entry, void const *type
648);
649
656#define CCC_flat_hash_map_insert_entry_with( \
657 map_entry_pointer, type_compound_literal... \
658) \
659 CCC_private_flat_hash_map_insert_entry_with( \
660 map_entry_pointer, type_compound_literal \
661 )
662
674[[nodiscard]]
676 CCC_Flat_hash_map *map, void *type_output, CCC_Allocator const *allocator
677);
678
693#define CCC_flat_hash_map_swap_entry_wrap( \
694 map_pointer, type_pointer, allocator_pointer \
695) \
696 &(struct { CCC_Entry private; }){ \
697 CCC_flat_hash_map_swap_entry( \
698 map_pointer, type_pointer, allocator_pointer \
699 )} \
700 .private
701
706[[nodiscard]] CCC_Entry
708
714#define CCC_flat_hash_map_remove_entry_wrap(map_entry_pointer) \
715 &(struct { CCC_Entry private; }){ \
716 CCC_flat_hash_map_remove_entry(map_entry_pointer)} \
717 .private
718
729[[nodiscard]]
731 CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator
732);
733
746#define CCC_flat_hash_map_try_insert_wrap( \
747 map_pointer, type_pointer, allocator_pointer... \
748) \
749 &(struct { CCC_Entry private; }){ \
750 CCC_flat_hash_map_try_insert( \
751 map_pointer, type_pointer, allocator_pointer \
752 )} \
753 .private
754
773#define CCC_flat_hash_map_try_insert_with( \
774 map_pointer, key, allocator_pointer, type_compound_literal... \
775) \
776 &(struct { CCC_Entry private; }){ \
777 CCC_private_flat_hash_map_try_insert_with( \
778 map_pointer, key, allocator_pointer, type_compound_literal \
779 )} \
780 .private
781
791[[nodiscard]]
793 CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator
794);
795
806#define CCC_flat_hash_map_insert_or_assign_wrap( \
807 map_pointer, type_pointer, allocator_pointer... \
808) \
809 &(struct { CCC_Entry private; }){ \
810 CCC_flat_hash_map_insert_or_assign( \
811 map_pointer, type_pointer, allocator_pointer \
812 )} \
813 .private
814
829#define CCC_flat_hash_map_insert_or_assign_with( \
830 map_pointer, key, allocator_pointer, type_compound_literal... \
831) \
832 &(struct { CCC_Entry private; }){ \
833 CCC_private_flat_hash_map_insert_or_assign_with( \
834 map_pointer, key, allocator_pointer, type_compound_literal \
835 )} \
836 .private
837
850[[nodiscard]] CCC_Entry
852
866#define CCC_flat_hash_map_remove_key_value_wrap( \
867 map_pointer, type_output_pointer \
868) \
869 &(struct { CCC_Entry private; }){ \
870 CCC_flat_hash_map_remove_key_value(map_pointer, type_output_pointer)} \
871 .private
872
876[[nodiscard]] void *
878
882[[nodiscard]] CCC_Tribool
884
900[[nodiscard]] CCC_Tribool
902
912[[nodiscard]] CCC_Entry_status
914
926 CCC_Flat_hash_map *map, CCC_Destructor const *destructor
927);
928
938 CCC_Destructor const *destructor,
939 CCC_Allocator const *allocator
940);
941
957
964[[nodiscard]] void *
965CCC_flat_hash_map_next(CCC_Flat_hash_map const *map, void const *type_iterator);
966
971[[nodiscard]] void *CCC_flat_hash_map_end(CCC_Flat_hash_map const *map);
972
982[[nodiscard]] CCC_Tribool
984
989
993[[nodiscard]] CCC_Count
995
1000[[nodiscard]] CCC_Tribool
1002
1007#ifdef FLAT_HASH_MAP_USING_NAMESPACE_CCC
1008/* NOLINTBEGIN(readability-identifier-naming) */
1009typedef CCC_Flat_hash_map Flat_hash_map;
1010typedef CCC_Flat_hash_map_entry Flat_hash_map_entry;
1011# define flat_hash_map_storage_for(arguments...) \
1012 CCC_flat_hash_map_storage_for(arguments)
1013# define flat_hash_map_reserve(arguments...) \
1014 CCC_flat_hash_map_reserve(arguments)
1015# define flat_hash_map_default(arguments...) \
1016 CCC_flat_hash_map_default(arguments)
1017# define flat_hash_map_for(arguments...) CCC_flat_hash_map_for(arguments)
1018# define flat_hash_map_from(arguments...) CCC_flat_hash_map_from(arguments)
1019# define flat_hash_map_with_capacity(arguments...) \
1020 CCC_flat_hash_map_with_capacity(arguments)
1021# define flat_hash_map_with_storage(arguments...) \
1022 CCC_flat_hash_map_with_storage(arguments)
1023# define flat_hash_map_copy(arguments...) CCC_flat_hash_map_copy(arguments)
1024# define flat_hash_map_and_modify_with(arguments...) \
1025 CCC_flat_hash_map_and_modify_with(arguments)
1026# define flat_hash_map_or_insert_with(arguments...) \
1027 CCC_flat_hash_map_or_insert_with(arguments)
1028# define flat_hash_map_insert_entry_with(arguments...) \
1029 CCC_flat_hash_map_insert_entry_with(arguments)
1030# define flat_hash_map_try_insert_with(arguments...) \
1031 CCC_flat_hash_map_try_insert_with(arguments)
1032# define flat_hash_map_insert_or_assign_with(arguments...) \
1033 CCC_flat_hash_map_insert_or_assign_with(arguments)
1034# define flat_hash_map_contains(arguments...) \
1035 CCC_flat_hash_map_contains(arguments)
1036# define flat_hash_map_get_key_value(arguments...) \
1037 CCC_flat_hash_map_get_key_value(arguments)
1038# define flat_hash_map_remove_key_value_wrap(arguments...) \
1039 CCC_flat_hash_map_remove_key_value_wrap(arguments)
1040# define flat_hash_map_swap_entry_wrap(arguments...) \
1041 CCC_flat_hash_map_swap_entry_wrap(arguments)
1042# define flat_hash_map_try_insert_wrap(arguments...) \
1043 CCC_flat_hash_map_try_insert_wrap(arguments)
1044# define flat_hash_map_insert_or_assign_wrap(arguments...) \
1045 CCC_flat_hash_map_insert_or_assign_wrap(arguments)
1046# define flat_hash_map_remove_entry_wrap(arguments...) \
1047 CCC_flat_hash_map_remove_entry_wrap(arguments)
1048# define flat_hash_map_remove_key_value(arguments...) \
1049 CCC_flat_hash_map_remove_key_value(arguments)
1050# define flat_hash_map_swap_entry(arguments...) \
1051 CCC_flat_hash_map_swap_entry(arguments)
1052# define flat_hash_map_try_insert(arguments...) \
1053 CCC_flat_hash_map_try_insert(arguments)
1054# define flat_hash_map_insert_or_assign(arguments...) \
1055 CCC_flat_hash_map_insert_or_assign(arguments)
1056# define flat_hash_map_remove_entry(arguments...) \
1057 CCC_flat_hash_map_remove_entry(arguments)
1058# define flat_hash_map_entry_wrap(arguments...) \
1059 CCC_flat_hash_map_entry_wrap(arguments)
1060# define flat_hash_map_entry(arguments...) CCC_flat_hash_map_entry(arguments)
1061# define flat_hash_map_and_modify(arguments...) \
1062 CCC_flat_hash_map_and_modify(arguments)
1063# define flat_hash_map_or_insert(arguments...) \
1064 CCC_flat_hash_map_or_insert(arguments)
1065# define flat_hash_map_insert_entry(arguments...) \
1066 CCC_flat_hash_map_insert_entry(arguments)
1067# define flat_hash_map_unwrap(arguments...) \
1068 CCC_flat_hash_map_unwrap(arguments)
1069# define flat_hash_map_occupied(arguments...) \
1070 CCC_flat_hash_map_occupied(arguments)
1071# define flat_hash_map_insert_error(arguments...) \
1072 CCC_flat_hash_map_insert_error(arguments)
1073# define flat_hash_map_begin(arguments...) CCC_flat_hash_map_begin(arguments)
1074# define flat_hash_map_next(arguments...) CCC_flat_hash_map_next(arguments)
1075# define flat_hash_map_end(arguments...) CCC_flat_hash_map_end(arguments)
1076# define flat_hash_map_is_empty(arguments...) \
1077 CCC_flat_hash_map_is_empty(arguments)
1078# define flat_hash_map_count(arguments...) CCC_flat_hash_map_count(arguments)
1079# define flat_hash_map_clear(arguments...) CCC_flat_hash_map_clear(arguments)
1080# define flat_hash_map_clear_and_free(arguments...) \
1081 CCC_flat_hash_map_clear_and_free(arguments)
1082# define flat_hash_map_capacity(arguments...) \
1083 CCC_flat_hash_map_capacity(arguments)
1084# define flat_hash_map_validate(arguments...) \
1085 CCC_flat_hash_map_validate(arguments)
1086/* NOLINTEND(readability-identifier-naming) */
1087#endif /* FLAT_HASH_MAP_USING_NAMESPACE_CCC */
1088
1089#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.
Private Flat Hash Map Interface.
The type passed by reference to any container function that may need to allocate memory....
Definition: types.h:369
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:457
An Occupied or Vacant position in a searchable container.
Definition: types.h:135
Definition: private_flat_hash_map.h:162
struct CCC_Flat_hash_map * map
Definition: private_flat_hash_map.h:164
Definition: private_flat_hash_map.h:141
The type passed by reference to any container function that may need to modify elements....
Definition: types.h:429
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