129using namespace Aleph;
150 template <
typename Key,
class BucketType,
class Cmp>
159 using Hash_Fct = std::function<size_t(
const Key &)>;
197 const bool remove_all,
const bool resize)
260 other.table =
nullptr;
263 other.busy_slots_counter = 0;
285 other.table =
nullptr;
288 other.busy_slots_counter = 0;
296 for (
size_t i = 0; i <
len; ++i)
321 for (
BucketItor it(list); it.has_curr(); it.next_ne())
322 if (
auto *bucket =
static_cast<Bucket *
>(it.get_curr());
cmp(key, bucket->get_key()))
351 template <
typename HashFunc,
typename SearchKey>
358 if (
auto *bucket =
static_cast<Bucket *
>(it.get_curr());
387 auto & list =
table[i];
409 auto & list =
table[i];
440 const auto idx =
hash_fct(bucket->get_key()) %
len;
480 for (
size_t i = 0; i <
old_size; ++i)
504 assert(bucket !=
nullptr);
518 if (
auto *node =
static_cast<Bucket *
>(
itor.get_curr());
cmp(bucket->get_key(), node->get_key()))
574 <<
"hash table iterator overflow";
636 <<
"hash table iterator underflow";
687 catch (
const std::overflow_error &)
748 <<
"hash table iterator underflow";
751 <<
"hash table iterator overflow";
767 <<
"hash table iterator overflow";
780 <<
"hash table iterator underflow";
801 template <
typename Key>
812 template <
typename Key>
835 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
855 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
C++20 concepts for constraining comparison functors.
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
Doubly linked circular list node.
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
Returns the current bucket without exception.
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
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
bool contains(const Key &key) const noexcept
Checks if a key exists in the table.
size_t(*)(const Key &) Hash_Fct_Ptr
GenLhashTable(GenLhashTable &&other) noexcept
Bucket * search_in_bucket_list(BucketList &list, const Key &key) const
void clear() noexcept
Empties the container.
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.
GenLhashTable(size_t table_size=Primes::DefaultPrime, Hash_Fct_Ptr hash_fct=Aleph::dft_hash_ptr_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 * 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.
Equivalence relation constraint for equality comparators.
Doubly linked circular list implementation.
Common hash table utilities and base classes.
Common operations for open addressing hash tables (CRTP mixin).
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
const float hash_default_upper_alpha
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
const float hash_default_lower_alpha
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.