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

Hashing with random tables, beyond the book. More...

Files

file  ADS/dictionary/RandomHashing.h
 Hashing with random tables, beyond the book:

Classes

class  ADS::SplitMix64
 the generator SplitMix64, a UniformRandomBitGenerator More...
class  ADS::ZobristTable
 a random word for each pair \( ( f , v ) \) of a feature and a value More...
class  ADS::TabulationHash
 the simple tabulation hashing of the keys of 64 bits More...

Functions

constexpr std::uint64_t ADS::splitmix64 (std::uint64_t x)
 the mix of SplitMix64: a bijection of the words of 64 bits
constexpr std::uint64_t ADS::fibonacciPlace (std::uint64_t h, int b)
 the place of the hash \( h \) in a table of \( 2^b \) places, its top \( b \) bits after the product by \( \lfloor 2^{64} / \phi \rfloor \)

Detailed description

Hashing with random tables, beyond the book.

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

Function documentation

◆ fibonacciPlace()

std::uint64_t ADS::fibonacciPlace ( std::uint64_t h,
int b )
nodiscardconstexpr

the place of the hash \( h \) in a table of \( 2^b \) places, its top \( b \) bits after the product by \( \lfloor 2^{64} / \phi \rfloor \)

In pseudocode (section 6.4 of TAOCP, the multiplicative hashing):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{fibonacciPlace}( h , b ) \cr 2 & \quad \textbf{return}\ \lfloor ( h \lfloor 2^{64} / \phi \rfloor \bmod 2^{64} ) / 2^{64 - b} \rfloor \end{array}} \]

Precondition
\( 1 \le b \le 64 \)

◆ splitmix64()

std::uint64_t ADS::splitmix64 ( std::uint64_t x)
nodiscardconstexpr

the mix of SplitMix64: a bijection of the words of 64 bits

In pseudocode (Steele, Lea and Flood, beyond the book), the arithmetic modulo \( 2^{64} \), \( \gg \) the shift to the right; each step is a bijection, a sum, a product by an odd constant or \( x \oplus ( x \gg s ) \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{splitmix64}( x ) \cr 2 & \quad x \gets x + \lfloor 2^{64} / \phi \rfloor \cr 3 & \quad x \gets ( x \oplus ( x \gg 30 ) ) \cdot \mathrm{BF58476D1CE4E5B9}_{16} \cr 4 & \quad x \gets ( x \oplus ( x \gg 27 ) ) \cdot \mathrm{94D049BB133111EB}_{16} \cr 5 & \quad \textbf{return}\ x \oplus ( x \gg 31 ) \end{array}} \]