1#ifndef KOUTIL_CONTAINER_HASH_ARRAY_H
2#define KOUTIL_CONTAINER_HASH_ARRAY_H
21template <
typename T,
typename Key>
22concept is_hash =
requires(T hash,
const Key& key) {
23 requires std::is_trivially_constructible_v<T>;
25 { hash(key) } -> std::same_as<std::size_t>;
34template <
typename T,
typename Key,
typename KeyID>
35concept is_key_adapter =
requires(
const Key& key, T adapter,
const KeyID& index) {
36 requires std::move_constructible<T> && std::is_trivially_copy_constructible_v<T>;
37 { adapter.eql(key, index) } -> std::same_as<bool>;
A hash array with open addressing and linear probing.
Definition hash_array.h:56
Allocator allocator_t
Definition hash_array.h:65
const_iterator_t cend() const
Get a constant iterator to the end of the hash_array.
Definition hash_array.h:265
iterator_t end()
Get an iterator to the end of the hash_array.
Definition hash_array.h:241
hash_array()=default
Default constructor.
bool try_set(const key_t &key, const key_id_t &new_key_id, adapter_t adapter)
Try to set new key ID.
Definition hash_array.h:193
void erase(const key_t &key, adapter_t adapter)
Erases an element from the hash table.
Definition hash_array.h:205
KeyID key_id_t
Definition hash_array.h:59
std::size_t bucket_count() const
Returns the number of buckets.
Definition hash_array.h:154
template_hash_array_t::iterator_t iterator_t
Definition hash_array.h:84
std::size_t size() const
Get the number of elements in the hash_array.
Definition hash_array.h:148
KeyAdapter adapter_t
Definition hash_array.h:64
template_hash_array_t m_storage
Definition hash_array.h:268
iterator_t begin()
Get an iterator to the beginning of the hash_array.
Definition hash_array.h:235
bool try_insert(const key_t &key, const key_id_t &key_id, adapter_t adapter)
Try to insert a key and key ID into the hash_array.
Definition hash_array.h:182
iterator_t find(const key_t &key, adapter_t adapter)
Finds an element in the hash table.
Definition hash_array.h:216
std::size_t value_t
Definition hash_array.h:60
bool empty() const
Check if the hash_array is empty.
Definition hash_array.h:142
~hash_array()=default
Destructor.
bucket_t::iterator bucket_iter
Definition hash_array.h:63
Key key_t
Definition hash_array.h:58
void clear()
Clear all elements from the hash_array.
Definition hash_array.h:174
static constexpr bool comptime_value
Definition hash_array.h:79
template_hash_array_t::const_iterator_t const_iterator_t
Definition hash_array.h:85
const_iterator_t cbegin() const
Get a constant iterator to the beginning of the hash_array.
Definition hash_array.h:259
float max_load_factor() const
Returns the maximum load factor.
Definition hash_array.h:160
Hash hash_t
Definition hash_array.h:62
void set_max_load_factor(float factor)
Sets a new maximum load factor.
Definition hash_array.h:166
Bucket bucket_t
Definition hash_array.h:61
hash_array & operator=(const hash_array &other)=default
Copy assignment operator.
iterator< true > const_iterator_t
Definition template_hash_array.h:194
bool empty() const
Check if the hash_array is empty.
Definition template_hash_array.h:303
iterator_t begin()
Get an iterator to the beginning of the hash_array.
Definition template_hash_array.h:413
iterator< false > iterator_t
Definition template_hash_array.h:193
std::size_t bucket_count() const
Returns the number of buckets.
Definition template_hash_array.h:315
void clear()
Clear all elements from the hash_array.
Definition template_hash_array.h:335
std::size_t size() const
Get the number of elements in the hash_array.
Definition template_hash_array.h:309
const_iterator_t cend() const
Get a constant iterator to the end of the hash_array.
Definition template_hash_array.h:443
void set_max_load_factor(float factor)
Sets a new maximum load factor.
Definition template_hash_array.h:327
const_iterator_t cbegin() const
Get a constant iterator to the beginning of the hash_array.
Definition template_hash_array.h:437
iterator_t end()
Get an iterator to the end of the hash_array.
Definition template_hash_array.h:419
float max_load_factor() const
Returns the maximum load factor.
Definition template_hash_array.h:321
Concept to check if a type is a valid allocator for a given bucket type.
Definition template_hash_array.h:69
Concept to check if a type is a valid bucket type.
Definition template_hash_array.h:35
Concept to check if a type is a valid hash function for a given Key type.
Definition hash_array.h:22
Concept to check if a type is a valid key adapter.
Definition hash_array.h:35
Definition comptime_map.h:11
Definition hash_array.h:67
bool eql(const key_t &key, const key_id_t &id) const
Definition hash_array.h:68
adapter_t adapter
Definition hash_array.h:70
Definition hash_array.h:73
hash_t hasher
Definition hash_array.h:76
std::size_t hash(const key_t &key)
Definition hash_array.h:74