You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by zh...@apache.org on 2018/04/09 19:11:56 UTC

[1/2] mesos git commit: Added test for difference operator of hashset.

Repository: mesos
Updated Branches:
  refs/heads/master 7b14bf72b -> be47e96e7


Added test for difference operator of hashset.

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


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

Branch: refs/heads/master
Commit: be47e96e727f07758ff9b8ba1c23bbec2a489cd6
Parents: 0cd8723
Author: Zhitao Li <zh...@gmail.com>
Authored: Tue Mar 27 15:12:42 2018 -0700
Committer: Zhitao Li <zh...@gmail.com>
Committed: Mon Apr 9 10:46:02 2018 -0700

----------------------------------------------------------------------
 3rdparty/stout/tests/hashset_tests.cpp | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/be47e96e/3rdparty/stout/tests/hashset_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/hashset_tests.cpp b/3rdparty/stout/tests/hashset_tests.cpp
index d2b7bf2..615e5e8 100644
--- a/3rdparty/stout/tests/hashset_tests.cpp
+++ b/3rdparty/stout/tests/hashset_tests.cpp
@@ -161,3 +161,31 @@ TEST(HashsetTest, Union)
 
   ASSERT_EQ(hs3, hs4);
 }
+
+
+TEST(HashsetTest, Difference)
+{
+  hashset<int> hs1;
+  hs1.insert(1);
+  hs1.insert(2);
+  hs1.insert(3);
+
+  hashset<int> hs2;
+  hs2.insert(3);
+  hs2.insert(4);
+  hs2.insert(5);
+
+  hashset<int> hs3 = hs1 - hs2;
+
+  ASSERT_EQ(2u, hs3.size());
+  ASSERT_TRUE(hs3.contains(1));
+  ASSERT_TRUE(hs3.contains(2));
+  ASSERT_FALSE(hs3.contains(3));
+  ASSERT_FALSE(hs3.contains(4));
+  ASSERT_FALSE(hs3.contains(5));
+
+  hashset<int> hs4 = hs1;
+  hs4 -= hs2;
+
+  ASSERT_EQ(hs3, hs4);
+}


[2/2] mesos git commit: Added difference operator overload for hashset.

Posted by zh...@apache.org.
Added difference operator overload for hashset.

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


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

Branch: refs/heads/master
Commit: 0cd87235ea75a946100e1b5aa0b110852ab4958f
Parents: 7b14bf7
Author: Zhitao Li <zh...@gmail.com>
Authored: Tue Mar 27 15:12:26 2018 -0700
Committer: Zhitao Li <zh...@gmail.com>
Committed: Mon Apr 9 10:46:02 2018 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/hashset.hpp | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0cd87235/3rdparty/stout/include/stout/hashset.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/hashset.hpp b/3rdparty/stout/include/stout/hashset.hpp
index 6af209c..2b86e5b 100644
--- a/3rdparty/stout/include/stout/hashset.hpp
+++ b/3rdparty/stout/include/stout/hashset.hpp
@@ -162,4 +162,30 @@ hashset<Elem, Hash, Equal>& operator|=(
   return left;
 }
 
+
+// Difference operator.
+template <typename Elem, typename Hash, typename Equal>
+hashset<Elem, Hash, Equal> operator-(
+    const hashset<Elem, Hash, Equal>& left,
+    const hashset<Elem, Hash, Equal>& right)
+{
+  hashset<Elem, Hash, Equal> result = left;
+  result -= right;
+  return result;
+}
+
+
+// Difference assignment operator.
+template <typename Elem, typename Hash, typename Equal>
+hashset<Elem, Hash, Equal>& operator-=(
+    hashset<Elem, Hash, Equal>& left,
+    const hashset<Elem, Hash, Equal>& right)
+{
+  foreach (const Elem& elem, right) {
+    left.erase(elem);
+  }
+
+  return left;
+}
+
 #endif // __STOUT_HASHSET_HPP__