[Bf-blender-cvs] [a9efbd6bcd0] functions: utility set functions
Jacques Lucke
noreply at git.blender.org
Sat Apr 27 13:25:42 CEST 2019
Commit: a9efbd6bcd02bb4e5d47f8297826b821a5212d09
Author: Jacques Lucke
Date: Sat Apr 27 12:21:13 2019 +0200
Branches: functions
https://developer.blender.org/rBa9efbd6bcd02bb4e5d47f8297826b821a5212d09
utility set functions
===================================================================
M source/blender/blenlib/BLI_small_set.hpp
M tests/gtests/blenlib/BLI_small_set_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_small_set.hpp b/source/blender/blenlib/BLI_small_set.hpp
index 55c4428235a..ea327f0758c 100644
--- a/source/blender/blenlib/BLI_small_set.hpp
+++ b/source/blender/blenlib/BLI_small_set.hpp
@@ -86,6 +86,21 @@ template<typename T, uint N = 4, typename Hash = std::hash<T>> class SmallSet {
return m_elements[0];
}
+ static bool Disjoint(const SmallSet &a, const SmallSet &b)
+ {
+ return !SmallSet::Intersects(a, b);
+ }
+
+ static bool Intersects(const SmallSet &a, const SmallSet &b)
+ {
+ for (const T &value : a) {
+ if (b.contains(value)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
T *begin() const
{
return m_elements.begin();
diff --git a/tests/gtests/blenlib/BLI_small_set_test.cc b/tests/gtests/blenlib/BLI_small_set_test.cc
index b364cea70cf..2d97780c3d9 100644
--- a/tests/gtests/blenlib/BLI_small_set_test.cc
+++ b/tests/gtests/blenlib/BLI_small_set_test.cc
@@ -122,3 +122,19 @@ TEST(small_set, RemoveMany)
}
}
}
+
+TEST(small_set, Intersects)
+{
+ IntSet a = {3, 4, 5, 6};
+ IntSet b = {1, 2, 5};
+ EXPECT_TRUE(IntSet::Intersects(a, b));
+ EXPECT_FALSE(IntSet::Disjoint(a, b));
+}
+
+TEST(small_set, Disjoint)
+{
+ IntSet a = {5, 6, 7, 8};
+ IntSet b = {2, 3, 4, 9};
+ EXPECT_FALSE(IntSet::Intersects(a, b));
+ EXPECT_TRUE(IntSet::Disjoint(a, b));
+}
More information about the Bf-blender-cvs
mailing list