00001 /* searchMoveSet.h 00002 */ 00003 #ifndef _SEARCHMOVESET_H 00004 #define _SEARCHMOVESET_H 00005 00006 #include "osl/container/linearMoveMap.h" 00007 #include "osl/search/searchMove.h" 00008 #ifdef OSL_SMP 00009 # include "osl/misc/lightMutex.h" 00010 #endif 00011 #include <iosfwd> 00012 00013 namespace osl 00014 { 00015 namespace search 00016 { 00017 class SearchMoveSet : private LinearMoveMap<search::SearchMove> 00018 { 00019 #ifdef OSL_SMP 00020 typedef osl::misc::LightMutex Mutex; 00021 mutable Mutex mutex; 00022 #endif 00023 public: 00024 typedef LinearMoveMap<search::SearchMove> base_t; 00025 typedef search::SearchMove SearchMove; 00026 00027 SearchMoveSet() {} 00028 SearchMoveSet(const SearchMoveSet& src); 00029 ~SearchMoveSet(); 00030 SearchMoveSet& operator=(const SearchMoveSet& src); 00031 00032 SearchMove* find(Move key) 00033 { 00034 #ifdef OSL_SMP 00035 Mutex::scoped_lock lk(mutex); 00036 #endif 00037 return base_t::find(key); 00038 } 00039 const SearchMove* find(Move key) const 00040 { 00041 #ifdef OSL_SMP 00042 Mutex::scoped_lock lk(mutex); 00043 #endif 00044 return base_t::find(key); 00045 } 00051 SearchMove *assignIfBetter(const MoveLogProb& move, int margin=0) 00052 { 00053 #ifdef OSL_SMP 00054 Mutex::scoped_lock lk(mutex); 00055 #endif 00056 SearchMove *recorded_move = base_t::find(move.getMove()); 00057 if (recorded_move) 00058 { 00059 // ˤ⤤Ψμ꤬äƤϿʤ 00060 // 㤤ΨμϾ 00061 if (recorded_move->moveLogProb().getLogProb() 00062 <= (move.getLogProb() + margin)) 00063 return 0; 00064 *recorded_move = SearchMove(move, recorded_move->record); 00065 return recorded_move; 00066 } 00067 return insertNoCheck(SearchMove(move)); 00068 } 00069 bool isValidAll() const; 00070 void dump(std::ostream&) const; 00071 bool hasOnlyPass() const 00072 { 00073 #ifdef OSL_SMP 00074 Mutex::scoped_lock lk(mutex); 00075 #endif 00076 const_iterator p = begin(); 00077 if (p == end()) 00078 return false; 00079 return (p->getMove().isPass() && (++p == end())); 00080 } 00081 00082 const SearchMove& front() const 00083 { 00084 #ifdef OSL_SMP 00085 Mutex::scoped_lock lk(mutex); 00086 #endif 00087 assert(! empty()); 00088 return *begin(); 00089 } 00090 00091 struct const_range 00092 { 00093 #ifdef OSL_SMP 00094 Mutex::scoped_lock lock; 00095 #endif 00096 const const_iterator first, last; 00097 explicit const_range(const SearchMoveSet& parent) 00098 : 00099 #ifdef OSL_SMP 00100 lock(parent.mutex), 00101 #endif 00102 first(parent.begin()), last(parent.end()) 00103 { 00104 } 00105 }; 00106 struct range 00107 { 00108 #ifdef OSL_SMP 00109 Mutex::scoped_lock lock; 00110 #endif 00111 const iterator first, last; 00112 explicit range(SearchMoveSet& parent) 00113 : 00114 #ifdef OSL_SMP 00115 lock(parent.mutex), 00116 #endif 00117 first(parent.begin()), last(parent.end()) 00118 { 00119 } 00120 }; 00121 friend class const_range; 00122 friend class range; 00123 using base_t::const_iterator; 00124 using base_t::iterator; 00125 using base_t::size; 00126 using base_t::empty; 00127 }; 00128 00129 } // namespace search 00130 using search::SearchMoveSet; 00131 } // namespace osl 00132 00133 00134 #endif /* _SEARCHMOVESET_H */ 00135 // ;;; Local Variables: 00136 // ;;; mode:c++ 00137 // ;;; c-basic-offset:2 00138 // ;;; End: