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

the hash code of the arrays and of the strings of section 5.3.3 of Morin's book, a polynomial over the prime field of \( p = 2^{61} - 1 \) with an end marker, \( h( x_0 , \ldots , x_{r-1} ) = ( \sum_i x_i z^i + ( p - 1 ) z^r ) \bmod p \) More...

#include <ADS/dictionary/UniversalHashing.h>

Public member functions

 SequenceHash (std::uint64_t seed=1)
 a function with a random point \( z \) and a random odd multiplier for the reduction of the words, from the seed
std::uint64_t operator() (std::span< const std::uint64_t > x) const
 \( h \) of an array of words, each reduced first to 60 bits by the multiplicative hashing [see MultiplicativeHash], so that it lies in \( \{ 0 , \ldots , p - 2 \} \) and \( p - 1 \) marks the end: two distinct arrays, the longer of \( r \) words, collide with probability at most \( 2 / 2^{60} + r / ( p - 1 ) \) (the point \( z \) drawn in \( [ 1 , p ) \))
std::uint64_t operator() (std::string_view s) const
 \( h \) of a string, its bytes \( x_i < p - 1 \) taken as they are: two distinct strings, the longer of \( r \) bytes, collide with probability at most \( r / ( p - 1 ) \) (Theorem 5.5 of Morin's book, \( z \) drawn in \( [ 1 , p ) \))

Detailed description

the hash code of the arrays and of the strings of section 5.3.3 of Morin's book, a polynomial over the prime field of \( p = 2^{61} - 1 \) with an end marker, \( h( x_0 , \ldots , x_{r-1} ) = ( \sum_i x_i z^i + ( p - 1 ) z^r ) \bmod p \)

Constructor and destructor documentation

◆ SequenceHash()

ADS::SequenceHash::SequenceHash ( std::uint64_t seed = 1)
explicit

a function with a random point \( z \) and a random odd multiplier for the reduction of the words, from the seed

Member function documentation

◆ operator()() [1/2]

std::uint64_t ADS::SequenceHash::operator() ( std::span< const std::uint64_t > x) const
nodiscard

\( h \) of an array of words, each reduced first to 60 bits by the multiplicative hashing [see MultiplicativeHash], so that it lies in \( \{ 0 , \ldots , p - 2 \} \) and \( p - 1 \) marks the end: two distinct arrays, the longer of \( r \) words, collide with probability at most \( 2 / 2^{60} + r / ( p - 1 ) \) (the point \( z \) drawn in \( [ 1 , p ) \))

In pseudocode (section 5.3.3 of Morin's book), by the rule of Horner from the end marker:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ h( x_0 , \ldots , x_{r-1} ) \cr 2 & \quad h \gets p - 1 \cr 3 & \quad \textbf{for}\ i \gets r - 1\ \textbf{downto}\ 0\ \textbf{do} \ h \gets ( h z + \lfloor ( a x_i \bmod 2^{64} ) / 2^4 \rfloor ) \bmod p \cr 4 & \quad \textbf{return}\ h \end{array}} \]

◆ operator()() [2/2]

std::uint64_t ADS::SequenceHash::operator() ( std::string_view s) const
nodiscard

\( h \) of a string, its bytes \( x_i < p - 1 \) taken as they are: two distinct strings, the longer of \( r \) bytes, collide with probability at most \( r / ( p - 1 ) \) (Theorem 5.5 of Morin's book, \( z \) drawn in \( [ 1 , p ) \))


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