ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RandomHashing.h File Reference

Hashing with random tables, beyond the book: More...

#include "ADS/Contract.h"
#include <array>
#include <atomic>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <ranges>
#include <vector>
#include "ADS/dictionary/impl/RandomHashing.tpp"

Go to the source code of this file.

Classes

class  ADS::SplitMix64
 the generator SplitMix64, a UniformRandomBitGenerator More...
class  ADS::ZobristTable
 a random word for each pair \( ( f , v ) \) of a feature and a value More...
class  ADS::TabulationHash
 the simple tabulation hashing of the keys of 64 bits More...

Namespaces

namespace  ADS

Functions

constexpr std::uint64_t ADS::splitmix64 (std::uint64_t x)
 the mix of SplitMix64: a bijection of the words of 64 bits
constexpr std::uint64_t ADS::fibonacciPlace (std::uint64_t h, int b)
 the place of the hash \( h \) in a table of \( 2^b \) places, its top \( b \) bits after the product by \( \lfloor 2^{64} / \phi \rfloor \)

Detailed description

Hashing with random tables, beyond the book:

  • splitmix64(), the finalizer of the generator SplitMix64 of Steele, Lea and Flood, a bijection of the words of 64 bits that mixes every input bit into every output bit, and SplitMix64, the generator itself, which meets UniformRandomBitGenerator and seeds the tables below;
  • fibonacciPlace(), the top \( b \) bits of \( h \lfloor 2^{64} / \phi \rfloor \), the multiplicative hashing of Knuth with the golden ratio, which spreads over a table of \( 2^b \) places also the hashes whose low bits are regular;
  • ZobristTable, a random word \( R[ f ][ v ] \) for each feature \( f \) and value \( v \), the hash of a state being the XOR of the words of its pairs: a move that changes the value of a feature updates the hash in \( O( 1 ) \) by two XOR, which makes it the hash of the board games and of the states of a search;
  • TabulationHash, the simple tabulation of Carter and Wegman: a key of 64 bits is cut into 8 bytes and the hash is the XOR of a random word of a table per byte; it is 3-independent, and Pătrașcu and Thorup showed that it gives linear probing, cuckoo hashing and the minwise estimates the bounds of fully random hashing.

The contracts [see Contract.h]: \( 1 \le b \le 64 \) for fibonacciPlace(), at least a feature and a value for ZobristTable, and the features and the values within it. The functions are defined in RandomHashing.tpp.

See also
G. L. Steele, D. Lea, C. H. Flood, Fast splittable pseudorandom number generators, Proceedings of OOPSLA 2014, 453-472, 2014, doi:10.1145/2660193.2660195
D. E. Knuth, The Art of Computer Programming, vol. 3, 2nd ed., Addison-Wesley, 1998, section 6.4 (the multiplicative hashing)
A. L. Zobrist, A new hashing method with application for game playing, Technical Report 88, University of Wisconsin, 1970
J. L. Carter, M. N. Wegman, Universal classes of hash functions, Journal of Computer and System Sciences 18(2), 143-154, 1979, doi:10.1016/0022-0000(79)90044-8
M. Pătrașcu, M. Thorup, The power of simple tabulation hashing, Journal of the ACM 59(3), article 14, 2012, doi:10.1145/2220357.2220361
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa