128using namespace Aleph;
149 template <
typename Key,
class BucketType,
class Cmp>
195 const bool remove_all,
const bool resize)
258 other.table =
nullptr;
261 other.busy_slots_counter = 0;
283 other.table =
nullptr;
286 other.busy_slots_counter = 0;
294 for (
size_t i = 0; i <
len; ++i)
304 for (
BucketItor it(list); it.has_curr(); it.next_ne())
305 if (
auto *bucket =
static_cast<Bucket *
>(it.get_curr());
cmp(key, bucket->get_key()))
334 template <
typename HashFunc,
typename SearchKey>
341 if (
auto *bucket =
static_cast<Bucket *
>(it.get_curr());
370 auto & list =
table[i];
392 auto & list =
table[i];
423 const auto idx =
hash_fct(bucket->get_key()) %
len;
463 for (
size_t i = 0; i <
old_size; ++i)
487 assert(bucket !=
nullptr);
501 if (
auto *node =
static_cast<Bucket *
>(
itor.get_curr());
cmp(bucket->get_key(), node->get_key()))
557 <<
"hash table iterator overflow";
619 <<
"hash table iterator underflow";
670 catch (
const std::overflow_error &)
720 <<
"hash table iterator underflow";
723 <<
"hash table iterator overflow";
739 <<
"hash table iterator overflow";
752 <<
"hash table iterator underflow";
773 template <
typename Key>
784 template <
typename Key>
807 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
826 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
Exception handling system with formatted messages for Aleph-w.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
void put_itor_at_the_end(Itor &it) noexcept
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
void append(Dlink *node) noexcept
Insert node before this.
Iterator on a list of Dnode objects.
Iterator over a GenLhashTable hash table.
void reset_last() noexcept
Reset the iterator to the last bucket.
void reset_first() noexcept
Reset the iterator to the first bucket.
Iterator()=default
Instantiate an empty iterator.
Bucket * get_curr()
Returns the current bucket.
void locate_prev_available_entry()
void locate_next_available_bucket_ne() noexcept
void locate_prev_available_bucket_ne() noexcept
void locate_next_available_entry_ne() noexcept
void prev_ne() noexcept
Moves the iterator back by one bucket.
Bucket * Item_Type
Item type returned by get_curr().
void next_ne() noexcept
Advances the iterator by one bucket.
void locate_next_available_entry()
Bucket * get_curr_ne() noexcept
GenLhashTable * hash_table
Iterator(const GenLhashTable &table) noexcept
Instantiate an iterator over the hash table.
void locate_prev_available_entry_ne() noexcept
bool has_curr() const noexcept
Returns true if the iterator has a current bucket.
void locate_prev_available_bucket()
long get_pos() const noexcept
void locate_next_available_bucket()
Generic hash table with collision resolution by separate chaining.
Bucket * remove(Bucket *bucket) noexcept
Removes bucket from the table.
GenLhashTable & operator=(const GenLhashTable &)=delete
GenLhashTable(size_t table_size=Primes::DefaultPrime, Hash_Fct_Ptr hash_fct=Aleph::dft_hash_fct< Key >, Cmp cmp=Cmp(), float lower_alpha=hash_default_lower_alpha, float upper_alpha=hash_default_upper_alpha, bool remove_all_buckets=true, bool with_resize=true)
Instantiate a generic hash table.
Bucket * insert(Bucket *bucket)
Inserts bucket into the table and returns its address if the key is not already in the table; otherwi...
Hash_Fct get_hash_fct() const noexcept
size_t(*)(const Key &) Hash_Fct_Ptr
GenLhashTable(GenLhashTable &&other) noexcept
Bucket * search_in_bucket_list(BucketList &list, const Key &key) const
typename Dnode< Key >::Iterator BucketItor
const size_t & get_num_busy_slots() const noexcept
Returns the number of occupied entries in the array.
void empty() noexcept
Empties the hash table; frees memory of all buckets.
const Cmp & get_compare() const
float current_alpha() const noexcept
return the current table load
Bucket * remove_bucket(Bucket *bucket) noexcept
const size_t & size() const noexcept
Returns the number of elements contained in the table.
Bucket * search_or_insert(Bucket *bucket)
void set_hash_fct(Hash_Fct fct) noexcept
Set the internal hash function.
virtual ~GenLhashTable()
Frees the table memory and, if remove_all_buckets is true (specified in the constructor),...
const size_t & capacity() const noexcept
Returns the table capacity.
std::function< size_t(const Key &)> Hash_Fct
void swap(GenLhashTable &other) noexcept
GenLhashTable(const GenLhashTable &)=delete
GenLhashTable(const size_t table_size, Hash_Fct hash_f, Cmp cpm_fct, const float lower, const float upper, const bool remove_all, const bool resize)
Bucket * search_next(Bucket *bucket) const
Returns the next bucket that collides with bucket.
Bucket * search(const Key &key) const noexcept
Search in the table for a bucket with key.
size_t busy_slots_counter
constexpr bool is_empty() const noexcept
GenLhashTable & operator=(GenLhashTable &&other) noexcept
Bucket * search_with_custom_hash(HashFunc hash_func, const SearchKey &search_key) const noexcept
Helper method for derived classes to perform custom heterogeneous searches.
size_t resize(const size_t new_size)
Resizes the hash table to new_size and re-locates keys.
void set_hash_fct(Hash_Fct_Ptr fct) noexcept
CRTP mixin providing statistics and configuration for chained hash tables.
Doubly linked circular list implementation.
Common hash table utilities and base classes.
Collection of general-purpose hash functions.
Common operations for open addressing hash tables (CRTP mixin).
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
const float hash_default_upper_alpha
const float hash_default_lower_alpha
DynList< T > maps(const C &c, Op op)
Classic map operation.
const unsigned long DefaultPrime
Default prime number used when no specific size is requested.
size_t next_prime(unsigned long n)
Find the smallest prime number >= n from the database.
Prime number utilities for hash tables and mathematical operations.
Bucket with virtual destructor for a hash table with collision resolution by separate chaining.
virtual ~LhashBucketVtl()=default
Virtual destructor.
Generic hash table with collision resolution by separate chaining and buckets with virtual destructor...
Generic hash table with collision resolution by separate chaining and buckets without virtual destruc...
Lazy and scalable dynamic array implementation.