C Container Collection (CCC)
Loading...
Searching...
No Matches
flat_hash_map.h
Go to the documentation of this file.
1
51#ifndef CCC_FLAT_HASH_MAP_H
52#define CCC_FLAT_HASH_MAP_H
53
55#include <stddef.h>
58#include "impl/impl_flat_hash_map.h"
59#include "types.h"
60
70typedef struct ccc_fhmap ccc_flat_hash_map;
71
77
150#define ccc_fhm_declare_fixed_map(fixed_map_type_name, key_val_type_name, \
151 capacity) \
152 ccc_impl_fhm_declare_fixed_map(fixed_map_type_name, key_val_type_name, \
153 capacity)
154
159#define ccc_fhm_fixed_capacity(fixed_map_type_name) \
160 ccc_impl_fhm_fixed_capacity(fixed_map_type_name)
161
224#define ccc_fhm_init(map_ptr, any_type_name, key_field, hash_fn, key_eq_fn, \
225 alloc_fn, aux_data, capacity) \
226 ccc_impl_fhm_init(map_ptr, any_type_name, key_field, hash_fn, key_eq_fn, \
227 alloc_fn, aux_data, capacity)
228
358 ccc_any_alloc_fn *fn);
359
376 ccc_any_alloc_fn *fn);
377
390 void const *key);
391
396[[nodiscard]] void *ccc_fhm_get_key_val(ccc_flat_hash_map const *h,
397 void const *key);
398
422 void const *key);
423
440#define ccc_fhm_entry_r(map_ptr, key_ptr) \
441 &(ccc_fhmap_entry) \
442 { \
443 ccc_fhm_entry(map_ptr, key_ptr).impl \
444 }
445
457
466[[nodiscard]] ccc_fhmap_entry *
468 void *aux);
469
494#define ccc_fhm_and_modify_w(map_entry_ptr, type_name, closure_over_T...) \
495 &(ccc_fhmap_entry) \
496 { \
497 ccc_impl_fhm_and_modify_w(map_entry_ptr, type_name, closure_over_T) \
498 }
499
509[[nodiscard]] void *ccc_fhm_or_insert(ccc_fhmap_entry const *e,
510 void const *key_val_type);
511
523#define ccc_fhm_or_insert_w(map_entry_ptr, lazy_key_value...) \
524 ccc_impl_fhm_or_insert_w(map_entry_ptr, lazy_key_value)
525
537[[nodiscard]] void *ccc_fhm_insert_entry(ccc_fhmap_entry const *e,
538 void const *key_val_type);
539
545#define ccc_fhm_insert_entry_w(map_entry_ptr, lazy_key_value...) \
546 ccc_impl_fhm_insert_entry_w(map_entry_ptr, lazy_key_value)
547
558[[nodiscard]]
559ccc_entry ccc_fhm_swap_entry(ccc_flat_hash_map *h, void *key_val_type_output);
560
572#define ccc_fhm_swap_entry_r(map_ptr, key_val_type_ptr) \
573 &(ccc_entry) \
574 { \
575 ccc_fhm_swap_entry(map_ptr, key_val_type_ptr).impl \
576 }
577
583
589#define ccc_fhm_remove_entry_r(map_entry_ptr) \
590 &(ccc_entry) \
591 { \
592 ccc_fhm_remove_entry(map_entry_ptr).impl \
593 }
594
604[[nodiscard]]
605ccc_entry ccc_fhm_try_insert(ccc_flat_hash_map *h, void const *key_val_type);
606
617#define ccc_fhm_try_insert_r(map_ptr, key_val_type_ptr) \
618 &(ccc_entry) \
619 { \
620 ccc_fhm_try_insert(map_ptr, key_val_type_ptr).impl \
621 }
622
638#define ccc_fhm_try_insert_w(map_ptr, key, lazy_value...) \
639 &(ccc_entry) \
640 { \
641 ccc_impl_fhm_try_insert_w(map_ptr, key, lazy_value) \
642 }
643
652[[nodiscard]]
654 void const *key_val_type);
655
664#define ccc_fhm_insert_or_assign_r(map_ptr, key_val_type_ptr) \
665 &(ccc_entry) \
666 { \
667 ccc_fhm_insert_or_assign(map_ptr, key_val_type_ptr).impl \
668 }
669
682#define ccc_fhm_insert_or_assign_w(map_ptr, key, lazy_value...) \
683 &(ccc_entry) \
684 { \
685 ccc_impl_fhm_insert_or_assign_w(map_ptr, key, lazy_value) \
686 }
687
701 void *key_val_type_output);
702
716#define ccc_fhm_remove_r(map_ptr, key_val_type_output_ptr) \
717 &(ccc_entry) \
718 { \
719 ccc_fhm_remove(map_ptr, key_val_type_output_ptr).impl \
720 }
721
725[[nodiscard]] void *ccc_fhm_unwrap(ccc_fhmap_entry const *e);
726
731
748
758[[nodiscard]] ccc_entry_status ccc_fhm_entry_status(ccc_fhmap_entry const *e);
759
774
785
814 ccc_any_type_destructor_fn *destructor,
815 ccc_any_alloc_fn *alloc);
816
831[[nodiscard]] void *ccc_fhm_begin(ccc_flat_hash_map const *h);
832
839[[nodiscard]] void *ccc_fhm_next(ccc_flat_hash_map const *h,
840 void const *key_val_type_iter);
841
846[[nodiscard]] void *ccc_fhm_end(ccc_flat_hash_map const *h);
847
858
863
868
876[[nodiscard]] void *ccc_fhm_data(ccc_flat_hash_map const *h);
877
883
888#ifdef FLAT_HASH_MAP_USING_NAMESPACE_CCC
889typedef ccc_flat_hash_map flat_hash_map;
890typedef ccc_fhmap_entry fhmap_entry;
891# define fhm_declare_fixed_map(args...) ccc_fhm_declare_fixed_map(args)
892# define fhm_fixed_capacity(args...) ccc_fhm_fixed_capacity(args)
893# define fhm_reserve(args...) ccc_fhm_reserve(args)
894# define fhm_init(args...) ccc_fhm_init(args)
895# define fhm_copy(args...) ccc_fhm_copy(args)
896# define fhm_and_modify_w(args...) ccc_fhm_and_modify_w(args)
897# define fhm_or_insert_w(args...) ccc_fhm_or_insert_w(args)
898# define fhm_insert_entry_w(args...) ccc_fhm_insert_entry_w(args)
899# define fhm_try_insert_w(args...) ccc_fhm_try_insert_w(args)
900# define fhm_insert_or_assign_w(args...) ccc_fhm_insert_or_assign_w(args)
901# define fhm_contains(args...) ccc_fhm_contains(args)
902# define fhm_get_key_val(args...) ccc_fhm_get_key_val(args)
903# define fhm_remove_r(args...) ccc_fhm_remove_r(args)
904# define fhm_swap_entry_r(args...) ccc_fhm_swap_entry_r(args)
905# define fhm_try_insert_r(args...) ccc_fhm_try_insert_r(args)
906# define fhm_insert_or_assign_r(args...) ccc_fhm_insert_or_assign_r(args)
907# define fhm_remove_entry_r(args...) ccc_fhm_remove_entry_r(args)
908# define fhm_remove(args...) ccc_fhm_remove(args)
909# define fhm_swap_entry(args...) ccc_fhm_swap_entry(args)
910# define fhm_try_insert(args...) ccc_fhm_try_insert(args)
911# define fhm_insert_or_assign(args...) ccc_fhm_insert_or_assign(args)
912# define fhm_remove_entry(args...) ccc_fhm_remove_entry(args)
913# define fhm_entry_r(args...) ccc_fhm_entry_r(args)
914# define fhm_entry(args...) ccc_fhm_entry(args)
915# define fhm_and_modify(args...) ccc_fhm_and_modify(args)
916# define fhm_and_modify_aux(args...) ccc_fhm_and_modify_aux(args)
917# define fhm_or_insert(args...) ccc_fhm_or_insert(args)
918# define fhm_insert_entry(args...) ccc_fhm_insert_entry(args)
919# define fhm_unwrap(args...) ccc_fhm_unwrap(args)
920# define fhm_occupied(args...) ccc_fhm_occupied(args)
921# define fhm_insert_error(args...) ccc_fhm_insert_error(args)
922# define fhm_begin(args...) ccc_fhm_begin(args)
923# define fhm_next(args...) ccc_fhm_next(args)
924# define fhm_end(args...) ccc_fhm_end(args)
925# define fhm_data(args...) ccc_fhm_data(args)
926# define fhm_is_empty(args...) ccc_fhm_is_empty(args)
927# define fhm_size(args...) ccc_fhm_size(args)
928# define fhm_clear(args...) ccc_fhm_clear(args)
929# define fhm_clear_and_free(args...) ccc_fhm_clear_and_free(args)
930# define fhm_clear_and_free_reserve(args...) \
931 ccc_fhm_clear_and_free_reserve(args)
932# define fhm_capacity(args...) ccc_fhm_capacity(args)
933# define fhm_validate(args...) ccc_fhm_validate(args)
934#endif
935
936#endif /* CCC_FLAT_HASH_MAP_H */
struct ccc_fhmap ccc_flat_hash_map
A container for storing key-value structures defined by the user in a contiguous buffer.
Definition: flat_hash_map.h:70
void * ccc_fhm_begin(ccc_flat_hash_map const *h)
Obtains a pointer to the first element in the table.
ccc_fhmap_entry * ccc_fhm_and_modify(ccc_fhmap_entry *e, ccc_any_type_update_fn *fn)
Modifies the provided entry if it is Occupied.
union ccc_fhmap_entry ccc_fhmap_entry
A container specific entry used to implement the Entry Interface.
Definition: flat_hash_map.h:76
ccc_fhmap_entry * ccc_fhm_and_modify_aux(ccc_fhmap_entry *e, ccc_any_type_update_fn *fn, void *aux)
Modifies the provided entry if it is Occupied.
void * ccc_fhm_get_key_val(ccc_flat_hash_map const *h, void const *key)
Returns a reference into the table at entry key.
ccc_tribool ccc_fhm_is_empty(ccc_flat_hash_map const *h)
Returns the size status of the table.
ccc_tribool ccc_fhm_contains(ccc_flat_hash_map const *h, void const *key)
Searches the table for the presence of key.
ccc_entry ccc_fhm_insert_or_assign(ccc_flat_hash_map *h, void const *key_val_type)
Invariantly inserts or overwrites a user struct into the table.
void * ccc_fhm_next(ccc_flat_hash_map const *h, void const *key_val_type_iter)
Advances the iterator to the next occupied table slot.
ccc_entry_status ccc_fhm_entry_status(ccc_fhmap_entry const *e)
Obtain the entry status from a container entry.
void * ccc_fhm_or_insert(ccc_fhmap_entry const *e, void const *key_val_type)
Inserts the struct with handle elem if the entry is Vacant.
ccc_result ccc_fhm_copy(ccc_flat_hash_map *dst, ccc_flat_hash_map const *src, ccc_any_alloc_fn *fn)
Copy the map at source to destination.
ccc_ucount ccc_fhm_size(ccc_flat_hash_map const *h)
Returns the size of the table representing active slots.
ccc_entry ccc_fhm_swap_entry(ccc_flat_hash_map *h, void *key_val_type_output)
Invariantly inserts the key value wrapping out_handle.
ccc_result ccc_fhm_clear(ccc_flat_hash_map *h, ccc_any_type_destructor_fn *fn)
Frees all slots in the table for use without affecting capacity.
ccc_tribool ccc_fhm_insert_error(ccc_fhmap_entry const *e)
Provides the status of the entry should an insertion follow.
ccc_tribool ccc_fhm_validate(ccc_flat_hash_map const *h)
Validation of invariants for the hash table.
ccc_entry ccc_fhm_remove(ccc_flat_hash_map *h, void *key_val_type_output)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
ccc_result ccc_fhm_clear_and_free(ccc_flat_hash_map *h, ccc_any_type_destructor_fn *fn)
Frees all slots in the table and frees the underlying buffer.
ccc_entry ccc_fhm_try_insert(ccc_flat_hash_map *h, void const *key_val_type)
Attempts to insert the key value wrapping key_val_handle.
ccc_ucount ccc_fhm_capacity(ccc_flat_hash_map const *h)
Return the full capacity of the backing storage.
ccc_tribool ccc_fhm_occupied(ccc_fhmap_entry const *e)
Returns the Vacant or Occupied status of the entry.
void * ccc_fhm_insert_entry(ccc_fhmap_entry const *e, void const *key_val_type)
Inserts the provided entry invariantly.
ccc_entry ccc_fhm_remove_entry(ccc_fhmap_entry const *e)
Remove the entry from the table if Occupied.
ccc_fhmap_entry ccc_fhm_entry(ccc_flat_hash_map *h, void const *key)
Obtains an entry for the provided key in the table for future use.
void * ccc_fhm_end(ccc_flat_hash_map const *h)
Check the current iterator against the end for loop termination.
void * ccc_fhm_unwrap(ccc_fhmap_entry const *e)
Unwraps the provided entry to obtain a view into the table element.
void * ccc_fhm_data(ccc_flat_hash_map const *h)
Return a reference to the base of backing array. O(1).
ccc_result ccc_fhm_clear_and_free_reserve(ccc_flat_hash_map *h, ccc_any_type_destructor_fn *destructor, ccc_any_alloc_fn *alloc)
Frees all slots in the table and frees the underlying buffer that was previously dynamically reserved...
ccc_result ccc_fhm_reserve(ccc_flat_hash_map *h, size_t to_add, ccc_any_alloc_fn *fn)
Reserve space required to add a specified number of elements to the map. If the current capacity is s...
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:187
#define ccc_entry(container_ptr, key_ptr...)
Obtain a container specific entry for the Entry Interface.
Definition: traits.h:141
The C Container Collection Fundamental Types.
void * ccc_any_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:312
ccc_result
A result of actions on containers.
Definition: types.h:132
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:117
void ccc_any_type_destructor_fn(ccc_any_type)
A callback function for destroying an element in the container.
Definition: types.h:347
void ccc_any_type_update_fn(ccc_any_type)
A callback function for modifying an element in the container.
Definition: types.h:329