The engineered hash functions of ADS, beyond the book.
More...
|
| file | ADS/dictionary/FastHash.h |
| | The engineered hash functions of ADS, beyond the book [see HashFunctions.h for those of section 7.1 and UniversalHashing.h for the universal classes]: hashes of 64 bits for the tables, the filters and the perfect hash functions, made of the folded product, the product of two words on 128 bits whose two halves are XORed [see foldedProduct()].
|
|
| struct | ADS::Product128 |
| | the product \( a b \) on 128 bits, its low and its high half More...
|
| struct | ADS::FastHash< T > |
| | the hash of the values of T, for the integers, the enumerations, the pointers, the floating point numbers (\( +0 \) and \( -0 \) the same) by hashWord(), and the strings by hashBytes() More...
|
| struct | ADS::FastHash< std::string_view > |
| | the hash of a string, by its bytes; any std::string_view, std::string and C string with the same characters hash the same More...
|
| struct | ADS::FastHash< std::string > |
| | the hash of a std::string, that of its characters More...
|
| struct | ADS::FastHash< const char * > |
| | the hash of a C string, that of its characters More...
|
|
| template<class K> |
| using | ADS::DefaultHash = typename detail::DefaultHashOf< K >::type |
| | the hash of the engineered tables and filters of ADS: FastHash< K > for the integers, the enumerations, the pointers, the floating point numbers and the strings, std::hash< K > for any other K
|
|
| constexpr Product128 | ADS::product128 (std::uint64_t a, std::uint64_t b) |
| | the product \( a b \) on 128 bits
|
| constexpr std::uint64_t | ADS::foldedProduct (std::uint64_t a, std::uint64_t b) |
| | the folded product: the low half of \( a b \) on 128 bits XOR its high half, \( ( a b \bmod 2^{64} ) \oplus \lfloor a b / 2^{64} \rfloor \)
|
| constexpr std::uint64_t | ADS::hashWord (std::uint64_t x, std::uint64_t seed=0) |
| | the hash of the word \( x \) under the seed, the folded product of \( x \) and of the seed XOR a constant
|
| std::uint64_t | ADS::hashBytes (const void *p, std::size_t n, std::uint64_t seed=0) |
| | the hash of the \( n \) bytes from \( p \) under the seed
|
The engineered hash functions of ADS, beyond the book.
The definitions, the invariants and the costs of the area are in Theory of dictionaries.
◆ DefaultHash
the hash of the engineered tables and filters of ADS: FastHash< K > for the integers, the enumerations, the pointers, the floating point numbers and the strings, std::hash< K > for any other K
◆ foldedProduct()
| std::uint64_t ADS::foldedProduct |
( |
std::uint64_t | a, |
|
|
std::uint64_t | b ) |
|
nodiscardconstexpr |
the folded product: the low half of \( a b \) on 128 bits XOR its high half, \( ( a b \bmod 2^{64} ) \oplus \lfloor a b / 2^{64} \rfloor \)
◆ hashBytes()
| std::uint64_t ADS::hashBytes |
( |
const void * | p, |
|
|
std::size_t | n, |
|
|
std::uint64_t | seed = 0 ) |
|
nodiscard |
the hash of the \( n \) bytes from \( p \) under the seed
In pseudocode (the folded products of wyhash and the stripes of XXH3, beyond the book), \( g \) the folded product, \( c_i \) constants and \( w( i ) \) the word of the 8 bytes from the byte \( i \); the cases up to 64 bytes have no loop:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{hashBytes}( p , n , s ) \cr
2 & \quad \textbf{if}\ n \le 8\ \textbf{then return}\ g( x \oplus s ,
c_1 \oplus n )\quad \triangleright\ x \text{ the bytes as a word} \cr
3 & \quad \textbf{if}\ n \le 16\ \textbf{then return}\ g \text{ of the }
\text{words } w( 0 ) \text{ and } w( n - 8 ) \cr
4 & \quad \textbf{if}\ n \le 32\ \textbf{then return}\ \text{the XOR of }
g \text{ on the first and on the last 16 bytes} \cr
5 & \quad \textbf{if}\ n \le 64\ \textbf{then return}\ g \text{ of the }
\text{four products of the first and the last 32 bytes} \cr
6 & \quad \textbf{if}\ n \le 256\ \textbf{then} \cr
7 & \qquad \text{fold the blocks of 16 bytes into 6 states, each}
\ h \gets g( w( i ) \oplus c , w( i + 8 ) \oplus h ) \cr
8 & \qquad \textbf{return}\ g \text{ of the states, the last 16 bytes }
\text{and } n \cr
9 & \quad \text{add to 8 lanes the stripes of 64 bytes, each lane }
\text{the product of the halves of its word} \cr
10 & \quad \textbf{return}\ g \text{ of the lanes folded by 4 products}
\end{array}}
\]
The cases up to 64 bytes are always inlined, the longer strings are hashed out of line.
- Precondition
- \( p \) is not nil if \( n > 0 \)
◆ hashWord()
| std::uint64_t ADS::hashWord |
( |
std::uint64_t | x, |
|
|
std::uint64_t | seed = 0 ) |
|
nodiscardconstexpr |
the hash of the word \( x \) under the seed, the folded product of \( x \) and of the seed XOR a constant
◆ product128()
| Product128 ADS::product128 |
( |
std::uint64_t | a, |
|
|
std::uint64_t | b ) |
|
nodiscardconstexpr |
the product \( a b \) on 128 bits