Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::GenLinearHashTable< Key, BucketType, Cmp > Class Template Reference

Generic linear hash table. More...

#include <tpl_linHash.H>

Inheritance diagram for Aleph::GenLinearHashTable< Key, BucketType, Cmp >:
[legend]
Collaboration diagram for Aleph::GenLinearHashTable< Key, BucketType, Cmp >:
[legend]

Classes

class  Iterator
 

Public Types

using Hash_Fct = std::function< size_t(const Key &)>
 The hash function type.
 
using Hash_Fct_Ptr = size_t(*)(const Key &)
 
using Bucket = BucketType< Key >
 The bucket type.
 
using Key_Type = Key
 
using Item_Type = Key
 

Public Member Functions

void set_hash_fct (Hash_Fct fct) noexcept
 Set the internal hash function.
 
void set_hash_fct (Hash_Fct_Ptr fct) noexcept
 
Hash_Fct get_hash_fct () const noexcept
 
Cmp & get_compare () noexcept
 
const Cmp & get_compare () const noexcept
 
float current_alpha () const noexcept
 return the current table load
 
 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 swap (GenLinearHashTable &other) noexcept
 
void empty () noexcept
 Empty the entire table.
 
 ~GenLinearHashTable ()
 
Bucketsearch (const Key &key) const noexcept
 Search for key in the linear hash table.
 
const size_tsize () const noexcept
 Returns the number of elements in the table.
 
bool is_empty () const noexcept
 return true is table is empty
 
const size_tcapacity () const noexcept
 Returns the table capacity.
 
const size_tbusy_slots () const noexcept
 Returns the number of busy slots in the table.
 
const size_texpansions () const noexcept
 Returns the expansion level performed on the table.
 
Bucketinsert (Bucket *bucket)
 Insert bucket in the table.
 
Bucketsearch_or_insert (Bucket *bucket)
 
size_t resize (size_t) noexcept
 Provided for generic programming compatibility.
 
Bucketremove (Bucket *bucket) noexcept
 Remove bucket from table.
 
void print ()
 
- Public Member Functions inherited from HashStats< HashTbl >
Stats stats () const
 Computes statistics about chain length distribution.
 
void print_stats (const Stats &stats) const
 Prints statistics to standard output.
 
void set_upper_alpha (float __upper_alpha)
 Sets the upper load factor threshold.
 
void set_lower_alpha (float __lower_alpha)
 Sets the lower load factor threshold.
 
constexpr float get_lower_alpha () const noexcept
 Returns the lower load factor threshold.
 
constexpr float get_upper_alpha () const noexcept
 Returns the upper load factor threshold.
 

Protected Member Functions

 GenLinearHashTable (size_t __len, Hash_Fct __hash_fct, Cmp __cmp, float __lower_alpha, float __upper_alpha, bool __remove_all_buckets, bool)
 

Protected Attributes

Hash_Fct hash_fct
 
Cmp cmp
 
float upper_alpha
 
float lower_alpha
 
size_t len
 

Private Types

using BucketList = Dnode< Key >
 
using BucketItor = typename Dnode< Key >::Iterator
 

Private Member Functions

size_t call_hash_fct (const Key &key) const
 
void expand ()
 
void contract () noexcept
 
Bucketsearch_in_bucket_list (BucketList *list, const Key &key) const
 
Bucketremove_bucket (Bucket *bucket) noexcept
 

Static Private Member Functions

static size_t multiply_by_two (size_t n) noexcept
 
static size_t divide_by_two (size_t n) noexcept
 

Private Attributes

DynArray< BucketListtable
 
Dlink entries_list
 
size_t M
 
size_t N
 
size_t busy_slots_counter
 
bool remove_all_buckets
 
size_t p
 
size_t l
 
size_t MP
 
size_t MM
 

Friends

class HashStats< GenLinearHashTable< Key, BucketType, Cmp > >
 

Detailed Description

template<typename Key, template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
class Aleph::GenLinearHashTable< Key, BucketType, Cmp >

Generic linear hash table.

Basically, a linear hash table is a hash table with collision resolution by separate chaining but with the difference that the table size increases dynamically to ensure that the load factor, typically called \(\alpha\), is bounded between two lower and upper values, respectively.

Internally, the table uses a dynamic array of type DynArray. This leads to memory savings for table entries that have not been written.

This type is generic and is not intended to be used directly. Instead, use LinearHashTable or LinearHashTableVtl depending on whether you want buckets without or with a virtual destructor.

Parameters
Keythe key type by which the table is indexed.
BucketTypethe bucket type between LinHashBucket or LinHashBucketVtl.
Cmpcomparison class between keys.
See also
DynArray LinearHashTable LinearHashTableVtl

Definition at line 156 of file tpl_linHash.H.

Member Typedef Documentation

◆ Bucket

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::Bucket = BucketType<Key>

The bucket type.

Definition at line 169 of file tpl_linHash.H.

◆ BucketItor

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::BucketItor = typename Dnode<Key>::Iterator
private

Definition at line 179 of file tpl_linHash.H.

◆ BucketList

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::BucketList = Dnode<Key>
private

Definition at line 177 of file tpl_linHash.H.

◆ Hash_Fct

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::Hash_Fct = std::function<size_t(const Key &)>

The hash function type.

Must return pseudo-random positive values, between zero and the largest possible number.

Definition at line 165 of file tpl_linHash.H.

◆ Hash_Fct_Ptr

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::Hash_Fct_Ptr = size_t (*) (const Key &)

Definition at line 166 of file tpl_linHash.H.

◆ Item_Type

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::Item_Type = Key

Definition at line 173 of file tpl_linHash.H.

◆ Key_Type

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
using Aleph::GenLinearHashTable< Key, BucketType, Cmp >::Key_Type = Key

Definition at line 171 of file tpl_linHash.H.

Constructor & Destructor Documentation

◆ GenLinearHashTable() [1/2]

◆ GenLinearHashTable() [2/2]

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
Aleph::GenLinearHashTable< Key, BucketType, Cmp >::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 
)
inline

Instantiate a generic linear hash table.

Instantiate a generic linear hash table of size len.

Parameters
[in]leninitial and minimum table size.
[in]hash_fcthash function.
[in]cmpcomparison functor for keys.
[in]lower_alphalower threshold at which the table should contract.
[in]upper_alphaupper threshold at which the table should expand.
[in]remove_all_bucketsif true, then the table's buckets are freed. Otherwise, they remain intact. By default the value is true.
[in]with_resizeif true, the table will resize automatically based on load factors.
Exceptions
length_errorif len is equal or greater than the maximum dimension allowed for a dynamic array.
domain_errorif upper_alpha is less than or equal to lower_alpha.
bad_allocif there is not enough memory
overflow_errorif an overflow occurs from DynArray (caused by its internal calculations).

Definition at line 373 of file tpl_linHash.H.

◆ ~GenLinearHashTable()

Member Function Documentation

◆ busy_slots()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
const size_t & Aleph::GenLinearHashTable< Key, BucketType, Cmp >::busy_slots ( ) const
inlinenoexcept

Returns the number of busy slots in the table.

Definition at line 471 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::busy_slots_counter.

Referenced by TEST(), and TEST().

◆ call_hash_fct()

◆ capacity()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
const size_t & Aleph::GenLinearHashTable< Key, BucketType, Cmp >::capacity ( ) const
inlinenoexcept

Returns the table capacity.

Definition at line 468 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::MP.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ contract()

◆ current_alpha()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
float Aleph::GenLinearHashTable< Key, BucketType, Cmp >::current_alpha ( ) const
inlinenoexcept

return the current table load

Definition at line 327 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::MP, and Aleph::GenLinearHashTable< Key, BucketType, Cmp >::N.

Referenced by TEST().

◆ divide_by_two()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
static size_t Aleph::GenLinearHashTable< Key, BucketType, Cmp >::divide_by_two ( size_t  n)
inlinestaticprivatenoexcept

