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(fixed_map_type_name, type_name, \
191 capacity) \
192 CCC_private_flat_hash_map_declare_fixed(fixed_map_type_name, type_name, \
193 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
264#define CCC_flat_hash_map_initialize(map_pointer, type_name, key_field, hash, \
265 compare, allocate, context_data, \
266 capacity) \
267 CCC_private_flat_hash_map_initialize(map_pointer, type_name, key_field, \
268 hash, compare, allocate, \
269 context_data, capacity)
270
329#define CCC_flat_hash_map_from(key_field, hash, compare, allocate, \
330 context_data, optional_capacity, \
331 array_compound_literal...) \
332 CCC_private_flat_hash_map_from(key_field, hash, compare, allocate, \
333 context_data, optional_capacity, \
334 array_compound_literal)
335
383#define CCC_flat_hash_map_with_capacity(type_name, key_field, hash, compare, \
384 allocate, context_data, capacity) \
385 CCC_private_flat_hash_map_with_capacity( \
386 type_name, key_field, hash, compare, allocate, context_data, capacity)
387
421#define CCC_flat_hash_map_with_compound_literal(key_field, hash, compare, \
422 compound_literal) \
423 CCC_private_flat_hash_map_with_compound_literal(key_field, hash, compare, \
424 compound_literal)
425
461#define CCC_flat_hash_map_with_context_compound_literal( \
462 key_field, hash, compare, context, compound_literal) \
463 CCC_private_flat_hash_map_with_context_compound_literal( \
464 key_field, hash, compare, context, compound_literal)
465
598 CCC_Flat_hash_map const *source,
599 CCC_Allocator *allocate);
600
617 CCC_Allocator *allocate);
618
630[[nodiscard]] CCC_Tribool
632
637[[nodiscard]] void *
639
662[[nodiscard]] CCC_Flat_hash_map_entry
664
681#define CCC_flat_hash_map_entry_wrap(map_pointer, key_pointer) \
682 &(CCC_Flat_hash_map_entry) \
683 { \
684 CCC_flat_hash_map_entry(map_pointer, key_pointer).private \
685 }
686
696[[nodiscard]] CCC_Flat_hash_map_entry *
698 CCC_Type_modifier *modify);
699
708[[nodiscard]] CCC_Flat_hash_map_entry *
710 CCC_Type_modifier *modify, void *context);
711
748#define CCC_flat_hash_map_and_modify_with(map_entry_pointer, type_name, \
749 closure_over_T...) \
750 &(CCC_Flat_hash_map_entry) \
751 { \
752 CCC_private_flat_hash_map_and_modify_with(map_entry_pointer, \
753 type_name, closure_over_T) \
754 }
755
765[[nodiscard]] void *
767 void const *type);
768
780#define CCC_flat_hash_map_or_insert_with(map_entry_pointer, \
781 type_compound_literal...) \
782 CCC_private_flat_hash_map_or_insert_with(map_entry_pointer, \
783 type_compound_literal)
784
796[[nodiscard]] void *
798 void const *type);
799
806#define CCC_flat_hash_map_insert_entry_with(map_entry_pointer, \
807 type_compound_literal...) \
808 CCC_private_flat_hash_map_insert_entry_with(map_entry_pointer, \
809 type_compound_literal)
810
821[[nodiscard]]
823 void *type_output);
824
837#define CCC_flat_hash_map_swap_entry_wrap(map_pointer, type_pointer) \
838 &(CCC_Entry) \
839 { \
840 CCC_flat_hash_map_swap_entry(map_pointer, type_pointer).private \
841 }
842
847[[nodiscard]] CCC_Entry
849
855#define CCC_flat_hash_map_remove_entry_wrap(map_entry_pointer) \
856 &(CCC_Entry) \
857 { \
858 CCC_flat_hash_map_remove_entry(map_entry_pointer).private \
859 }
860
870[[nodiscard]]
872 void const *type);
873
884#define CCC_flat_hash_map_try_insert_wrap(map_pointer, type_pointer) \
885 &(CCC_Entry) \
886 { \
887 CCC_flat_hash_map_try_insert(map_pointer, type_pointer).private \
888 }
889
906#define CCC_flat_hash_map_try_insert_with(map_pointer, key, \
907 type_compound_literal...) \
908 &(CCC_Entry) \
909 { \
910 CCC_private_flat_hash_map_try_insert_with(map_pointer, key, \
911 type_compound_literal) \
912 }
913
922[[nodiscard]]
924 void const *type);
925
934#define CCC_flat_hash_map_insert_or_assign_wrap(map_pointer, type_pointer) \
935 &(CCC_Entry) \
936 { \
937 CCC_flat_hash_map_insert_or_assign(map_pointer, type_pointer).private \
938 }
939
952#define CCC_flat_hash_map_insert_or_assign_with(map_pointer, key, \
953 type_compound_literal...) \
954 &(CCC_Entry) \
955 { \
956 CCC_private_flat_hash_map_insert_or_assign_with(map_pointer, key, \
957 type_compound_literal) \
958 }
959
972[[nodiscard]] CCC_Entry
974
988#define CCC_flat_hash_map_remove_key_value_wrap(map_pointer, \
989 type_output_pointer) \
990 &(CCC_Entry) \
991 { \
992 CCC_flat_hash_map_remove_key_value(map_pointer, type_output_pointer) \
993 .private \
994 }
995
999[[nodiscard]] void *
1001
1005[[nodiscard]] CCC_Tribool
1007
1023[[nodiscard]] CCC_Tribool
1025
1035[[nodiscard]] CCC_Entry_status
1037
1052 CCC_Type_destructor *destroy);
1053
1063 CCC_Type_destructor *destroy);
1064
1094 CCC_Type_destructor *destroy,
1095 CCC_Allocator *allocate);
1096
1111[[nodiscard]] void *CCC_flat_hash_map_begin(CCC_Flat_hash_map const *map);
1112
1119[[nodiscard]] void *CCC_flat_hash_map_next(CCC_Flat_hash_map const *map,
1120 void const *type_iterator);
1121
1126[[nodiscard]] void *CCC_flat_hash_map_end(CCC_Flat_hash_map const *map);
1127
1137[[nodiscard]] CCC_Tribool
1139
1144
1148[[nodiscard]] CCC_Count
1150
1155[[nodiscard]] CCC_Tribool
1157
1162#ifdef FLAT_HASH_MAP_USING_NAMESPACE_CCC
1163typedef CCC_Flat_hash_map Flat_hash_map;
1164typedef CCC_Flat_hash_map_entry Flat_hash_map_entry;
1165# define flat_hash_map_declare_fixed(args...) \
1166 CCC_flat_hash_map_declare_fixed(args)
1167# define flat_hash_map_fixed_capacity(args...) \
1168 CCC_flat_hash_map_fixed_capacity(args)
1169# define flat_hash_map_reserve(args...) CCC_flat_hash_map_reserve(args)
1170# define flat_hash_map_initialize(args...) CCC_flat_hash_map_initialize(args)
1171# define flat_hash_map_from(args...) CCC_flat_hash_map_from(args)
1172# define flat_hash_map_with_capacity(args...) \
1173 CCC_flat_hash_map_with_capacity(args)
1174# define flat_hash_map_with_compound_literal(args...) \
1175 CCC_flat_hash_map_with_compound_literal(args)
1176# define flat_hash_map_with_context_compound_literal(args...) \
1177 CCC_flat_hash_map_with_context_compound_literal(args)
1178# define flat_hash_map_copy(args...) CCC_flat_hash_map_copy(args)
1179# define flat_hash_map_and_modify_with(args...) \
1180 CCC_flat_hash_map_and_modify_with(args)
1181# define flat_hash_map_or_insert_with(args...) \
1182 CCC_flat_hash_map_or_insert_with(args)
1183# define flat_hash_map_insert_entry_with(args...) \
1184 CCC_flat_hash_map_insert_entry_with(args)
1185# define flat_hash_map_try_insert_with(args...) \
1186 CCC_flat_hash_map_try_insert_with(args)
1187# define flat_hash_map_insert_or_assign_with(args...) \
1188 CCC_flat_hash_map_insert_or_assign_with(args)
1189# define flat_hash_map_contains(args...) CCC_flat_hash_map_contains(args)
1190# define flat_hash_map_get_key_value(args...) \
1191 CCC_flat_hash_map_get_key_value(args)
1192# define flat_hash_map_remove_key_value_wrap(args...) \
1193 CCC_flat_hash_map_remove_key_value_wrap(args)
1194# define flat_hash_map_swap_entry_wrap(args...) \
1195 CCC_flat_hash_map_swap_entry_wrap(args)
1196# define flat_hash_map_try_insert_wrap(args...) \
1197 CCC_flat_hash_map_try_insert_wrap(args)
1198# define flat_hash_map_insert_or_assign_wrap(args...) \
1199 CCC_flat_hash_map_insert_or_assign_wrap(args)
1200# define flat_hash_map_remove_entry_wrap(args...) \
1201 CCC_flat_hash_map_remove_entry_wrap(args)
1202# define flat_hash_map_remove_key_value(args...) \
1203 CCC_flat_hash_map_remove_key_value(args)
1204# define flat_hash_map_swap_entry(args...) CCC_flat_hash_map_swap_entry(args)
1205# define flat_hash_map_try_insert(args...) CCC_flat_hash_map_try_insert(args)
1206# define flat_hash_map_insert_or_assign(args...) \
1207 CCC_flat_hash_map_insert_or_assign(args)
1208# define flat_hash_map_remove_entry(args...) \
1209 CCC_flat_hash_map_remove_entry(args)
1210# define flat_hash_map_entry_wrap(args...) CCC_flat_hash_map_entry_wrap(args)
1211# define flat_hash_map_entry(args...) CCC_flat_hash_map_entry(args)
1212# define flat_hash_map_and_modify(args...) CCC_flat_hash_map_and_modify(args)
1213# define flat_hash_map_and_modify_context(args...) \
1214 CCC_flat_hash_map_and_modify_context(args)
1215# define flat_hash_map_or_insert(args...) CCC_flat_hash_map_or_insert(args)
1216# define flat_hash_map_insert_entry(args...) \
1217 CCC_flat_hash_map_insert_entry(args)
1218# define flat_hash_map_unwrap(args...) CCC_flat_hash_map_unwrap(args)
1219# define flat_hash_map_occupied(args...) CCC_flat_hash_map_occupied(args)
1220# define flat_hash_map_insert_error(args...) \
1221 CCC_flat_hash_map_insert_error(args)
1222# define flat_hash_map_begin(args...) CCC_flat_hash_map_begin(args)
1223# define flat_hash_map_next(args...) CCC_flat_hash_map_next(args)
1224# define flat_hash_map_end(args...) CCC_flat_hash_map_end(args)
1225# define flat_hash_map_is_empty(args...) CCC_flat_hash_map_is_empty(args)
1226# define flat_hash_map_count(args...) CCC_flat_hash_map_count(args)
1227# define flat_hash_map_clear(args...) CCC_flat_hash_map_clear(args)
1228# define flat_hash_map_clear_and_free(args...) \
1229 CCC_flat_hash_map_clear_and_free(args)
1230# define flat_hash_map_clear_and_free_reserve(args...) \
1231 CCC_flat_hash_map_clear_and_free_reserve(args)
1232# define flat_hash_map_capacity(args...) CCC_flat_hash_map_capacity(args)
1233# define flat_hash_map_validate(args...) CCC_flat_hash_map_validate(args)
1234#endif
1235
1236#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