79# define LINBUCKET_BODY(BUCKETNAME) \
85 BUCKETNAME(const BUCKETNAME & bucket) \
86 : Dnode<Key>(bucket) {} \
90 BUCKETNAME(const Key & key) \
91 : Dnode<Key>(key) {} \
93 Key & get_key() noexcept { return this->get_data(); } \
95 Dlink * get_link() noexcept { return &link; } \
97 DLINK_TO_BASE(BUCKETNAME, link);
107 template <
typename Key>
120 template <
typename Key>
154 template <
typename Key,
template <
class>
class BucketType,
157 :
public HashStats<GenLinearHashTable<Key, BucketType, Cmp>>
222 const auto i =
hash %
M;
243 const Key & key = bucket->get_key();
344 <<
"upper alpha must be greater than lower alpha";
379 bool with_resize =
true)
412 bucket->get_link()->del();
433 for (
BucketItor it(*list); it.has_curr(); it.next_ne())
436 if (
cmp (key, bucket->get_key()))
526 assert(bucket !=
nullptr);
533 if (
next->is_empty())
548 bucket->get_link()->del();
554 for (
size_t i = 0; i <
MP; ++i)
556 std::cout <<
"table[" << i <<
"] = [ ";
563 for (
BucketItor it(list); it.has_curr(); it.next_ne())
566 const Key & key = bucket->get_key();
567 std::cout << key <<
",";
570 std::cout <<
"]" <<
'\n';
658template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
680 template <
typename Key,
class Cmp = Aleph::equal_to<Key>>
Exception handling system with formatted messages for Aleph-w.
#define ah_length_error_if(C)
Throws std::length_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
void next_ne() noexcept
Move the iterator one position backward guaranteeing no exception.
Dlink * get_curr() const
Return the current node of iterator.
void next()
Move the iterator one position forward.
Dlink * del()
Remove from the list the current node and move the iterator one position forward.
void prev()
Move the iterator one position backward.
Dlink * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
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.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
Dlink * remove_first_ne() noexcept
Iterator on a list of Dnode objects.
Node belonging to a double circular linked list with header node.
T & append(const T &item)
Append a new item by copy.
GenLinearHashTable * hash_table
Iterator() noexcept
Instantiate an empty iterator.
Bucket * get_curr()
Return the current bucket.
Bucket * get_curr_ne() noexcept
Bucket * Item_Type
The element type returned by get_curr().
Iterator(const GenLinearHashTable &table) noexcept
Instantiate an iterator over the hash table.
long get_pos() const noexcept
Generic linear hash table.
const size_t & capacity() const noexcept
Returns the table capacity.
void swap(GenLinearHashTable &other) noexcept
std::function< size_t(const Key &)> Hash_Fct
The hash function type.
void set_hash_fct(Hash_Fct_Ptr fct) noexcept
DynArray< BucketList > table
static size_t divide_by_two(size_t n) noexcept
Bucket * remove_bucket(Bucket *bucket) noexcept
Cmp & get_compare() noexcept
const size_t & size() const noexcept
Returns the number of elements in the table.
bool is_empty() const noexcept
return true is table is empty
size_t busy_slots_counter
GenLinearHashTable(size_t len=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 linear hash table.
void empty() noexcept
Empty the entire table.
typename Dnode< Key >::Iterator BucketItor
static size_t multiply_by_two(size_t n) noexcept
const size_t & expansions() const noexcept
Returns the expansion level performed on the table.
size_t call_hash_fct(const Key &key) const
float current_alpha() const noexcept
return the current table load
Bucket * remove(Bucket *bucket) noexcept
Remove bucket from table.
BucketType< Key > Bucket
The bucket type.
const size_t & busy_slots() const noexcept
Returns the number of busy slots in the table.
Bucket * insert(Bucket *bucket)
Insert bucket in the table.
Hash_Fct get_hash_fct() const noexcept
size_t(*)(const Key &) Hash_Fct_Ptr
void set_hash_fct(Hash_Fct fct) noexcept
Set the internal hash function.
Bucket * search_or_insert(Bucket *bucket)
const Cmp & get_compare() const noexcept
GenLinearHashTable(size_t __len, Hash_Fct __hash_fct, Cmp __cmp, float __lower_alpha, float __upper_alpha, bool __remove_all_buckets, bool)
Bucket * search(const Key &key) const noexcept
Search for key in the linear hash table.
size_t resize(size_t) noexcept
Provided for generic programming compatibility.
Bucket * search_in_bucket_list(BucketList *list, const Key &key) const
constexpr bool is_empty() const noexcept
Return true if list is empty.
void concat_list(HTList &l) noexcept
Bucket with virtual destructor for a hash table with collision resolution by separate chaining.
virtual ~LinHashBucketVtl()
virtual destructor.
Bucket without virtual destructor for a hash table with collision resolution by separate chaining.
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
void next()
Advance all underlying iterators (bounds-checked).
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.
Prime number utilities for hash tables and mathematical operations.
Doubly linked list node with typed data.
Lazy and scalable dynamic array implementation.
#define LINBUCKET_BODY(BUCKETNAME)