BitBully 0.0.39
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 };
24
25 TranspositionTable(const int log_2_size = LOG_2_SIZE) {
26 tableSize = UINT64_C(1) << log_2_size;
27 table = std::make_unique<Entry[]>(tableSize);
28 }
29
30 inline Entry *get(const Board &b) {
31 // Prefetching?:
32 // size_t index = b.hash() & (tableSize - 1);
33 // __builtin_prefetch(&table[index]); // GCC/Clang prefetching
34 // return &table[index];
35
36 return &table[b.hash() & (tableSize - 1)];
37 }
38
39 private:
40 std::unique_ptr<Entry[]> table;
41 size_t tableSize;
42};
43
44} // namespace BitBully
45
46#endif // BITBULLY__TRANSPOSITIONTABLE_H_