N-bit hash codes. More...
#include <SgHash.h>
Public Member Functions | |
SgHash () | |
Costruct hash code initialized with zero. | |
SgHash (unsigned int key) | |
Construct hash code from integer index. | |
~SgHash () | |
void | Clear () |
Reinitialize the hash code. | |
void | Invalidate () |
Set to random value. | |
bool | operator< (const SgHash &code) const |
bool | operator== (const SgHash &code) const |
bool | operator!= (const SgHash &code) const |
bool | IsZero () const |
void | Xor (const SgHash &code) |
Combine this hash code with the given hash code. | |
unsigned int | Hash (int max) const |
Use this hash code to hash into a table with 'max' elements. | |
unsigned int | Code1 () const |
First integer (deprecated). | |
unsigned int | Code2 () const |
Second integer (deprecated). | |
void | RollLeft (int n) |
Roll bits n places to the left. | |
void | RollRight (int n) |
Roll bits n places to the right. | |
std::string | ToString () const |
Convert hash code to string. | |
void | FromString (const std::string &str) |
Convert string to hash code. | |
Static Public Member Functions | |
static SgHash | Random () |
Return a random hash code. | |
static int | Size () |
Private Member Functions | |
unsigned int | Mix32 (int key) const |
Thomas Wang's 32 bit mix function. | |
unsigned int | GetWord () const |
Private Attributes | |
std::bitset< N > | m_code |
N-bit hash codes.
Definition at line 26 of file SgHash.h.
Construct hash code from integer index.
Definition at line 99 of file SgHash.h.
References SgHash< N >::GetWord(), SgHash< N >::m_code, and SgHash< N >::Mix32().
void SgHash< N >::Clear | ( | ) |
Reinitialize the hash code.
Caution: after Clear() hash code matches code of empty board.
Definition at line 141 of file SgHash.h.
References SgHash< N >::m_code.
Referenced by SgStrategy::Clear(), and SgHash< N >::FromString().
unsigned int SgHash< N >::Code1 | ( | ) | const |
First integer (deprecated).
Definition at line 147 of file SgHash.h.
References SgHash< N >::GetWord().
unsigned int SgHash< N >::Code2 | ( | ) | const |
Second integer (deprecated).
Definition at line 153 of file SgHash.h.
References SgHash< N >::m_code.
void SgHash< N >::FromString | ( | const std::string & | str | ) |
Convert string to hash code.
Definition at line 159 of file SgHash.h.
References SgHash< N >::Clear(), and SgHash< N >::m_code.
Referenced by operator>>().
unsigned int SgHash< N >::GetWord | ( | ) | const [private] |
Definition at line 178 of file SgHash.h.
References SgHash< N >::m_code.
Referenced by SgHash< N >::Code1(), SgHash< N >::Hash(), and SgHash< N >::SgHash().
unsigned int SgHash< N >::Hash | ( | int | max | ) | const |
Use this hash code to hash into a table with 'max' elements.
Definition at line 185 of file SgHash.h.
References SgHash< N >::GetWord().
Referenced by SgHashTable< DATA >::Lookup(), and SgHashTable< DATA >::Store().
void SgHash< N >::Invalidate | ( | ) |
bool SgHash< N >::IsZero | ( | ) | const |
Definition at line 197 of file SgHash.h.
References SgHash< N >::m_code.
unsigned int SgHash< N >::Mix32 | ( | int | key | ) | const [private] |
Thomas Wang's 32 bit mix function.
Definition at line 203 of file SgHash.h.
Referenced by SgHash< N >::SgHash().
Definition at line 135 of file SgHash.h.
References SgHash< N >::m_code.
Definition at line 112 of file SgHash.h.
References SgHash< N >::m_code.
Definition at line 129 of file SgHash.h.
References SgHash< N >::m_code.
Return a random hash code.
Definition at line 215 of file SgHash.h.
References SgRandom::Global(), SgRandom::Int(), and SgHash< N >::m_code.
Referenced by SgHash< N >::Invalidate().
void SgHash< N >::RollLeft | ( | int | n | ) |
Roll bits n places to the left.
Definition at line 229 of file SgHash.h.
References SgHash< N >::m_code.
void SgHash< N >::RollRight | ( | int | n | ) |
Roll bits n places to the right.
Definition at line 235 of file SgHash.h.
References SgHash< N >::m_code.
std::string SgHash< N >::ToString | ( | ) | const |
Convert hash code to string.
Definition at line 247 of file SgHash.h.
References SgHash< N >::m_code.
Combine this hash code with the given hash code.
Definition at line 261 of file SgHash.h.
References SgHash< N >::m_code.
Referenced by SgHashUtil::XorInteger(), and SgHashUtil::XorZobrist().
Definition at line 92 of file SgHash.h.
Referenced by SgHash< N >::Clear(), SgHash< N >::Code2(), SgHash< N >::FromString(), SgHash< N >::GetWord(), SgHash< N >::IsZero(), SgHash< N >::operator!=(), SgHash< N >::operator<(), SgHash< N >::operator==(), SgHash< N >::Random(), SgHash< N >::RollLeft(), SgHash< N >::RollRight(), SgHash< N >::SgHash(), SgHash< N >::ToString(), and SgHash< N >::Xor().