|
ADS
Algorithms and Data Structures
|
The hash functions of section 7.1. More...
#include "ADS/Contract.h"#include <cmath>#include <cstddef>#include <cstdint>#include <limits>#include <string_view>#include "ADS/dictionary/impl/HashFunctions.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| unsigned | ADS::bin_bit (std::string_view k, std::size_t j) |
| the bit of place \( j \) of \( \mathrm{bin}( k ) \), counted from the left; 0 past the end | |
| std::uint64_t | ADS::int_bin (std::string_view k) |
| \( \mathrm{int}( \mathrm{bin}( k ) ) \) of a key of at most 8 characters | |
| std::uint64_t | ADS::hash_extraction (std::string_view k, int p, std::size_t s) |
| the extraction: the \( p \) bits of \( \mathrm{bin}( k ) \) from the place \( s \) on, counted from the left, as an integer in \( [ 0 , 2^p ) \) | |
| std::uint64_t | ADS::hash_xor (std::string_view k, int p) |
| the XOR of the blocks of \( p \) bits of \( \mathrm{bin}( k ) \), the last one padded with zeros on the right | |
| std::uint64_t | ADS::hash_division (std::string_view k, std::uint64_t m, std::uint64_t base=256, std::uint64_t seed=0) |
| the division \( \mathrm{int}( \mathrm{bin}( k ) ) \bmod m \) by the rule of Horner in the given base, each character being a digit, from the leading digit seed (the \( h = 5 \), \( h = 3 h + c \) is base 3 and seed 5); a character is any byte, up to 255 also in a base below 256 | |
| std::uint64_t | ADS::hash_multiplication (std::uint64_t i, std::uint64_t m, long double C=(std::sqrt(5.0L) - 1)/2) |
| the multiplication in floating point, the formula of the book, \( \lfloor m ( C i - \lfloor C i \rfloor ) \rfloor \): exact only while \( C i \) keeps enough digits after the point, i.e., for \( i \) well below the \( 2^{64} \) of the mantissa of a long double | |
| std::uint64_t | ADS::hash_fibonacci (std::uint64_t i, int p) |
| the multiplication with integers for \( m = 2^p \), \( w = 64 \): the \( p \) most significant bits of the 64 least significant ones of \( i s \), with \( s = \lfloor C 2^{64} \rfloor \); it is \( \lfloor m \, \mathrm{frac}( i s / 2^{64} ) \rfloor \), which differs from the exact \( \lfloor m \, \mathrm{frac}( C i ) \rfloor \) by about \( m i / 2^{64} \) | |
| std::uint64_t | ADS::hash_midsquare (std::uint64_t i, int p) |
| the middle square: the \( p \) bits in the middle of the 64 least significant ones of \( i^2 \) | |
The hash functions of section 7.1.
A hash function \( H : U \rightarrow \{ 0 , \ldots , m - 1 \} \) maps a key to a place of a vector of size \( m \); it has the simple uniformity if
\[ Q( i ) = \sum_{k : H( k ) = i} P( k ) = \frac{1}{m} \qquad \forall i \in \{ 0 , \ldots , m - 1 \} \]
where \( P( k ) \) is the probability that the key \( k \) is in the dictionary. A key is read as the string \( \mathrm{bin}( k ) \) of its bits, the bytes of a string one after the other from the first, the most significant bit of each first, and \( \mathrm{int}( b ) \) is the integer of the bit string \( b \). The functions are
The contracts [see Contract.h]: the number \( p \) of bits in its range, a key of at most 8 characters for int_bin(), and for hash_division() a size \( m > 0 \) and a base \( > 0 \) such that the rule of Horner does not overflow; each result is below the size it is meant for. The functions are defined in HashFunctions.tpp.