ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::MultiplicativeHash< K, Code > Class Template Reference

the multiplicative hashing of section 5.1.1 of Morin's book, \( \mathrm{hash}( x ) = ( z x \bmod 2^w ) \operatorname{div} 2^{w-d} \) on a table of \( 2^d \) places, \( z \) a random odd word and \( x \) the hash code Code( k ) of the key More...

#include <ADS/dictionary/UniversalHashing.h>

Public member functions

 MultiplicativeHash (std::uint64_t seed=1, Code code=Code())
 a function with a random odd \( z \) of 64 bits, from the seed
std::uint64_t operator() (const K &k) const
 the product \( z x \bmod 2^{64} \), whose high bits are the hash
std::size_t place (const K &k, std::size_t m) const
 the place of \( k \) in a table of \( m = 2^d \) places, the \( d \) high bits of \( z x \bmod 2^{64} \) [see PlaceHash in TableSize.h]; two distinct codes collide with probability at most \( 2 / 2^d \) (Lemma 5.1 of Morin's book)
std::uint64_t multiplier (void) const
 the multiplier \( z \)

Static public member functions

static MultiplicativeHash ofMultiplier (std::uint64_t z, Code code=Code())
 the function of the multiplier \( z \)

Detailed description

template<class K = std::uint64_t, class Code = std::hash< K >>
class ADS::MultiplicativeHash< K, Code >

the multiplicative hashing of section 5.1.1 of Morin's book, \( \mathrm{hash}( x ) = ( z x \bmod 2^w ) \operatorname{div} 2^{w-d} \) on a table of \( 2^d \) places, \( z \) a random odd word and \( x \) the hash code Code( k ) of the key

Constructor and destructor documentation

◆ MultiplicativeHash()

template<class K = std::uint64_t, class Code = std::hash< K >>
ADS::MultiplicativeHash< K, Code >::MultiplicativeHash ( std::uint64_t seed = 1,
Code code = Code() )
explicit

a function with a random odd \( z \) of 64 bits, from the seed

Member function documentation

◆ multiplier()

template<class K = std::uint64_t, class Code = std::hash< K >>
std::uint64_t ADS::MultiplicativeHash< K, Code >::multiplier ( void ) const
inlinenodiscard

the multiplier \( z \)

◆ ofMultiplier()

template<class K = std::uint64_t, class Code = std::hash< K >>
MultiplicativeHash ADS::MultiplicativeHash< K, Code >::ofMultiplier ( std::uint64_t z,
Code code = Code() )
staticnodiscard

the function of the multiplier \( z \)

Precondition
\( z \) odd

◆ operator()()

template<class K = std::uint64_t, class Code = std::hash< K >>
std::uint64_t ADS::MultiplicativeHash< K, Code >::operator() ( const K & k) const
nodiscard

the product \( z x \bmod 2^{64} \), whose high bits are the hash

◆ place()

template<class K = std::uint64_t, class Code = std::hash< K >>
std::size_t ADS::MultiplicativeHash< K, Code >::place ( const K & k,
std::size_t m ) const
nodiscard

the place of \( k \) in a table of \( m = 2^d \) places, the \( d \) high bits of \( z x \bmod 2^{64} \) [see PlaceHash in TableSize.h]; two distinct codes collide with probability at most \( 2 / 2^d \) (Lemma 5.1 of Morin's book)

In pseudocode (section 5.1.1 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{place}( k , 2^d ) \cr 2 & \quad \textbf{return}\ ( z \cdot \mathrm{code}( k ) \bmod 2^w ) \operatorname{div} 2^{w-d} \end{array}} \]

Precondition
\( m \) is a power of two
Postcondition
the result is below \( m \)

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