summaryrefslogtreecommitdiff
path: root/utils/logval.h
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 03:35:23 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-15 03:35:23 +0000
commit3b245a5b2a858fe3712ca367312146f5505abb25 (patch)
tree1bbffa9f1d180bb19fe1f2bc3c1d966c45f72a6e /utils/logval.h
parent66d9f91ce7ad792138d68a7f29ab159e7af6a132 (diff)
warning
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@551 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils/logval.h')
-rw-r--r--utils/logval.h36
1 files changed, 23 insertions, 13 deletions
diff --git a/utils/logval.h b/utils/logval.h
index 37f14ae5..b337cf0e 100644
--- a/utils/logval.h
+++ b/utils/logval.h
@@ -3,12 +3,13 @@
#define LOGVAL_CHECK_NEG false
+#include <boost/functional/hash.hpp>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <limits>
-template <typename T>
+template <class T>
class LogVal {
public:
LogVal() : s_(), v_(-std::numeric_limits<T>::infinity()) {}
@@ -23,6 +24,11 @@ class LogVal {
static LogVal<T> e() { return LogVal(1,false); }
void logeq(const T& v) { s_ = false; v_ = v; }
+ std::size_t hash_impl() const {
+ using namespace boost;
+ return hash_value(v_)+s_;
+ }
+
LogVal& operator+=(const LogVal& a) {
if (a.v_ == -std::numeric_limits<T>::infinity()) return *this;
if (a.s_ == s_) {
@@ -98,31 +104,31 @@ class LogVal {
};
// copy elision - as opposed to explicit copy of LogVal<T> const& o1, we should be able to construct Logval r=a+(b+c) as a single result in place in r. todo: return std::move(o1) - C++0x
-template<typename T>
+template<class T>
LogVal<T> operator+(LogVal<T> o1, const LogVal<T>& o2) {
o1 += o2;
return o1;
}
-template<typename T>
+template<class T>
LogVal<T> operator*(LogVal<T> o1, const LogVal<T>& o2) {
o1 *= o2;
return o1;
}
-template<typename T>
+template<class T>
LogVal<T> operator/(LogVal<T> o1, const LogVal<T>& o2) {
o1 /= o2;
return o1;
}
-template<typename T>
+template<class T>
LogVal<T> operator-(LogVal<T> o1, const LogVal<T>& o2) {
o1 -= o2;
return o1;
}
-template<typename T>
+template<class T>
T log(const LogVal<T>& o) {
#ifdef LOGVAL_CHECK_NEG
if (o.s_) return log(-1.0);
@@ -130,12 +136,12 @@ T log(const LogVal<T>& o) {
return o.v_;
}
-template <typename T>
+template <class T>
LogVal<T> pow(const LogVal<T>& b, const T& e) {
return b.pow(e);
}
-template <typename T>
+template <class T>
bool operator<(const LogVal<T>& lhs, const LogVal<T>& rhs) {
if (lhs.s_ == rhs.s_) {
return (lhs.v_ < rhs.v_);
@@ -145,28 +151,32 @@ bool operator<(const LogVal<T>& lhs, const LogVal<T>& rhs) {
}
#if 0
-template <typename T>
+template <class T>
bool operator<=(const LogVal<T>& lhs, const LogVal<T>& rhs) {
return (lhs.v_ <= rhs.v_);
}
-template <typename T>
+template <class T>
bool operator>(const LogVal<T>& lhs, const LogVal<T>& rhs) {
return (lhs.v_ > rhs.v_);
}
-template <typename T>
+template <class T>
bool operator>=(const LogVal<T>& lhs, const LogVal<T>& rhs) {
return (lhs.v_ >= rhs.v_);
}
#endif
-template <typename T>
+
+template <class T>
+std::size_t hash_value(const LogVal<T>& x) { return x.hash_impl(); }
+
+template <class T>
bool operator==(const LogVal<T>& lhs, const LogVal<T>& rhs) {
return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_);
}
-template <typename T>
+template <class T>
bool operator!=(const LogVal<T>& lhs, const LogVal<T>& rhs) {
return !(lhs == rhs);
}