00001 #include "osl/checkmate/simpleCheckHashTable.h" 00002 #include "osl/checkmate/checkHashRecord.h" 00003 #include "osl/stl/hash_map.h" 00004 #include "osl/hash/hashKey.h" 00005 #include <algorithm> 00006 #include <iostream> 00007 00008 namespace osl 00009 { 00010 namespace checkmate 00011 { 00012 static const int initial_capacity = 1000000; 00013 typedef hash_map<HashKey,CheckHashRecord> hash_map_t; 00014 struct SimpleCheckHashTable::Table : public hash_map_t 00015 { 00016 explicit Table(size_t capacity) : hash_map_t(capacity) 00017 { 00018 } 00019 }; 00020 00021 SimpleCheckHashTable::SimpleCheckHashTable(Player a) 00022 : table(new Table(initial_capacity)), attacker(a) 00023 { 00024 } 00025 SimpleCheckHashTable::~SimpleCheckHashTable() 00026 { 00027 #ifdef CHECKMATE_DEBUG 00028 confirmNoVisitedRecords(); 00029 #endif 00030 } 00031 00032 CheckHashRecord * SimpleCheckHashTable::find(const HashKey& key) 00033 { 00034 Table::iterator it=table->find(key); 00035 if (it==table->end()) 00036 return 0; 00037 return &it->second; 00038 } 00039 00040 CheckHashRecord * SimpleCheckHashTable:: 00041 allocate(const HashKey& key, const PieceStand& white_stand, 00042 const PathEncoding&) 00043 { 00044 CheckHashRecord *result = &(*table)[key]; 00045 if ((result->stand(BLACK) != key.blackStand()) 00046 || (result->stand(WHITE) != white_stand)) 00047 *result = CheckHashRecord(key.blackStand(), white_stand); 00048 return result; 00049 } 00050 00051 void SimpleCheckHashTable::clear(){ 00052 TwinTableHolder::clear(); 00053 table->clear(); 00054 } 00055 00056 const CheckHashRecord * SimpleCheckHashTable::find(const HashKey& key) const 00057 { 00058 Table::const_iterator it=table->find(key); 00059 if (it==table->end()) 00060 return 0; 00061 return &it->second; 00062 } 00063 size_t SimpleCheckHashTable::size() const{ 00064 return table->size(); 00065 } 00066 void SimpleCheckHashTable::confirmNoVisitedRecords() const 00067 { 00068 size_t visited = 0; 00069 for (Table::const_iterator p=table->begin(); p!=table->end(); ++p) 00070 { 00071 if (p->second.isVisited) 00072 { 00073 ++visited; 00074 std::cerr << p->first << " " << &p->second << "\n"; 00075 } 00076 } 00077 if (visited) 00078 { 00079 std::cerr << "SimpleCheckHashTable::confirmNoVisitedRecords " 00080 << visited << " visited nodes found\n"; 00081 } 00082 } 00083 } // namespace checkmate 00084 } // namespace osl 00085 // ;;; Local Variables: 00086 // ;;; mode:c++ 00087 // ;;; c-basic-offset:2 00088 // ;;; End: