Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
HashStats< HashTbl > Class Template Reference

CRTP mixin providing statistics and configuration for chained hash tables. More...

#include <hashDry.H>

Inheritance diagram for HashStats< HashTbl >:
[legend]

Classes

struct  Stats
 Statistics about chain length distribution. More...
 

Public Member Functions

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.
 

Private Member Functions

HashTblme ()
 Returns a pointer to the derived class (CRTP pattern).
 
const HashTblconst_me () const
 Returns a const pointer to the derived class (CRTP pattern).
 

Static Private Member Functions

static void update_stat_len (DynArray< size_t > &lens, size_t i)
 Updates chain length histogram.
 

Private Attributes

float lower_alpha
 Lower load factor threshold for shrinking.
 
float upper_alpha
 Upper load factor threshold for growing.
 
size_t busy_slots_counter = 0
 Number of buckets with at least one entry.
 
size_t N = 0
 Total number of entries.
 

Detailed Description

template<class HashTbl>
class HashStats< HashTbl >

CRTP mixin providing statistics and configuration for chained hash tables.

This class provides statistics gathering and load factor configuration for hash tables using separate chaining (linked lists per bucket). It uses CRTP for static polymorphism.

Template Parameters
HashTblThe derived hash table class.
Provided Operations:
See also
LhashTable

Definition at line 984 of file hashDry.H.

Member Function Documentation

◆ const_me()

template<class HashTbl >
const HashTbl * HashStats< HashTbl >::const_me ( ) const
inlineprivate

Returns a const pointer to the derived class (CRTP pattern).

Returns
Const pointer to this object cast to const HashTbl*.

Definition at line 994 of file hashDry.H.

References Aleph::maps().

Referenced by HashStats< HashTbl >::print_stats(), and HashStats< HashTbl >::stats().

◆ get_lower_alpha()

template<class HashTbl >
constexpr float HashStats< HashTbl >::get_lower_alpha ( ) const
inlineconstexprnoexcept

Returns the lower load factor threshold.

Returns
The lower alpha threshold.

Definition at line 1134 of file hashDry.H.

References HashStats< HashTbl >::lower_alpha.

◆ get_upper_alpha()

template<class HashTbl >
constexpr float HashStats< HashTbl >::get_upper_alpha ( ) const
inlineconstexprnoexcept

Returns the upper load factor threshold.

Returns
The upper alpha threshold.

Definition at line 1139 of file hashDry.H.

References HashStats< HashTbl >::upper_alpha.

◆ me()

template<class HashTbl >
HashTbl * HashStats< HashTbl >::me ( )
inlineprivate

Returns a pointer to the derived class (CRTP pattern).

Returns
Pointer to this object cast to HashTbl*.

Definition at line 989 of file hashDry.H.

References Aleph::maps().

◆ print_stats()

template<class HashTbl >
void HashStats< HashTbl >::print_stats ( const Stats stats) const
inline

Prints statistics to standard output.

Displays formatted statistics including capacity, size, busy slots, average chain length, standard deviation, load factor, and chain length distribution.

Parameters
statsStatistics object to print.

Definition at line 1086 of file hashDry.H.

References HashStats< HashTbl >::Stats::avg, HashStats< HashTbl >::busy_slots_counter, HashStats< HashTbl >::const_me(), HashStats< HashTbl >::Stats::lens, Aleph::DynArray< T >::size(), sqrt(), HashStats< HashTbl >::stats(), and HashStats< HashTbl >::Stats::var.

◆ set_lower_alpha()

template<class HashTbl >
void HashStats< HashTbl >::set_lower_alpha ( float  __lower_alpha)
inline

Sets the lower load factor threshold.

When the load factor drops below this value after a removal, the table automatically shrinks (if auto-resize is enabled).

Parameters
__lower_alphaNew lower threshold.
Exceptions
std::domain_errorIf __lower_alpha >= upper_alpha.

Definition at line 1123 of file hashDry.H.

References ah_domain_error_if, HashStats< HashTbl >::lower_alpha, Aleph::maps(), and HashStats< HashTbl >::upper_alpha.

◆ set_upper_alpha()

template<class HashTbl >
void HashStats< HashTbl >::set_upper_alpha ( float  __upper_alpha)
inline

Sets the upper load factor threshold.

When the load factor exceeds this value, the table automatically grows (if auto-resize is enabled).

Parameters
__upper_alphaNew upper threshold.
Exceptions
std::domain_errorIf __upper_alpha <= lower_alpha.

Definition at line 1107 of file hashDry.H.

References ah_domain_error_if, HashStats< HashTbl >::lower_alpha, Aleph::maps(), and HashStats< HashTbl >::upper_alpha.

◆ stats()

template<class HashTbl >
Stats HashStats< HashTbl >::stats ( ) const
inline

Computes statistics about chain length distribution.

Iterates through all buckets to compute the distribution of chain lengths, along with mean and variance.

Returns
Stats object containing chain length statistics.
Complexity: O(n + m) where n is entries and m is capacity.

Definition at line 1040 of file hashDry.H.

References HashStats< HashTbl >::Stats::avg, HashStats< HashTbl >::const_me(), Aleph::count(), HashStats< HashTbl >::Stats::lens, Aleph::DynArray< T >::size(), HashStats< HashTbl >::stats(), Aleph::sum(), HashStats< HashTbl >::update_stat_len(), and HashStats< HashTbl >::Stats::var.

Referenced by HashStats< HashTbl >::print_stats(), and HashStats< HashTbl >::stats().

◆ update_stat_len()

template<class HashTbl >
static void HashStats< HashTbl >::update_stat_len ( DynArray< size_t > &  lens,
size_t  i 
)
inlinestaticprivate

Updates chain length histogram.

Parameters
lensThe histogram array to update.
iThe chain length to record.

Definition at line 1021 of file hashDry.H.

References Aleph::DynArray< T >::exist(), and Aleph::DynArray< T >::touch().

Referenced by HashStats< HashTbl >::stats().

Member Data Documentation

◆ busy_slots_counter

template<class HashTbl >
size_t HashStats< HashTbl >::busy_slots_counter = 0
private

Number of buckets with at least one entry.

Definition at line 998 of file hashDry.H.

Referenced by HashStats< HashTbl >::print_stats().

◆ lower_alpha

template<class HashTbl >
float HashStats< HashTbl >::lower_alpha
private

Lower load factor threshold for shrinking.

Definition at line 996 of file hashDry.H.

Referenced by HashStats< HashTbl >::get_lower_alpha(), HashStats< HashTbl >::set_lower_alpha(), and HashStats< HashTbl >::set_upper_alpha().

◆ N

template<class HashTbl >
size_t HashStats< HashTbl >::N = 0
private

Total number of entries.

Definition at line 999 of file hashDry.H.

◆ upper_alpha

template<class HashTbl >
float HashStats< HashTbl >::upper_alpha
private

Upper load factor threshold for growing.

Definition at line 997 of file hashDry.H.

Referenced by HashStats< HashTbl >::get_upper_alpha(), HashStats< HashTbl >::set_lower_alpha(), and HashStats< HashTbl >::set_upper_alpha().


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