Debian Codegraph @

old-sample/legacy-checkmate/lib/simpleCheckHashTable.cc

raw
1 #include "simpleCheckHashTable.h"
2 #include "checkHashRecord.h"
3 #include "osl/stl/hash_map.h"
4 #include "osl/hash/hashKey.h"
5 #include <algorithm>
6 #include <iostream>
7
8 #ifndef MINIMAL
9 namespace osl
10 {
11 namespace checkmate
12 {
13 static const int initial_capacity = 1000000;
14 typedef hash_map<HashKey,CheckHashRecord> hash_map_t;
15 struct SimpleCheckHashTable::Table : public hash_map_t
16 {
17 explicit Table(size_t capacity) : hash_map_t(capacity)
18 {
19 }
20 };
21
22 SimpleCheckHashTable::SimpleCheckHashTable(Player a)
23 : table(new Table(initial_capacity)), attacker(a)
24 {
25 }
26 SimpleCheckHashTable::~SimpleCheckHashTable()
27 {
28 #ifdef CHECKMATE_DEBUG
29 confirmNoVisitedRecords();
30 #endif
31 }
32
33 CheckHashRecord * SimpleCheckHashTable::find(const HashKey& key)
34 {
35 Table::iterator it=table->find(key);
36 if (it==table->end())
37 return 0;
38 return &it->second;
39 }
40
41 CheckHashRecord * SimpleCheckHashTable::
42 allocate(const HashKey& key, const PieceStand& white_stand,
43 const PathEncoding&)
44 {
45 CheckHashRecord *result = &(*table)[key];
46 if ((result->stand(BLACK) != key.blackStand())
47 || (result->stand(WHITE) != white_stand))
48 *result = CheckHashRecord(key.blackStand(), white_stand);
49 return result;
50 }
51
52 void SimpleCheckHashTable::clear(){
53 TwinTableHolder::clear();
54 table->clear();
55 }
56
57 const CheckHashRecord * SimpleCheckHashTable::find(const HashKey& key) const
58 {
59 Table::const_iterator it=table->find(key);
60 if (it==table->end())
61 return 0;
62 return &it->second;
63 }
64 size_t SimpleCheckHashTable::size() const{
65 return table->size();
66 }
67 void SimpleCheckHashTable::confirmNoVisitedRecords() const
68 {
69 size_t visited = 0;
70 for (Table::const_iterator p=table->begin(); p!=table->end(); ++p)
71 {
72 if (p->second.isVisited)
73 {
74 ++visited;
75 std::cerr << p->first << " " << &p->second << "\n";
76 }
77 }
78 if (visited)
79 {
80 std::cerr << "SimpleCheckHashTable::confirmNoVisitedRecords "
81 << visited << " visited nodes found\n";
82 }
83 }
84 } // namespace checkmate
85 } // namespace osl
86 #endif
87 // ;;; Local Variables:
88 // ;;; mode:c++
89 // ;;; c-basic-offset:2
90 // ;;; End: