summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/logval.h5
-rwxr-xr-xutils/max_plus.h40
2 files changed, 20 insertions, 25 deletions
diff --git a/utils/logval.h b/utils/logval.h
index 868146de..833da7b8 100644
--- a/utils/logval.h
+++ b/utils/logval.h
@@ -110,10 +110,10 @@ class LogVal {
//remember, s_ means negative.
inline bool lt(Self const& o) const {
- return s_ ? (!o.s_ || o.v_<v_) : (o.s_ || v_<o.v_);
+ return s_==o.s_ ? v_ < o.v_ : s_ > o.s_;
}
inline bool gt(Self const& o) const {
- return s_ ? (o.s_ && v_<o.v_) : (!o.s_ && o.v_<v_);
+ return s_==o.s_ ? o.v_ < v_ : s_ < o.s_;
}
Self operator-() const {
@@ -148,6 +148,7 @@ template <class T>
struct semiring_traits<LogVal<T> > : default_semiring_traits<LogVal<T> > {
static const bool has_logplus=true;
static const bool has_besteq=true;
+ static const bool has_order=true;
static const bool has_subtract=true;
static const bool has_negative=true;
};
diff --git a/utils/max_plus.h b/utils/max_plus.h
index 5136b881..5ca26522 100755
--- a/utils/max_plus.h
+++ b/utils/max_plus.h
@@ -1,7 +1,6 @@
#ifndef MAX_PLUS_H_
#define MAX_PLUS_H_
-#include
// max-plus algebra. ordering a > b really means that (i.e. default a<b sorting will do worst (closest to 0) first. so get used to passing predicates like std::greater<MaxPlus<T> > around
// x+y := max{x,y}
// x*y := x+y
@@ -44,11 +43,6 @@ class MaxPlus {
void logeq(const T& v) { v_ = v; }
bool signbit() const { return false; }
- std::size_t hash_impl() const {
- using namespace boost;
- return hash_value(v_);
- }
-
Self& logpluseq(const Self& a) {
if (a.is_0()) return *this;
if (a.s_ == s_) {
@@ -116,15 +110,15 @@ class MaxPlus {
}
// copy elision - as opposed to explicit copy of Self 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
- friend inline operator+(Self a,Self const& b) {
+ friend inline Self operator+(Self a,Self const& b) {
a+=b;
return a;
}
- friend inline operator*(Self a,Self const& b) {
+ friend inline Self operator*(Self a,Self const& b) {
a*=b;
return a;
}
- friend inline operator/(Self a,Self const& b) {
+ friend inline Self operator/(Self a,Self const& b) {
a/=b;
return a;
}
@@ -148,6 +142,15 @@ class MaxPlus {
friend inline bool operator!=(Self const& lhs, Self const&rhs) {
return lhs.v_ != rhs.v_;
}
+
+ std::size_t hash() const {
+ using namespace boost;
+ return hash_value(v_);
+ }
+ friend inline std::size_t hash_value(Self const& x) {
+ return x.hash();
+ }
+
/*
operator T() const {
return std::exp(v_);
@@ -171,6 +174,11 @@ template <class T>
#if 0
template <class T>
+bool operator=(const MaxPlus<T>& lhs, const MaxPlus<T>& rhs) {
+ return (lhs.v_ <= rhs.v_);
+}
+
+template <class T>
bool operator<=(const MaxPlus<T>& lhs, const MaxPlus<T>& rhs) {
return (lhs.v_ <= rhs.v_);
}
@@ -186,18 +194,4 @@ bool operator>=(const MaxPlus<T>& lhs, const MaxPlus<T>& rhs) {
}
#endif
-
-template <class T>
-std::size_t hash_value(const MaxPlus<T>& x) { return x.hash_impl(); }
-
-template <class T>
-bool operator==(const MaxPlus<T>& lhs, const MaxPlus<T>& rhs) {
- return (lhs.v_ == rhs.v_) && (lhs.s_ == rhs.s_);
-}
-
-template <class T>
-bool operator!=(const MaxPlus<T>& lhs, const MaxPlus<T>& rhs) {
- return !(lhs == rhs);
-}
-
#endif