simpleHashTable.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
simpleHashTable.cc
Go to the documentation of this file.
1 /* simpleHashTable.cc
2 */
3 #include "osl/search/simpleHashTable.h"
4 #include "osl/search/simpleHashRecord.h"
5 #include "osl/search/analyzer/recordSet_.h"
6 #include "osl/container/generalSimpleHashTable.tcc"
7 #include <iostream>
8
9 namespace osl
10 {
11 template class container::GeneralSimpleHashTable <SimpleHashRecord>;
12 } // namespace osl
13
14 osl::search::SimpleHashTable::
15 SimpleHashTable(size_t capacity, int minimum_recordlimit, int v)
16 : GeneralSimpleHashTable<SimpleHashRecord>(capacity),
17 minimum_limit(minimum_recordlimit), verbose(v)
18 {
19 }
20
21 uint64_t osl::search::SimpleHashTable::
22 memoryUse() const
23 {
24 return 1ull * (sizeof(SimpleHashRecord)+sizeof(HashKey)+sizeof(SimpleHashRecord*)) * size();
25 }
26
27 osl::search::SimpleHashTable::
28 ~SimpleHashTable()
29 {
30 const uint64_t memory_use = memoryUse();
31 if ((verbose > 1 && size()) || memory_use > (1024*(1ull<<20)))
32 {
33 std::cerr << "SimpleHashTable size: " << size() << " ("
34 << memory_use / (1ull<<20) << "MB)"
35 << ", cache hit " << table->num_cache_hit
36 << ", table full " << table->num_record_after_full << "\n";
37 }
38 }
39
40 void osl::search::SimpleHashTable::
41 setVerbose(int v)
42 {
43 verbose = v;
44 }
45
46 void osl::search::SimpleHashTable::
47 setMinimumRecordLimit(int new_limit)
48 {
49 minimum_limit = new_limit;
50 }
51
52 int osl::search::SimpleHashTable::
53 minimumRecordLimit() const
54 {
55 return minimum_limit;
56 }
57
58 osl::search::SimpleHashRecord *
59 osl::search::SimpleHashTable::
60 allocate(const HashKey& key, int limit)
61 {
62 if (limit < minimumRecordLimit())
63 return find(key);
64 return GeneralSimpleHashTable <SimpleHashRecord>::allocate (key);
65 }
66
67 int osl::search::SimpleHashTable::
68 verboseLevel() const
69 {
70 return verbose;
71 }
72
73 bool osl::search::SimpleHashTable::
74 isConsistent() const
75 {
76 return true;
77 }
78
79 int osl::search::SimpleHashTable::
80 divSize() const
81 {
82 return GeneralSimpleHashTable<SimpleHashRecord>::divSize();
83 }
84
85 #ifndef MINIMAL
86 void osl::search::SimpleHashTable::
87 getPV(const HashKey& root, MoveVector& out, size_t *quiesce_start) const
88 {
89 analyzer::RecordSet dejavu;
90 HashKey key = root;
91 const SimpleHashRecord *record;
92 while (true) {
93 record = table->find(key);
94 if (! record || dejavu.find(record) != dejavu.end()) {
95 break;
96 }
97 const Move best_move = record->bestMove().move();
98 if (best_move.isInvalid()) {
99 break;
100 }
101 dejavu.insert(record);
102 out.push_back(best_move);
103 key = key.newHashWithMove(best_move);
104 }
105 if (! quiesce_start || ! record)
106 return;
107 *quiesce_start = out.size();
108 while (true) {
109 const Move best_move = record->qrecord.bestMove();
110 if (best_move.isInvalid()) {
111 break;
112 }
113 out.push_back(best_move);
114
115 key = key.newHashWithMove(best_move);
116 record = table->find(key);
117 if (! record || dejavu.find(record) != dejavu.end()) {
118 break;
119 }
120 dejavu.insert(record);
121 }
122 }
123 #endif
124 /* ------------------------------------------------------------------------- */
125 // ;;; Local Variables:
126 // ;;; mode:c++
127 // ;;; c-basic-offset:2
128 // ;;; End: