BitBully 0.0.76
Loading...
Searching...
No Matches
TranspositionTable.h
1#ifndef BITBULLY__TRANSPOSITIONTABLE_H_
2#define BITBULLY__TRANSPOSITIONTABLE_H_
3
4#include <memory>
5
6#include "Board.h"
7
8namespace BitBully {
9
10class TranspositionTable {
11 public:
12 // hash tables of size 2^n allow fast modulo operations since
13 // x mod 2^n = x & (2^n - 1)
14 // TODO: compute the effect of the hash table size on the long-term perf. of
15 // the BitBully solver
16 static constexpr int LOG_2_SIZE = 20;
17
18 struct Entry {
19 enum NodeType { NONE = 0, EXACT = 1, LOWER = 2, UPPER = 3 };
20 uint64_t b; // TODO: There should be a global type TBitboard
21 NodeType flag{NONE};
22 int value;
23 int8_t searchDepth{0}; // remaining search budget when entry was stored
24 // INT8_MAX = unlimited (full) search
25 };
26
27 TranspositionTable(const int log_2_size = LOG_2_SIZE) {
28 tableSize = UINT64_C(1) << log_2_size;
29 table = std::make_unique<Entry[]>(tableSize);
30 }
31
32 inline Entry* get(const Board& b) {
33 // Prefetching?:
34 // size_t index = b.hash() & (tableSize - 1);
35 // __builtin_prefetch(&table[index]); // GCC/Clang prefetching
36 // return &table[index];
37
38 return &table[b.hash() & (tableSize - 1)];
39 }
40
41 private:
42 std::unique_ptr<Entry[]> table;
43 size_t tableSize;
44};
45
46} // namespace BitBully
47
48#endif // BITBULLY__TRANSPOSITIONTABLE_H_