45#ifndef CCC_HANDLE_HASH_MAP_H
46#define CCC_HANDLE_HASH_MAP_H
52#include "impl/impl_handle_hash_map.h"
99#define ccc_hhm_init(memory_ptr, hhash_elem_field, key_field, hash_fn, \
100 key_eq_fn, alloc_fn, aux_data, capacity) \
101 ccc_impl_hhm_init(memory_ptr, hhash_elem_field, key_field, hash_fn, \
102 key_eq_fn, alloc_fn, aux_data, capacity)
222#define ccc_hhm_as(handle_hash_map_ptr, type_name, handle_i...) \
223 ccc_impl_hhm_as(handle_hash_map_ptr, type_name, handle_i)
273#define ccc_hhm_swap_handle_r(handle_hash_map_ptr, out_handle_ptr) \
276 ccc_hhm_swap_handle((handle_hash_map_ptr), (out_handle_ptr)).impl_ \
303#define ccc_hhm_remove_r(handle_hash_map_ptr, out_handle_ptr) \
306 ccc_hhm_remove((handle_hash_map_ptr), (out_handle_ptr)).impl_ \
327#define ccc_hhm_try_insert_r(handle_hash_map_ptr, key_val_handle_ptr) \
330 ccc_hhm_try_insert((handle_hash_map_ptr), (key_val_handle_ptr)).impl_ \
348#define ccc_hhm_try_insert_w(handle_hash_map_ptr, key, lazy_value...) \
351 ccc_impl_hhm_try_insert_w(handle_hash_map_ptr, key, lazy_value) \
375#define ccc_hhm_insert_or_assign_r(handle_hash_map_ptr, key_val_handle_ptr) \
378 ccc_hhm_insert_or_assign((handle_hash_map_ptr), (key_val_handle)) \
394#define ccc_hhm_insert_or_assign_w(handle_hash_map_ptr, key, lazy_value...) \
397 ccc_impl_hhm_insert_or_assign_w(handle_hash_map_ptr, key, lazy_value) \
434#define ccc_hhm_handle_r(handle_hash_map_ptr, key_ptr) \
435 &(ccc_hhmap_handle) \
437 ccc_hhm_handle((handle_hash_map_ptr), (key_ptr)).impl_ \
488#define ccc_hhm_and_modify_w(handle_hash_map_handle_ptr, type_name, \
490 &(ccc_hhmap_handle) \
492 ccc_impl_hhm_and_modify_w(handle_hash_map_handle_ptr, type_name, \
520#define ccc_hhm_or_insert_w(handle_hash_map_handle_ptr, lazy_key_value...) \
521 ccc_impl_hhm_or_insert_w(handle_hash_map_handle_ptr, lazy_key_value)
542#define ccc_hhm_insert_handle_w(handle_hash_map_handle_ptr, lazy_key_value...) \
543 ccc_impl_hhm_insert_handle_w(handle_hash_map_handle_ptr, lazy_key_value)
559#define ccc_hhm_remove_handle_r(handle_hash_map_handle_ptr) \
562 ccc_hhm_remove_handle((handle_hash_map_handle_ptr)).impl_ \
714#ifdef HANDLE_HASH_MAP_USING_NAMESPACE_CCC
718# define hhm_init(args...) ccc_hhm_init(args)
719# define hhm_copy(args...) ccc_hhm_copy(args)
720# define hhm_contains(args...) ccc_hhm_contains(args)
721# define hhm_get_key_val(args...) ccc_hhm_get_key_val(args)
722# define hhm_at(args...) ccc_hhm_at(args)
723# define hhm_as(args...) ccc_hhm_as(args)
724# define hhm_swap_entry(args...) ccc_hhm_swap_entry(args)
725# define hhm_swap_entry_r(args...) ccc_hhm_swap_entry_r(args)
726# define hhm_remove(args...) ccc_hhm_remove(args)
727# define hhm_remove_r(args...) ccc_hhm_remove_r(args)
728# define hhm_try_insert(args...) ccc_hhm_try_insert(args)
729# define hhm_try_insert_r(args...) ccc_hhm_try_insert_r(args)
730# define hhm_try_insert_w(args...) ccc_hhm_try_insert_w(args)
731# define hhm_insert_or_assign(args...) ccc_hhm_insert_or_assign(args)
732# define hhm_insert_or_assign_r(args...) ccc_hhm_insert_or_assign_r(args)
733# define hhm_insert_or_assign_w(args...) ccc_hhm_insert_or_assign_w(args)
734# define hhm_handle(args...) ccc_hhm_handle(args)
735# define hhm_handle_r(args...) ccc_hhm_handle_r(args)
736# define hhm_and_modify(args...) ccc_hhm_and_modify(args)
737# define hhm_and_modify_aux(args...) ccc_hhm_and_modify_aux(args)
738# define hhm_and_modify_w(args...) ccc_hhm_and_modify_w(args)
739# define hhm_or_insert(args...) ccc_hhm_or_insert(args)
740# define hhm_or_insert_w(args...) ccc_hhm_or_insert_w(args)
741# define hhm_insert_handle(args...) ccc_hhm_insert_handle(args)
742# define hhm_insert_handle_w(args...) ccc_hhm_insert_handle_w(args)
743# define hhm_remove_handle(args...) ccc_hhm_remove_handle(args)
744# define hhm_remove_handle_r(args...) ccc_hhm_remove_handle_r(args)
745# define hhm_unwrap(args...) ccc_hhm_unwrap(args)
746# define hhm_occupied(args...) ccc_hhm_occupied(args)
747# define hhm_insert_error(args...) ccc_hhm_insert_error(args)
748# define hhm_handle_status(args...) ccc_hhm_handle_status(args)
749# define hhm_clear(args...) ccc_hhm_clear(args)
750# define hhm_clear_and_free(args...) ccc_hhm_clear_and_free(args)
751# define hhm_begin(args...) ccc_hhm_begin(args)
752# define hhm_next(args...) ccc_hhm_next(args)
753# define hhm_end(args...) ccc_hhm_end(args)
754# define hhm_is_empty(args...) ccc_hhm_is_empty(args)
755# define hhm_size(args...) ccc_hhm_size(args)
756# define hhm_next_prime(args...) ccc_hhm_next_prime(args)
757# define hhm_capacity(args...) ccc_hhm_capacity(args)
758# define hhm_data(args...) ccc_hhm_data(args)
759# define hhm_validate(args...) ccc_hhm_validate(args)
ccc_handle_i ccc_hhm_insert_handle(ccc_hhmap_handle const *e, ccc_hhmap_elem *elem)
Inserts the provided handle invariantly.
ccc_handle ccc_hhm_try_insert(ccc_handle_hash_map *h, ccc_hhmap_elem *key_val_handle)
Attempts to insert the key value wrapping key_val_handle.
ccc_result ccc_hhm_next(ccc_hhmap_handle *iter)
Advances the iterator to the next occupied table handle.
ccc_handle ccc_hhm_remove_handle(ccc_hhmap_handle const *e)
Remove the handle from the table if Occupied.
ccc_handle ccc_hhm_remove(ccc_handle_hash_map *h, ccc_hhmap_elem *out_handle)
Removes the key value in the map storing the old value, if present, in the struct containing out_hand...
struct ccc_hhmap_ ccc_handle_hash_map
A container for storing key-value structures defined by the user in a contiguous buffer.
Definition: handle_hash_map.h:64
ccc_handle_i ccc_hhm_or_insert(ccc_hhmap_handle const *e, ccc_hhmap_elem *elem)
Inserts the struct with handle elem if the handle is Vacant.
ccc_hhmap_handle * ccc_hhm_and_modify(ccc_hhmap_handle *e, ccc_update_fn *fn)
Modifies the provided handle if it is Occupied.
struct ccc_hhmap_elem_ ccc_hhmap_elem
An intrusive element for a user provided type.
Definition: handle_hash_map.h:70
ccc_ucount ccc_hhm_size(ccc_handle_hash_map const *h)
Returns the size of the table representing active slots.
ccc_handle_status ccc_hhm_handle_status(ccc_hhmap_handle const *e)
Obtain the handle status from a container handle.
ccc_handle ccc_hhm_swap_handle(ccc_handle_hash_map *h, ccc_hhmap_elem *out_handle)
Invariantly inserts the key value wrapping out_handle.
ccc_tribool ccc_hhm_contains(ccc_handle_hash_map *h, void const *key)
Searches the table for the presence of key.
ccc_result ccc_hhm_clear(ccc_handle_hash_map *h, ccc_destructor_fn *fn)
Frees all slots in the table for use without affecting capacity.
void * ccc_hhm_data(ccc_handle_hash_map const *h)
Return a reference to the base of backing array. O(1).
ccc_tribool ccc_hhm_end(ccc_hhmap_handle const *iter)
Check if the current handle iterator has reached the end.
void * ccc_hhm_at(ccc_handle_hash_map const *h, ccc_handle_i i)
Returns a reference to the user data at the provided handle.
ccc_ucount ccc_hhm_capacity(ccc_handle_hash_map const *h)
Return the full capacity of the backing storage.
ccc_result ccc_hhm_clear_and_free(ccc_handle_hash_map *h, ccc_destructor_fn *fn)
Frees all slots in the table and frees the underlying buffer.
ccc_tribool ccc_hhm_occupied(ccc_hhmap_handle const *e)
Returns the Vacant or Occupied status of the handle.
ccc_handle_i ccc_hhm_unwrap(ccc_hhmap_handle const *e)
Unwraps the provided handle to obtain a handle index.
ccc_ucount ccc_hhm_next_prime(size_t n)
Helper to find a prime number if needed.
ccc_handle_i ccc_hhm_get_key_val(ccc_handle_hash_map *h, void const *key)
Returns a handle to the element stored at key if present.
ccc_handle ccc_hhm_insert_or_assign(ccc_handle_hash_map *h, ccc_hhmap_elem *key_val_handle)
Invariantly inserts or overwrites a user struct into the table.
ccc_hhmap_handle ccc_hhm_begin(ccc_handle_hash_map const *h)
Obtains a handle to the first element in the table.
ccc_hhmap_handle * ccc_hhm_and_modify_aux(ccc_hhmap_handle *e, ccc_update_fn *fn, void *aux)
Modifies the provided handle if it is Occupied.
ccc_hhmap_handle ccc_hhm_handle(ccc_handle_hash_map *h, void const *key)
Obtains a handle for the provided key in the table for future use.
ccc_tribool ccc_hhm_validate(ccc_handle_hash_map const *h)
Validation of invariants for the hash table.
ccc_tribool ccc_hhm_is_empty(ccc_handle_hash_map const *h)
Returns the size status of the table.
ccc_tribool ccc_hhm_insert_error(ccc_hhmap_handle const *e)
Provides the status of the handle should an insertion follow.
ccc_result ccc_hhm_copy(ccc_handle_hash_map *dst, ccc_handle_hash_map const *src, ccc_alloc_fn *fn)
Copy the map at source to destination.
union ccc_hhmap_handle_ ccc_hhmap_handle
A container specific handle used to implement the Handle Interface.
Definition: handle_hash_map.h:76
A type for returning an unsigned integer from a container for counting. Intended to count sizes,...
Definition: types.h:172
The C Container Collection Fundamental Types.
void ccc_update_fn(ccc_user_type)
A callback function for modifying an element in the container.
Definition: types.h:300
union ccc_handle_ ccc_handle
An Occupied or Vacant handle to a flat searchable container entry.
Definition: types.h:66
size_t ccc_handle_i
A stable index to user data in a container that uses a flat array as the underlying storage method.
Definition: types.h:78
ccc_result
A result of actions on containers.
Definition: types.h:117
enum ccc_entry_status_ ccc_handle_status
The status monitoring and handle state once it is obtained.
Definition: types.h:88
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:102
void * ccc_alloc_fn(void *ptr, size_t size, void *aux)
An allocation function at the core of all containers.
Definition: types.h:283
void ccc_destructor_fn(ccc_user_type)
A callback function for destroying an element in the container.
Definition: types.h:318