ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
TableSize.h

The sizes of the hash tables that restructure themselves (section 7.4). More...

Files

file  ADS/dictionary/TableSize.h
 The sizes of the hash tables that restructure themselves (section 7.4): a size that is a power of two doubles or halves, any other one goes to the first prime not smaller than its double or its half, so that the inspections of an OpenHashTable that need a prime size, or a size coprime with their step, keep working.

Concepts

concept  ADS::PlaceHash
 a hash \( H \) that maps a key straight to a place of a table of \( m = 2^d \) places by h.place( k , m ), as the multiplicative hashing of section 5.1.1 of Morin's book and the tabulation hashing of its section 5.2.3 do with the \( d \) most significant bits of a product or of a XOR [see MultiplicativeHash in UniversalHashing.h and TabulationHash in RandomHashing.h]; the tables use it in place of \( h( k ) \bmod m \), whose low bits are the worst ones of a product

Functions

bool ADS::is_prime (std::size_t n)
 true if \( n \) is prime, by trial division up to \( \sqrt{n} \)
std::size_t ADS::next_prime (std::size_t n)
 the smallest prime not smaller than \( n \), by trial divisions
bool ADS::is_pow2 (std::size_t n)
 true if \( n \) is a power of two, i.e., \( n \ne 0 \) and n & ( n - 1 ) is 0
std::size_t ADS::resized (std::size_t m, bool grow, std::size_t m0)
 the size after a doubling, or after a halving down to \( m_0 \)

Detailed description

The sizes of the hash tables that restructure themselves (section 7.4).

The definitions, the invariants and the costs of the area are in Theory of dictionaries.

Function documentation

◆ is_pow2()

bool ADS::is_pow2 ( std::size_t n)

true if \( n \) is a power of two, i.e., \( n \ne 0 \) and n & ( n - 1 ) is 0

◆ is_prime()

bool ADS::is_prime ( std::size_t n)

true if \( n \) is prime, by trial division up to \( \sqrt{n} \)

◆ next_prime()

std::size_t ADS::next_prime ( std::size_t n)

the smallest prime not smaller than \( n \), by trial divisions

◆ resized()

std::size_t ADS::resized ( std::size_t m,
bool grow,
std::size_t m0 )

the size after a doubling, or after a halving down to \( m_0 \)

In pseudocode (section 7.4, with the sizes beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{resized}( m , \mathit{grow} , m_0 ) \cr 2 & \quad \textbf{if}\ m \text{ is a power of two }\ \textbf{then} \cr 3 & \qquad \textbf{if}\ \mathit{grow}\ \textbf{then return}\ 2 m \ \textbf{else return}\ \max\{ \lfloor m / 2 \rfloor , m_0 \} \cr 4 & \quad \textbf{if}\ \mathit{grow}\ \textbf{then return} \ \mathrm{nextPrime}( 2 m ) \cr 5 & \quad \textbf{return}\ \max\{ \mathrm{nextPrime}( \lfloor m / 2 \rfloor ) , m_0 \} \end{array}} \]

Precondition
\( 0 < m_0 \le m \)
Postcondition
not below \( m_0 \), and a power of two (or \( m_0 \)) if \( m \) is one