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

\( h( s ) = \sum_i ( s_i + 1 ) x^i \bmod ( 2^{61} - 1 ) \), at a random point \( x \) More...

#include <ADS/dictionary/UniversalHashing.h>

Public member functions

 StringHash (std::uint64_t seed=1)
 a function with a random point \( x \), from the seed
std::uint64_t operator() (std::string_view s) const
 \( h( s ) \)

Detailed description

\( h( s ) = \sum_i ( s_i + 1 ) x^i \bmod ( 2^{61} - 1 ) \), at a random point \( x \)

Constructor and destructor documentation

◆ StringHash()

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

a function with a random point \( x \), from the seed

Member function documentation

◆ operator()()

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

\( h( s ) \)

In pseudocode (chapter 8 of Ferragina), by the rule of Horner from the last character, \( p = 2^{61} - 1 \) and each character counted one more, so that the character 0 counts:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ h( s ) \cr 2 & \quad h \gets 0 \cr 3 & \quad \textbf{for}\ i \gets |s| - 1\ \textbf{downto}\ 0 \ \textbf{do}\ h \gets ( h x + s_i + 1 ) \bmod p \cr 4 & \quad \textbf{return}\ h \end{array}} \]

Postcondition
the result is below \( 2^{61} - 1 \)

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