◆ empty()

◆ expand()

◆ expansions()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
const size_t & Aleph::GenLinearHashTable< Key, BucketType, Cmp >::expansions ( ) const
inlinenoexcept

Returns the expansion level performed on the table.

Definition at line 474 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::l.

Referenced by TEST(), TEST(), and TEST().

◆ get_compare() [1/2]

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
const Cmp & Aleph::GenLinearHashTable< Key, BucketType, Cmp >::get_compare ( ) const
inlinenoexcept

◆ get_compare() [2/2]

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
Cmp & Aleph::GenLinearHashTable< Key, BucketType, Cmp >::get_compare ( )
inlinenoexcept

Definition at line 322 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::cmp.

Referenced by TEST().

◆ get_hash_fct()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
Hash_Fct Aleph::GenLinearHashTable< Key, BucketType, Cmp >::get_hash_fct ( ) const
inlinenoexcept

Definition at line 320 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::hash_fct.

Referenced by TEST().

◆ insert()

◆ is_empty()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
bool Aleph::GenLinearHashTable< Key, BucketType, Cmp >::is_empty ( ) const
inlinenoexcept

return true is table is empty

Definition at line 465 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::N.

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ multiply_by_two()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
static size_t Aleph::GenLinearHashTable< Key, BucketType, Cmp >::multiply_by_two ( size_t  n)
inlinestaticprivatenoexcept

◆ print()

◆ remove()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
Bucket * Aleph::GenLinearHashTable< Key, BucketType, Cmp >::remove ( Bucket bucket)
inlinenoexcept

Remove bucket from table.

Warning: it is not verified whether the bucket belongs to the table.

Definition at line 546 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::remove_bucket().

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ remove_bucket()

◆ resize()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
size_t Aleph::GenLinearHashTable< Key, BucketType, Cmp >::resize ( size_t  )
inlinenoexcept

Provided for generic programming compatibility.

Definition at line 516 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::MP.

Referenced by TEST().

◆ search()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
Bucket * Aleph::GenLinearHashTable< Key, BucketType, Cmp >::search ( const Key &  key) const
inlinenoexcept

◆ search_in_bucket_list()

◆ search_or_insert()

◆ set_hash_fct() [1/2]

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
void Aleph::GenLinearHashTable< Key, BucketType, Cmp >::set_hash_fct ( Hash_Fct  fct)
inlinenoexcept

Set the internal hash function.

Definition at line 310 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::hash_fct, and Aleph::maps().

Referenced by TEST().

◆ set_hash_fct() [2/2]

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
void Aleph::GenLinearHashTable< Key, BucketType, Cmp >::set_hash_fct ( Hash_Fct_Ptr  fct)
inlinenoexcept

◆ size()

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
const size_t & Aleph::GenLinearHashTable< Key, BucketType, Cmp >::size ( ) const
inlinenoexcept

Returns the number of elements in the table.

Definition at line 462 of file tpl_linHash.H.

References Aleph::GenLinearHashTable< Key, BucketType, Cmp >::N.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ swap()

Friends And Related Symbol Documentation

◆ HashStats< GenLinearHashTable< Key, BucketType, Cmp > >

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
friend class HashStats< GenLinearHashTable< Key, BucketType, Cmp > >
friend

Definition at line 126 of file tpl_linHash.H.

Member Data Documentation

◆ busy_slots_counter

◆ cmp

◆ entries_list

◆ hash_fct

◆ l

◆ len

◆ lower_alpha

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
float Aleph::GenLinearHashTable< Key, BucketType, Cmp >::lower_alpha
protected

◆ M

◆ MM

◆ MP

◆ N

◆ p

◆ remove_all_buckets

template<typename Key , template< class > class BucketType, class Cmp = Aleph::equal_to<Key>>
bool Aleph::GenLinearHashTable< Key, BucketType, Cmp >::remove_all_buckets
private

◆ table

◆ upper_alpha


The documentation for this class was generated from the following file: