Aleph-w 7.10.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.
 
constexpr bool get_with_resize () const noexcept
 Returns whether the table resizes itself.
 
void set_with_resize (const bool with_resize) noexcept
 Turns the automatic resizing on or off.
 

Private Member Functions

HashTbl * me ()
 Returns a pointer to the derived class (CRTP pattern).
 
const HashTbl * const_me () const
 Returns a const pointer to the derived class (CRTP pattern).
 
size_t bucket_length (const size_t i) const
 Returns the length of the collision chain of bucket i.
 

Static Private Member Functions

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

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 1391 of file hashDry.H.

Member Function Documentation

◆ bucket_length()

template<class HashTbl >
size_t HashStats< HashTbl >::bucket_length ( const size_t  i) const
inlineprivate

Returns the length of the collision chain of bucket i.

Parameters
iBucket index, smaller than capacity().
Returns
Number of entries stored in bucket i.
Note
A lazily allocated table (a DynArray, as in linear hashing) may contain buckets that were never written. Such a bucket is empty, so it counts as zero instead of being read, which would throw.

Definition at line 1438 of file hashDry.H.

References HashStats< HashTbl >::const_me(), and Aleph::count().

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

◆ 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 1401 of file hashDry.H.

Referenced by HashStats< HashTbl >::bucket_length(), HashStats< HashTbl >::get_lower_alpha(), HashStats< HashTbl >::get_upper_alpha(), HashStats< HashTbl >::get_with_resize(), 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 1559 of file hashDry.H.

References HashStats< HashTbl >::const_me().

◆ 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 1564 of file hashDry.H.

References HashStats< HashTbl >::const_me().

◆ get_with_resize()

template<class HashTbl >
constexpr bool HashStats< HashTbl >::get_with_resize ( ) const
inlineconstexprnoexcept

Returns whether the table resizes itself.

Returns
true if the table grows and shrinks by itself.

Definition at line 1569 of file hashDry.H.

References HashStats< HashTbl >::const_me().

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

◆ 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 1396 of file hashDry.H.

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

◆ 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 1511 of file hashDry.H.

References HashStats< HashTbl >::Stats::avg, 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 1548 of file hashDry.H.

References ah_domain_error_if, and HashStats< HashTbl >::me().

Referenced by TEST().

◆ 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 1532 of file hashDry.H.

References ah_domain_error_if, and HashStats< HashTbl >::me().

Referenced by TEST().

◆ set_with_resize()

template<class HashTbl >
void HashStats< HashTbl >::set_with_resize ( const bool  with_resize)
inlinenoexcept

Turns the automatic resizing on or off.

As with the thresholds, the change applies from the next insertion or removal on: turning it on does not resize the table at once. Turned off, the table keeps its capacity, and its lists get longer as keys come in.

Parameters
with_resizetrue for the table to grow and shrink by itself.

Definition at line 1580 of file hashDry.H.

References HashStats< HashTbl >::me().

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

◆ 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.
Note
Buckets that a lazily allocated table never wrote count as empty chains; computing the statistics does not allocate them.

Definition at line 1470 of file hashDry.H.

References HashStats< HashTbl >::Stats::avg, HashStats< HashTbl >::bucket_length(), HashStats< HashTbl >::const_me(), HashStats< HashTbl >::Stats::lens, Aleph::DynArray< T >::reserve(), 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(), HashStats< HashTbl >::stats(), Aleph::adversarial_search_detail::store_adversarial_transposition(), and TEST().

◆ 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.
Note
touch() also extends lens.size() to i + 1, so every recorded length is inside the range that the statistics traverse. New entries start at zero.

Definition at line 1426 of file hashDry.H.

References Aleph::DynArray< T >::touch().

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


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