ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::DotProductHash Class Reference

\( h( k ) = \sum_i a_i k_i \bmod m \), the \( k_i \) being the digits of \( k \) in base \( m \) More...

#include <ADS/dictionary/UniversalHashing.h>

Public member functions

 DotProductHash (std::uint64_t m, int r, std::uint64_t seed=1)
 a function with \( r \) random digits \( a_i \), from the seed
 DotProductHash (std::uint64_t m, std::vector< std::uint64_t > a)
 the function of the digits \( a \)
std::uint64_t operator() (std::uint64_t k) const
 \( h( k ) \)
std::uint64_t universe (void) const
 the size \( m^r \) of the universe, or 0 if it exceeds \( 2^{64} - 1 \)

Detailed description

\( h( k ) = \sum_i a_i k_i \bmod m \), the \( k_i \) being the digits of \( k \) in base \( m \)

Constructor and destructor documentation

◆ DotProductHash() [1/2]

ADS::DotProductHash::DotProductHash ( std::uint64_t m,
int r,
std::uint64_t seed = 1 )

a function with \( r \) random digits \( a_i \), from the seed

Precondition
\( 2 \le m \le 2^{32} \) and \( r \ge 1 \)

◆ DotProductHash() [2/2]

ADS::DotProductHash::DotProductHash ( std::uint64_t m,
std::vector< std::uint64_t > a )

the function of the digits \( a \)

Precondition
\( 2 \le m \le 2^{32} \), \( a \) not empty, each digit below \( m \)

Member function documentation

◆ operator()()

std::uint64_t ADS::DotProductHash::operator() ( std::uint64_t k) const
nodiscard

\( h( k ) \)

In pseudocode (chapter 8 of Ferragina):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ h( k ) \cr 2 & \quad s \gets 0 \cr 3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ r - 1\ \textbf{do} \cr 4 & \qquad s \gets ( s + a_i ( k \bmod m ) ) \bmod m;\ k \gets \lfloor k / m \rfloor \cr 5 & \quad \textbf{return}\ s \end{array}} \]

Precondition
\( k < m^r \)
Postcondition
the result is below \( m \)

◆ universe()

std::uint64_t ADS::DotProductHash::universe ( void ) const
nodiscard

the size \( m^r \) of the universe, or 0 if it exceeds \( 2^{64} - 1 \)


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