C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_hash_map.h
Go to the documentation of this file.
1
91#ifndef CCC_FLAT_HASH_MAP_H
92#define CCC_FLAT_HASH_MAP_H
93
95#include <stddef.h>
99#include "types.h"
100
111
117
190#define CCC_flat_hash_map_declare_fixed_map(fixed_map_type_name, type_name, \
191 capacity) \
192 CCC_private_flat_hash_map_declare_fixed_map(fixed_map_type_name, \
193 type_name, capacity)
194
199#define CCC_flat_hash_map_fixed_capacity(fixed_map_type_name) \
200 CCC_private_flat_hash_map_fixed_capacity(fixed_map_type_name)
201
265#define CCC_flat_hash_map_initialize(map_pointer, type_name, key_field, hash, \
266 compare, allocate, context_data, \
267 capacity) \
268 CCC_private_flat_hash_map_initialize(map_pointer, type_name, key_field, \
269 hash, compare, allocate, \
270 context_data, capacity)
271
331#define CCC_flat_hash_map_from(key_field, hash, compare, allocate, \
332 context_data, optional_capacity, \
333 array_compound_literal...) \
334 CCC_private_flat_hash_map_from(key_field, hash, compare, allocate, \
335 context_data, optional_capacity, \
336 array_compound_literal)
337
386#define CCC_flat_hash_map_with_capacity(type_name, key_field, hash, compare, \
387 allocate, context_data, capacity) \
388 CCC_private_flat_hash_map_with_capacity( \
389 type_name, key_field, hash, compare, allocate, context_data, capacity)
390
523 CCC_Flat_hash_map const *source,
524 CCC_Allocator *allocate);
525
542 CCC_Allocator *allocate);
543
555[[nodiscard]] CCC_Tribool
557
562[[nodiscard]] void *
564
587[[nodiscard]] CCC_Flat_hash_map_entry
589
606#define CCC_flat_hash_map_entry_wrap(map_pointer, key_pointer) \
607 &(CCC_Flat_hash_map_entry) \
608 { \
609 CCC_flat_hash_map_entry(map_pointer, key_pointer).private \
610 }
611
621[[nodiscard]] CCC_Flat_hash_map_entry *
623 CCC_Type_modifier *modify);
624
633[[nodiscard]] CCC_Flat_hash_map_entry *
635 CCC_Type_modifier *modify, void *context);
636
673#define CCC_flat_hash_map_and_modify_with(map_entry_pointer, type_name, \
674 closure_over_T...) \
675 &(CCC_Flat_hash_map_entry) \
676 { \
677 CCC_private_flat_hash_map_and_modify_with(map_entry_pointer, \
678 type_name, closure_over_T) \
679 }
680
690[[nodiscard]] void *
692 void const *type);
693
705#define CCC_flat_hash_map_or_insert_with(map_entry_pointer, \
706 type_compound_literal...) \
707 CCC_private_flat_hash_map_or_insert_with(map_entry_pointer, \
708 type_compound_literal)
709
721[[nodiscard]] void *
723 void const *type);
724
731#define CCC_flat_hash_map_insert_entry_with(map_entry_pointer, \
732 type_compound_literal...) \
733 CCC_private_flat_hash_map_insert_entry_with(map_entry_pointer, \
734 type_compound_literal)
735
746[[nodiscard]]
748 void *type_output);
749
762#define CCC_flat_hash_map_swap_entry_wrap(map_pointer, type_pointer) \
763 &(CCC_Entry) \
764 { \
765 CCC_flat_hash_map_swap_entry(map_pointer, type_pointer).private \
766 }
767
772[[nodiscard]] CCC_Entry
774
780#define CCC_flat_hash_map_remove_entry_wrap(map_entry_pointer) \
781 &(CCC_Entry) \
782 { \
783 CCC_flat_hash_map_remove_entry(map_entry_pointer).private \
784 }
785
795[[nodiscard]]
797 void const *type);
798
809#define CCC_flat_hash_map_try_insert_wrap(map_pointer, type_pointer) \
810 &(CCC_Entry) \
811 { \
812 CCC_flat_hash_map_try_insert(map_pointer, type_pointer).private \
813 }
814
831#define CCC_flat_hash_map_try_insert_with(map_pointer, key, \
832 type_compound_literal...) \
833 &(CCC_Entry) \
834 { \
835 CCC_private_flat_hash_map_try_insert_with(map_pointer, key, \
836 type_compound_literal) \
837 }
838
847[[nodiscard]]
849 void const *type);
850
859#define CCC_flat_hash_map_insert_or_assign_wrap(map_pointer, type_pointer) \
860 &(CCC_Entry) \
861 { \
862 CCC_flat_hash_map_insert_or_assign(map_pointer, type_pointer).private \
863 }
864
877#define CCC_flat_hash_map_insert_or_assign_with(map_pointer, key, \
878 type_compound_literal...) \
879 &(CCC_Entry) \
880 { \
881 CCC_private_flat_hash_map_insert_or_assign_with(map_pointer, key, \
882 type_compound_literal) \
883 }
884
897[[nodiscard]] CCC_Entry
899
913#define CCC_flat_hash_map_remove_key_value_wrap(map_pointer, \
914 type_output_pointer) \
915 &(CCC_Entry) \
916 { \
917 CCC_flat_hash_map_remove_key_value(map_pointer, type_output_pointer) \
918 .private \
919 }
920
924[[nodiscard]] void *
926
930[[nodiscard]] CCC_Tribool
932
948[[nodiscard]] CCC_Tribool
950
960[[nodiscard]] CCC_Entry_status
962
977 CCC_Type_destructor *destroy);
978
988 CCC_Type_destructor *destroy);
989
1019 CCC_Type_destructor *destroy,
1020 CCC_Allocator *allocate);
1021
1036[[nodiscard]] void *CCC_flat_hash_map_begin(CCC_Flat_hash_map const *map);
1037
1044[[nodiscard]] void *CCC_flat_hash_map_next(CCC_Flat_hash_map const *map,
1045 void const *type_iterator);
1046
1051[[nodiscard]] void *CCC_flat_hash_map_end(CCC_Flat_hash_map const *map);
1052
1062[[nodiscard]] CCC_Tribool
1064
1069
1073[[nodiscard]] CCC_Count
1075
1080[[nodiscard]] CCC_Tribool
1082
1087#ifdef FLAT_HASH_MAP_USING_NAMESPACE_CCC
1088typedef CCC_Flat_hash_map Flat_hash_map;
1089typedef CCC_Flat_hash_map_entry Flat_hash_map_entry;
1090# define flat_hash_map_declare_fixed_map(args...) \
1091 CCC_flat_hash_map_declare_fixed_map(args)
1092# define flat_hash_map_fixed_capacity(args...) \
1093 CCC_flat_hash_map_fixed_capacity(args)
1094# define flat_hash_map_reserve(args...) CCC_flat_hash_map_reserve(args)
1095# define flat_hash_map_initialize(args...) CCC_flat_hash_map_initialize(args)
1096# define flat_hash_map_from(args...) CCC_flat_hash_map_from(args)
1097# define flat_hash_map_with_capacity(args...) \
1098 CCC_flat_hash_map_with_capacity(args)
1099# define flat_hash_map_copy(args...) CCC_flat_hash_map_copy(args)
1100# define flat_hash_map_and_modify_with(args...) \
1101 CCC_flat_hash_map_and_modify_with(args)
1102# define flat_hash_map_or_insert_with(args...) \
1103 CCC_flat_hash_map_or_insert_with(args)
1104# define flat_hash_map_insert_entry_with(args...) \
1105 CCC_flat_hash_map_insert_entry_with(args)
1106# define flat_hash_map_try_insert_with(args...) \
1107 CCC_flat_hash_map_try_insert_with(args)
1108# define flat_hash_map_insert_or_assign_with(args...) \
1109 CCC_flat_hash_map_insert_or_assign_with(args)
1110# define flat_hash_map_contains(args...) CCC_flat_hash_map_contains(args)
1111# define flat_hash_map_get_key_value(args...) \
1112 CCC_flat_hash_map_get_key_value(args)
1113# define flat_hash_map_remove_key_value_wrap(args...) \
1114 CCC_flat_hash_map_remove_key_value_wrap(args)
1115# define flat_hash_map_swap_entry_wrap(args...) \
1116 CCC_flat_hash_map_swap_entry_wrap(args)
1117# define flat_hash_map_try_insert_wrap(args...) \
1118 CCC_flat_hash_map_try_insert_wrap(args)
1119# define flat_hash_map_insert_or_assign_wrap(args...) \
1120 CCC_flat_hash_map_insert_or_assign_wrap(args)
1121# define flat_hash_map_remove_entry_wrap(args...) \
1122 CCC_flat_hash_map_remove_entry_wrap(args)
1123# define flat_hash_map_remove_key_value(args...) \
1124 CCC_flat_hash_map_remove_key_value(args)
1125# define flat_hash_map_swap_entry(args...) CCC_flat_hash_map_swap_entry(args)
1126# define flat_hash_map_try_insert(args...) CCC_flat_hash_map_try_insert(args)
1127# define flat_hash_map_insert_or_assign(args...) \
1128 CCC_flat_hash_map_insert_or_assign(args)
1129# define flat_hash_map_remove_entry(args...) \
1130 CCC_flat_hash_map_remove_entry(args)
1131# define flat_hash_map_entry_wrap(args...) CCC_flat_hash_map_entry_wrap(args)
1132# define flat_hash_map_entry(args...) CCC_flat_hash_map_entry(args)
1133# define flat_hash_map_and_modify(args...) CCC_flat_hash_map_and_modify(args)
1134# define flat_hash_map_and_modify_context(args...) \
1135 CCC_flat_hash_map_and_modify_context(args)
1136# define flat_hash_map_or_insert(args...) CCC_flat_hash_map_or_insert(args)
1137# define flat_hash_map_insert_entry(args...) \
1138 CCC_flat_hash_map_insert_entry(args)
1139# define flat_hash_map_unwrap(args...) CCC_flat_hash_map_unwrap(args)
1140# define flat_hash_map_occupied(args...) CCC_flat_hash_map_occupied(args)
1141# define flat_hash_map_insert_error(args...) \
1142 CCC_flat_hash_map_insert_error(args)
1143# define flat_hash_map_begin(args...) CCC_flat_hash_map_begin(args)
1144# define flat_hash_map_next(args...) CCC_flat_hash_map_next(args)
1145# define flat_hash_map_end(args...) CCC_flat_hash_map_end(args)
1146# define flat_hash_map_is_empty(args...) CCC_flat_hash_map_is_empty(args)
1147# define flat_hash_map_count(args...) CCC_flat_hash_map_count(args)
1148# define flat_hash_map_clear(args...) CCC_flat_hash_map_clear(args)
1149# define flat_hash_map_clear_and_free(args...) \
1150 CCC_flat_hash_map_clear_and_free(args)
1151# define flat_hash_map_clear_and_free_reserve(args...) \
1152 CCC_flat_hash_map_clear_and_free_reserve(args)
1153# define flat_hash_map_capacity(args...) CCC_flat_hash_map_capacity(args)
1154# define flat_hash_map_validate(args...) CCC_flat_hash_map_validate(args)
1155#endif
1156
1157#endif /* CCC_FLAT_HASH_MAP_H */
CCC_Entry CCC_flat_hash_map_remove_entry(CCC_Flat_hash_map_entry const *entry)
Remove the entry from the table if Occupied.
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_Entry CCC_flat_hash_map_insert_or_assign(CCC_Flat_hash_map *map, void const *type)
Invariantly inserts or overwrites a user struct into the table.
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.
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_Entry CCC_flat_hash_map_swap_entry(CCC_Flat_hash_map *map, void *type_output)
Invariantly inserts the key value wrapping out_handle.
CCC_Result CCC_flat_hash_map_clear_and_free(CCC_Flat_hash_map *map, CCC_Type_destructor *destroy)
Frees all slots in the table and frees the underlying buffer.
CCC_Tribool CCC_flat_hash_map_validate(CCC_Flat_hash_map const *map)
Validation of invariants for the hash table.
CCC_Flat_hash_map_entry * CCC_flat_hash_map_and_modify(CCC_Flat_hash_map_entry *entry, CCC_Type_modifier *modify)
Modifies the provided entry if it is Occupied.
CCC_Tribool CCC_flat_hash_map_contains(CCC_Flat_hash_map const *map, void const *key)
Searches the table for the presence of key.
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_Flat_hash_map_entry * CCC_flat_hash_map_and_modify_context(CCC_Flat_hash_map_entry *entry, CCC_Type_modifier *modify, void *context)
Modifies the provided entry if it is Occupied.
CCC_Result CCC_flat_hash_map_clear_and_free_reserve(CCC_Flat_hash_map *map, CCC_Type_destructor *destroy, CCC_Allocator *allocate)
Frees all slots in the table and frees the underlying Buffer that was previously dynamically reserved...
CCC_Result CCC_flat_hash_map_reserve(CCC_Flat_hash_map *map, size_t to_add, CCC_Allocator *allocate)
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)
Obtains an entry for the provided key in the table for future use.
CCC_Result CCC_flat_hash_map_copy(CCC_Flat_hash_map *destination, CCC_Flat_hash_map const *source, CCC_Allocator *allocate)
Copy the map at source to destination.
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_Count CCC_flat_hash_map_count(CCC_Flat_hash_map const *map)
Returns the count of table occupied slots.
CCC_Result CCC_flat_hash_map_clear(CCC_Flat_hash_map *map, CCC_Type_destructor *destroy)
Frees all slots in the table for use without affecting capacity.
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.
CCC_Entry CCC_flat_hash_map_try_insert(CCC_Flat_hash_map *map, void const *type)
Attempts to insert the key value wrapping key_val_handle.
Private Flat Hash Map Interface.
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:202
Definition: private_types.h:53
Definition: private_flat_hash_map.h:170
Definition: private_flat_hash_map.h:142
The C Container Collection Fundamental Types.
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:133
void CCC_Type_destructor(CCC_Type_context)
A callback function for destroying an element in the container.
Definition: types.h:376
CCC_Result
A result of actions on containers.
Definition: types.h:148
void * CCC_Allocator(CCC_Allocator_context)
An allocation function at the core of all containers.
Definition: types.h:340
void CCC_Type_modifier(CCC_Type_context)
A callback function for modifying an element in the container.
Definition: types.h:358
Definition: private_flat_hash_map.h:188