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
177#define CCC_flat_hash_map_storage_for( \
178 user_type_compound_literal_array, optional_storage_specifier... \
179) \
180 CCC_private_flat_hash_map_storage_for( \
181 user_type_compound_literal_array, optional_storage_specifier \
182 )
183
191#define CCC_flat_hash_map_default(type_name, key_field, hasher...) \
192 CCC_private_flat_hash_map_default(type_name, key_field, hasher)
193
224#define CCC_flat_hash_map_for( \
225 type_name, key_field, hasher, capacity, map_pointer \
226) \
227 CCC_private_flat_hash_map_for( \
228 type_name, key_field, hasher, capacity, map_pointer \
229 )
230
286#define CCC_flat_hash_map_from( \
287 key_field, hasher, allocator, optional_capacity, array_compound_literal... \
288) \
289 CCC_private_flat_hash_map_from( \
290 key_field, \
291 hasher, \
292 allocator, \
293 optional_capacity, \
294 array_compound_literal \
295 )
296
340#define CCC_flat_hash_map_with_capacity( \
341 type_name, key_field, hasher, allocator, capacity \
342) \
343 CCC_private_flat_hash_map_with_capacity( \
344 type_name, key_field, hasher, allocator, capacity \
345 )
346
381#define CCC_flat_hash_map_with_storage( \
382 key_field, hasher, compound_literal, optional_storage_specifier... \
383) \
384 CCC_private_flat_hash_map_with_storage( \
385 key_field, hasher, compound_literal, optional_storage_specifier \
386 )
387
455 CCC_Flat_hash_map *destination,
456 CCC_Flat_hash_map const *source,
457 CCC_Allocator const *allocator
458);
459
471 CCC_Flat_hash_map *map, size_t to_add, CCC_Allocator const *allocator
472);
473
485[[nodiscard]] CCC_Tribool
487
492[[nodiscard]] void *
494
523 CCC_Flat_hash_map *map, void const *key, CCC_Allocator const *allocator
524);
525
547#define CCC_flat_hash_map_entry_wrap( \
548 map_pointer, key_pointer, allocator_pointer... \
549) \
550 &(struct { CCC_Flat_hash_map_entry private; }){ \
551 CCC_flat_hash_map_entry(map_pointer, key_pointer, allocator_pointer)} \
552 .private
553
559 CCC_Flat_hash_map_entry *entry, CCC_Modifier const *modifier
560);
561
597#define CCC_flat_hash_map_and_modify_with( \
598 map_entry_pointer, closure_parameter, closure_over_closure_parameter... \
599) \
600 &( \
601 struct { CCC_Flat_hash_map_entry private; } \
602 ){CCC_private_flat_hash_map_and_modify_with( \
603 map_entry_pointer, closure_parameter, closure_over_closure_parameter \
604 )} \
605 .private
606
616[[nodiscard]] void *CCC_flat_hash_map_or_insert(
617 CCC_Flat_hash_map_entry const *entry, void const *type
618);
619
631#define CCC_flat_hash_map_or_insert_with( \
632 map_entry_pointer, type_compound_literal... \
633) \
634 CCC_private_flat_hash_map_or_insert_with( \
635 map_entry_pointer, type_compound_literal \
636 )
637
650 CCC_Flat_hash_map_entry const *entry, void const *type
651);
652
659#define CCC_flat_hash_map_insert_entry_with( \
660 map_entry_pointer, type_compound_literal... \
661) \
662 CCC_private_flat_hash_map_insert_entry_with( \
663 map_entry_pointer, type_compound_literal \
664 )
665
677[[nodiscard]]
679 CCC_Flat_hash_map *map, void *type_output, CCC_Allocator const *allocator
680);
681
696#define CCC_flat_hash_map_swap_entry_wrap( \
697 map_pointer, type_pointer, allocator_pointer \
698) \
699 &(struct { CCC_Entry private; }){ \
700 CCC_flat_hash_map_swap_entry( \
701 map_pointer, type_pointer, allocator_pointer \
702 )} \
703 .private
704
709[[nodiscard]] CCC_Entry
711
717#define CCC_flat_hash_map_remove_entry_wrap(map_entry_pointer) \
718 &(struct { CCC_Entry private; }){ \
719 CCC_flat_hash_map_remove_entry(map_entry_pointer)} \
720 .private
721
732[[nodiscard]]
734 CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator
735);
736
749#define CCC_flat_hash_map_try_insert_wrap( \
750 map_pointer, type_pointer, allocator_pointer... \
751) \
752 &(struct { CCC_Entry private; }){ \
753 CCC_flat_hash_map_try_insert( \
754 map_pointer, type_pointer, allocator_pointer \
755 )} \
756 .private
757
776#define CCC_flat_hash_map_try_insert_with( \
777 map_pointer, key, allocator_pointer, type_compound_literal... \
778) \
779 &(struct { CCC_Entry private; }){ \
780 CCC_private_flat_hash_map_try_insert_with( \
781 map_pointer, key, allocator_pointer, type_compound_literal \
782 )} \
783 .private
784
794[[nodiscard]]
796 CCC_Flat_hash_map *map, void const *type, CCC_Allocator const *allocator
797);
798
809#define CCC_flat_hash_map_insert_or_assign_wrap( \
810 map_pointer, type_pointer, allocator_pointer... \
811) \
812 &(struct { CCC_Entry private; }){ \
813 CCC_flat_hash_map_insert_or_assign( \
814 map_pointer, type_pointer, allocator_pointer \
815 )} \
816 .private
817
832#define CCC_flat_hash_map_insert_or_assign_with( \
833 map_pointer, key, allocator_pointer, type_compound_literal... \
834) \
835 &(struct { CCC_Entry private; }){ \
836 CCC_private_flat_hash_map_insert_or_assign_with( \
837 map_pointer, key, allocator_pointer, type_compound_literal \
838 )} \
839 .private
840
853[[nodiscard]] CCC_Entry
855
869#define CCC_flat_hash_map_remove_key_value_wrap( \
870 map_pointer, type_output_pointer \
871) \
872 &(struct { CCC_Entry private; }){ \
873 CCC_flat_hash_map_remove_key_value(map_pointer, type_output_pointer)} \
874 .private
875
879[[nodiscard]] void *
881
885[[nodiscard]] CCC_Tribool
887
903[[nodiscard]] CCC_Tribool
905
915[[nodiscard]] CCC_Entry_status
917
929 CCC_Flat_hash_map *map, CCC_Destructor const *destructor
930);
931
941 CCC_Destructor const *destructor,
942 CCC_Allocator const *allocator
943);
944
960
967[[nodiscard]] void *
968CCC_flat_hash_map_next(CCC_Flat_hash_map const *map, void const *type_iterator);
969
974[[nodiscard]] void *CCC_flat_hash_map_end(CCC_Flat_hash_map const *map);
975
985[[nodiscard]] CCC_Tribool
987
992
996[[nodiscard]] CCC_Count
998
1003[[nodiscard]] CCC_Tribool
1005
1010#ifdef FLAT_HASH_MAP_USING_NAMESPACE_CCC
1011/* NOLINTBEGIN(readability-identifier-naming) */
1012typedef CCC_Flat_hash_map Flat_hash_map;
1013typedef CCC_Flat_hash_map_entry Flat_hash_map_entry;
1014# define flat_hash_map_storage_for(arguments...) \
1015 CCC_flat_hash_map_storage_for(arguments)
1016# define flat_hash_map_reserve(arguments...) \
1017 CCC_flat_hash_map_reserve(arguments)
1018# define flat_hash_map_default(arguments...) \
1019 CCC_flat_hash_map_default(arguments)
1020# define flat_hash_map_for(arguments...) CCC_flat_hash_map_for(arguments)
1021# define flat_hash_map_from(arguments...) CCC_flat_hash_map_from(arguments)
1022# define flat_hash_map_with_capacity(arguments...) \
1023 CCC_flat_hash_map_with_capacity(arguments)
1024# define flat_hash_map_with_storage(arguments...) \
1025 CCC_flat_hash_map_with_storage(arguments)
1026# define flat_hash_map_copy(arguments...) CCC_flat_hash_map_copy(arguments)
1027# define flat_hash_map_and_modify_with(arguments...) \
1028 CCC_flat_hash_map_and_modify_with(arguments)
1029# define flat_hash_map_or_insert_with(arguments...) \
1030 CCC_flat_hash_map_or_insert_with(arguments)
1031# define flat_hash_map_insert_entry_with(arguments...) \
1032 CCC_flat_hash_map_insert_entry_with(arguments)
1033# define flat_hash_map_try_insert_with(arguments...) \
1034 CCC_flat_hash_map_try_insert_with(arguments)
1035# define flat_hash_map_insert_or_assign_with(arguments...) \
1036 CCC_flat_hash_map_insert_or_assign_with(arguments)
1037# define flat_hash_map_contains(arguments...) \
1038 CCC_flat_hash_map_contains(arguments)
1039# define flat_hash_map_get_key_value(arguments...) \
1040 CCC_flat_hash_map_get_key_value(arguments)
1041# define flat_hash_map_remove_key_value_wrap(arguments...) \
1042 CCC_flat_hash_map_remove_key_value_wrap(arguments)
1043# define flat_hash_map_swap_entry_wrap(arguments...) \
1044 CCC_flat_hash_map_swap_entry_wrap(arguments)
1045# define flat_hash_map_try_insert_wrap(arguments...) \
1046 CCC_flat_hash_map_try_insert_wrap(arguments)
1047# define flat_hash_map_insert_or_assign_wrap(arguments...) \
1048 CCC_flat_hash_map_insert_or_assign_wrap(arguments)
1049# define flat_hash_map_remove_entry_wrap(arguments...) \
1050 CCC_flat_hash_map_remove_entry_wrap(arguments)
1051# define flat_hash_map_remove_key_value(arguments...) \
1052 CCC_flat_hash_map_remove_key_value(arguments)
1053# define flat_hash_map_swap_entry(arguments...) \
1054 CCC_flat_hash_map_swap_entry(arguments)
1055# define flat_hash_map_try_insert(arguments...) \
1056 CCC_flat_hash_map_try_insert(arguments)
1057# define flat_hash_map_insert_or_assign(arguments...) \
1058 CCC_flat_hash_map_insert_or_assign(arguments)
1059# define flat_hash_map_remove_entry(arguments...) \
1060 CCC_flat_hash_map_remove_entry(arguments)
1061# define flat_hash_map_entry_wrap(arguments...) \
1062 CCC_flat_hash_map_entry_wrap(arguments)
1063# define flat_hash_map_entry(arguments...) CCC_flat_hash_map_entry(arguments)
1064# define flat_hash_map_and_modify(arguments...) \
1065 CCC_flat_hash_map_and_modify(arguments)
1066# define flat_hash_map_or_insert(arguments...) \
1067 CCC_flat_hash_map_or_insert(arguments)
1068# define flat_hash_map_insert_entry(arguments...) \
1069 CCC_flat_hash_map_insert_entry(arguments)
1070# define flat_hash_map_unwrap(arguments...) \
1071 CCC_flat_hash_map_unwrap(arguments)
1072# define flat_hash_map_occupied(arguments...) \
1073 CCC_flat_hash_map_occupied(arguments)
1074# define flat_hash_map_insert_error(arguments...) \
1075 CCC_flat_hash_map_insert_error(arguments)
1076# define flat_hash_map_begin(arguments...) CCC_flat_hash_map_begin(arguments)
1077# define flat_hash_map_next(arguments...) CCC_flat_hash_map_next(arguments)
1078# define flat_hash_map_end(arguments...) CCC_flat_hash_map_end(arguments)
1079# define flat_hash_map_is_empty(arguments...) \
1080 CCC_flat_hash_map_is_empty(arguments)
1081# define flat_hash_map_count(arguments...) CCC_flat_hash_map_count(arguments)
1082# define flat_hash_map_clear(arguments...) CCC_flat_hash_map_clear(arguments)
1083# define flat_hash_map_clear_and_free(arguments...) \
1084 CCC_flat_hash_map_clear_and_free(arguments)
1085# define flat_hash_map_capacity(arguments...) \
1086 CCC_flat_hash_map_capacity(arguments)
1087# define flat_hash_map_validate(arguments...) \
1088 CCC_flat_hash_map_validate(arguments)
1089/* NOLINTEND(readability-identifier-naming) */
1090#endif /* FLAT_HASH_MAP_USING_NAMESPACE_CCC */
1091
1092#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:376
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
An Occupied or Vacant position in a searchable container.
Definition: types.h:135
Definition: private_flat_hash_map.h:158
struct CCC_Flat_hash_map * map
Definition: private_flat_hash_map.h:160
Definition: private_flat_hash_map.h:137
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.
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