|
ADS
Algorithms and Data Structures
|
\( 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 ) \) | |
\( h( s ) = \sum_i ( s_i + 1 ) x^i \bmod ( 2^{61} - 1 ) \), at a random point \( x \)
|
explicit |
a function with a random point \( x \), from the seed
|
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}} \]