You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2014/04/30 23:13:32 UTC
git commit: Updated the 'contains' method in stout IntervalSet to
support more types.
Repository: mesos
Updated Branches:
refs/heads/master 02cd26c47 -> bcdb5a4e5
Updated the 'contains' method in stout IntervalSet to support more
types.
Review: https://reviews.apache.org/r/20898
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bcdb5a4e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bcdb5a4e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bcdb5a4e
Branch: refs/heads/master
Commit: bcdb5a4e53a01745f911230fe798a81e024f0aa0
Parents: 02cd26c
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Apr 30 14:13:10 2014 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Apr 30 14:13:10 2014 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/interval.hpp | 55 +++++++++++++++-----
.../3rdparty/stout/tests/interval_tests.cpp | 31 +++++++++++
2 files changed, 72 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/bcdb5a4e/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
index b219605..43a1e07 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
@@ -160,12 +160,26 @@ public:
Base::add((lower, upper));
}
- // Checks if the specified value is in this set.
+ // Checks if an element is in this set.
bool contains(const T& value) const
{
return boost::icl::contains(static_cast<const Base&>(*this), value);
}
+ // Checks if an interval is in this set.
+ bool contains(const Interval<T>& interval) const
+ {
+ return boost::icl::contains(static_cast<const Base&>(*this), interval);
+ }
+
+ // Checks if an interval set is a subset of this set.
+ bool contains(const IntervalSet<T>& set) const
+ {
+ return boost::icl::contains(
+ static_cast<const Base&>(*this),
+ static_cast<const Base&>(set));
+ }
+
// Returns the number of intervals in this set.
size_t intervalCount() const
{
@@ -173,32 +187,33 @@ public:
}
// Overloaded operators.
- template <typename X>
- IntervalSet<T>& operator += (const X& x)
+ IntervalSet<T>& operator += (const T& value)
{
- static_cast<Base&>(*this) += x;
+ static_cast<Base&>(*this) += value;
return *this;
}
- template <typename X>
- IntervalSet<T>& operator -= (const X& x)
+ IntervalSet<T>& operator += (const Interval<T>& interval)
{
- static_cast<Base&>(*this) -= x;
+ static_cast<Base&>(*this) += interval;
return *this;
}
- template <typename X>
- IntervalSet<T>& operator &= (const X& x)
+ IntervalSet<T>& operator += (const IntervalSet<T>& set)
{
- static_cast<Base&>(*this) &= x;
+ static_cast<Base&>(*this) += static_cast<const Base&>(set);
return *this;
}
- // Special overloads for IntervalSet. According to C++ standard,
- // a non-template function always wins an ambiguous overload.
- IntervalSet<T>& operator += (const IntervalSet<T>& set)
+ IntervalSet<T>& operator -= (const T& value)
{
- static_cast<Base&>(*this) += static_cast<const Base&>(set);
+ static_cast<Base&>(*this) -= value;
+ return *this;
+ }
+
+ IntervalSet<T>& operator -= (const Interval<T>& interval)
+ {
+ static_cast<Base&>(*this) -= interval;
return *this;
}
@@ -208,6 +223,18 @@ public:
return *this;
}
+ IntervalSet<T>& operator &= (const T& value)
+ {
+ static_cast<Base&>(*this) &= value;
+ return *this;
+ }
+
+ IntervalSet<T>& operator &= (const Interval<T>& interval)
+ {
+ static_cast<Base&>(*this) &= interval;
+ return *this;
+ }
+
IntervalSet<T>& operator &= (const IntervalSet<T>& set)
{
static_cast<Base&>(*this) &= static_cast<const Base&>(set);
http://git-wip-us.apache.org/repos/asf/mesos/blob/bcdb5a4e/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp
index 83a580b..7f709d5 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp
@@ -135,6 +135,37 @@ TEST(IntervalTest, Constructor)
}
+TEST(IntervalTest, Contains)
+{
+ IntervalSet<int> set;
+
+ set += (Bound<int>::closed(1), Bound<int>::closed(10));
+
+ EXPECT_TRUE(set.contains(1));
+ EXPECT_TRUE(set.contains(10));
+ EXPECT_FALSE(set.contains(11));
+ EXPECT_FALSE(set.contains(0));
+
+ EXPECT_TRUE(set.contains((Bound<int>::closed(2), Bound<int>::closed(10))));
+ EXPECT_TRUE(set.contains((Bound<int>::closed(2), Bound<int>::open(11))));
+ EXPECT_TRUE(set.contains((Bound<int>::open(2), Bound<int>::open(4))));
+ EXPECT_FALSE(set.contains((Bound<int>::closed(5), Bound<int>::closed(11))));
+ EXPECT_FALSE(set.contains((Bound<int>::open(0), Bound<int>::closed(20))));
+
+ IntervalSet<int> set2;
+
+ set2 += (Bound<int>::open(4), Bound<int>::open(10));
+
+ EXPECT_TRUE(set.contains(set2));
+ EXPECT_FALSE(set2.contains(set));
+
+ IntervalSet<int> set3;
+
+ EXPECT_TRUE(set.contains(set3));
+ EXPECT_FALSE(set3.contains(set2));
+}
+
+
TEST(IntervalTest, Addition)
{
IntervalSet<int> set;