Go to the documentation of this file.00001 #include "osl/container/moveLogProbVector.h"
00002 #include <boost/foreach.hpp>
00003 #include <algorithm>
00004 #include <iostream>
00005
00006
00007
00008
00009 #ifndef MINIMAL
00010 std::ostream& osl::container::operator<<(std::ostream& os,MoveLogProbVector const& mv)
00011 {
00012 os<< "LogProbVector" << std::endl;
00013 BOOST_FOREACH(const MoveLogProb& move, mv)
00014 {
00015 os << move << std::endl;
00016 }
00017 return os << std::endl;
00018 }
00019 #endif
00020 bool osl::container::operator==(const MoveLogProbVector& l, const MoveLogProbVector& r)
00021 {
00022 return l.size() == r.size()
00023 && std::equal(l.begin(), l.end(), r.begin());
00024 }
00025
00026 namespace osl
00027 {
00028 template <bool isLess>
00029 struct LogProbCompare
00030 {
00031 bool operator()(const MoveLogProb& l, const MoveLogProb& r) const
00032 {
00033 #ifdef RIGID_SORT_OF_MOVE
00034 if (l.logProb() != r.logProb())
00035 {
00036 #endif
00037 if (isLess)
00038 return l.logProb() < r.logProb();
00039 else
00040 return l.logProb() > r.logProb();
00041 #ifdef RIGID_SORT_OF_MOVE
00042 }
00043 return l.move() > r.move();
00044 #endif
00045 }
00046 };
00047 }
00048
00049 void osl::container::MoveLogProbVector::sortByProbability()
00050 {
00051 std::sort(begin(), end(), LogProbCompare<true>());
00052 }
00053 void osl::container::MoveLogProbVector::sortByProbabilityReverse()
00054 {
00055 std::sort(begin(), end(), LogProbCompare<false>());
00056 }
00057
00058 const osl::MoveLogProb* osl::container::MoveLogProbVector::find(Move m) const
00059 {
00060 for (const_iterator p=begin(); p!=end(); ++p)
00061 if (p->move() == m)
00062 return &*p;
00063 return 0;
00064 }
00065
00066
00067
00068
00069