|
ADS
Algorithms and Data Structures
|
a random word for each pair \( ( f , v ) \) of a feature and a value More...
#include <ADS/dictionary/RandomHashing.h>
Public member functions | |
| ZobristTable (std::size_t n, std::size_t m, std::uint64_t seed=1) | |
| the words of \( n \) features with \( m \) values each, from the seed | |
| std::uint64_t | operator() (std::size_t f, std::size_t v) const |
| the word \( R[ f ][ v ] \) of the feature \( f \) with the value \( v \) | |
| template<std::ranges::random_access_range S> requires std::ranges::sized_range< S > | |
| std::uint64_t | hash (const S &s) const |
| the hash of a state, the value of each feature by its place in \( S \), any range with a size and access by index (a vector, an array, a span of the state) | |
| std::uint64_t | update (std::uint64_t h, std::size_t f, std::size_t a, std::size_t b) const |
| the hash \( h \) of a state after the feature \( f \) changes from \( a \) to \( b \), \( h \oplus R[ f ][ a ] \oplus R[ f ][ b ] \), since \( x \oplus x = 0 \) takes the old word away | |
a random word for each pair \( ( f , v ) \) of a feature and a value
| ADS::ZobristTable::ZobristTable | ( | std::size_t | n, |
| std::size_t | m, | ||
| std::uint64_t | seed = 1 ) |
the words of \( n \) features with \( m \) values each, from the seed
|
nodiscard |
the hash of a state, the value of each feature by its place in \( S \), any range with a size and access by index (a vector, an array, a span of the state)
In pseudocode (Zobrist, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{hash}( S ) \cr 2 & \quad h \gets 0 \cr 3 & \quad \textbf{for}\ f \gets 0\ \textbf{to}\ n - 1\ \textbf{do}\ h \gets h \oplus R[ f ][ S[ f ] ] \cr 4 & \quad \textbf{return}\ h \end{array}} \]
|
nodiscard |
the word \( R[ f ][ v ] \) of the feature \( f \) with the value \( v \)
|
nodiscard |
the hash \( h \) of a state after the feature \( f \) changes from \( a \) to \( b \), \( h \oplus R[ f ][ a ] \oplus R[ f ][ b ] \), since \( x \oplus x = 0 \) takes the old word away