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/05/10 00:17:32 UTC

git commit: Added intersection test for stout Interval and IntervalSet.

Repository: mesos
Updated Branches:
  refs/heads/master 5a8eaa2f4 -> 93c719928


Added intersection test for stout Interval and IntervalSet.

Review: https://reviews.apache.org/r/21190


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/93c71992
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/93c71992
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/93c71992

Branch: refs/heads/master
Commit: 93c7199283d1199db138eeee5fd8247ac1b4bda2
Parents: 5a8eaa2
Author: Jie Yu <yu...@gmail.com>
Authored: Fri May 9 15:17:14 2014 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri May 9 15:17:14 2014 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/interval.hpp   | 38 ++++++++++++++++++++
 .../3rdparty/stout/tests/interval_tests.cpp     | 28 +++++++++++++++
 2 files changed, 66 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/93c71992/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 c84e0c6..2423f67 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/interval.hpp
@@ -27,6 +27,10 @@ template <typename T>
 class Interval;
 
 
+template <typename T>
+class IntervalSet;
+
+
 // Represents a bound (left or right) for an interval. A bound can
 // either be open or closed.
 template <typename T>
@@ -82,6 +86,12 @@ public:
   // Returns the exclusive upper bound of this interval.
   T upper() const { return data.upper(); }
 
+  // Checks if this interval intersects with another interval.
+  bool intersects(const Interval<T>& interval) const;
+
+  // Checks if this interval intersects with an interval set.
+  bool intersects(const IntervalSet<T>& set) const;
+
 private:
   friend class Bound<T>;
 
@@ -197,6 +207,20 @@ public:
         static_cast<const Base&>(set));
   }
 
+  // Checks if this set intersects with an interval.
+  bool intersects(const Interval<T>& interval) const
+  {
+    return boost::icl::intersects(static_cast<const Base&>(*this), interval);
+  }
+
+  // Checks if this set intersects with another interval set.
+  bool intersects(const IntervalSet<T>& set) const
+  {
+    return boost::icl::intersects(
+        static_cast<const Base&>(*this),
+        static_cast<const Base&>(set));
+  }
+
   // Returns the number of intervals in this set.
   size_t intervalCount() const
   {
@@ -276,6 +300,20 @@ std::ostream& operator << (std::ostream& stream, const IntervalSet<T>& set)
 }
 
 
+template <typename T>
+bool Interval<T>::intersects(const Interval<T>& interval) const
+{
+  return IntervalSet<T>(*this).intersects(interval);
+}
+
+
+template <typename T>
+bool Interval<T>::intersects(const IntervalSet<T>& set) const
+{
+  return set.intersects(*this);
+}
+
+
 // Defines type traits for the custom Interval above. These type
 // traits are required by the boost interval set.
 namespace boost {

http://git-wip-us.apache.org/repos/asf/mesos/blob/93c71992/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 ecca829..b251d88 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/interval_tests.cpp
@@ -274,6 +274,34 @@ TEST(IntervalTest, Intersection)
 }
 
 
+TEST(IntervalTest, IntersectionTest)
+{
+  Interval<int> interval((Bound<int>::open(4), Bound<int>::closed(6)));
+  Interval<int> interval2((Bound<int>::closed(1), Bound<int>::closed(5)));
+  Interval<int> interval3((Bound<int>::closed(7), Bound<int>::closed(8)));
+
+  IntervalSet<int> set((Bound<int>::closed(1), Bound<int>::closed(3)));
+  IntervalSet<int> set2((Bound<int>::open(2), Bound<int>::open(4)));
+  IntervalSet<int> set3((Bound<int>::open(6), Bound<int>::closed(7)));
+
+  EXPECT_FALSE(set.intersects(interval));
+  EXPECT_TRUE(set2.intersects(interval2));
+  EXPECT_TRUE(set3.intersects(interval3));
+
+  EXPECT_FALSE(set2.intersects(interval));
+  EXPECT_TRUE(set2.intersects(interval2));
+  EXPECT_FALSE(set2.intersects(interval3));
+
+  EXPECT_TRUE(set.intersects(set2));
+  EXPECT_TRUE(set2.intersects(set));
+  EXPECT_FALSE(set3.intersects(set2));
+
+  EXPECT_TRUE(interval.intersects(interval2));
+  EXPECT_FALSE(interval2.intersects(interval3));
+  EXPECT_FALSE(interval3.intersects(interval));
+}
+
+
 TEST(IntervalTest, LargeInterval)
 {
   IntervalSet<int> set;