160using namespace Aleph;
181 template <
typename Key,
class BucketType,
class Cmp>
190 using Hash_Fct = std::function<size_t(
const Key &)>;
227 const float lower,
const float upper,
228 const bool remove_all,
const bool resize)
278 std::swap(
hash_fct, other.hash_fct);
279 std::swap(
table, other.table);
280 std::swap(
len, other.len);
284 std::swap(
N, other.N);
323 other.table =
nullptr;
326 other.busy_slots_counter = 0;
363 for (
size_t i = 0; i <
len; ++i)
365 delete static_cast<Bucket *
>(itor.del_ne());
388 for (
BucketItor it(list); it.has_curr(); it.next_ne())
389 if (
auto *bucket =
static_cast<Bucket *
>(it.get_curr());
cmp(key, bucket->get_key()))
418 template <
typename HashFunc,
typename SearchKey>
420 const SearchKey & search_key)
const noexcept
422 if (
len == 0) [[unlikely]]
425 const auto bucket_idx = hash_func(search_key) %
len;
428 if (
auto *bucket =
static_cast<Bucket *
>(it.get_curr());
429 cmp(bucket->get_key(), search_key))
483 float load() const noexcept {
return 1.0 *
N /
len; }
505 if (
table ==
nullptr) [[unlikely]]
509 auto & list =
table[i];
531 if (
table ==
nullptr) [[unlikely]]
535 auto & list =
table[i];
557 if (
len == 0) [[unlikely]]
569 const auto idx =
hash_fct(bucket->get_key()) %
len;
600 catch (
const std::bad_alloc &)
638 size_t size = hash_dry_detail::checked_table_len<BucketList>(new_size);
641 size = hash_dry_detail::prime_table_len<BucketList>(2 *
size);
645 const size_t old_size =
len;
650 for (
size_t i = 0; i < old_size; ++i)
652 for (
BucketItor it(old_table[i]); it.has_curr(); )
674 assert(bucket !=
nullptr);
685 if (not itor.has_curr())
688 if (
auto *node =
static_cast<Bucket *
>(itor.get_curr());
cmp(bucket->get_key(), node->get_key()))
697 const size_t &
size() const noexcept {
return N; }
703 [[nodiscard]]
constexpr bool is_empty() const noexcept {
return N == 0; }
744 <<
"hash table iterator overflow";
806 <<
"hash table iterator underflow";
857 catch (
const std::overflow_error &)
918 <<
"hash table iterator underflow";
921 <<
"hash table iterator overflow";
937 <<
"hash table iterator overflow";
950 <<
"hash table iterator underflow";
971 template <
typename Key>
982 template <
typename Key>
1005 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
1025 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
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.
void set_hash_fct(Hash_Fct_Ptr fct)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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
Takes the lists and the buckets of other.
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; zero for a table without lists
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)
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
Swaps this table with other in constant time.
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.
float load() const noexcept
Bucket * search(const Key &key) const noexcept
Search in the table for a bucket with key.
void set_hash_fct(Hash_Fct fct)
Sets the hash function.
size_t busy_slots_counter
constexpr bool is_empty() const noexcept
GenLhashTable & operator=(GenLhashTable &&other) noexcept
Frees the buckets and the lists of this table, and takes those of other, with what rules them: the ha...
Bucket * search_with_custom_hash(HashFunc hash_func, const SearchKey &search_key) const noexcept
Helper method for derived classes to perform custom heterogeneous searches.
void make_default_lists()
size_t resize(const size_t new_size)
Resizes the table to new_size lists and places every bucket again.
Number Theoretic Transform over Z / MOD Z.
CRTP mixin providing statistics and configuration for chained hash tables.
Equivalence relation constraint for equality comparators.
Doubly linked circular list implementation.
void swap_compare(Cmp &a, Cmp &b) noexcept
Swaps the comparators of two hash tables.
Common hash table utilities and base classes.
Standard hash functions for Aleph types.
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
and
Check uniqueness with explicit hash + equality functors.
const float hash_default_lower_alpha
const unsigned long DefaultPrime
Default prime number used when no specific size is requested.
unsigned long next_prime(unsigned long n)
Find a prime >= n in the database, for hash table sizing.
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.