[Bf-blender-cvs] [1a7507709f1] functions: get number of values stored per key in multimap
Jacques Lucke
noreply at git.blender.org
Tue Jul 2 16:11:58 CEST 2019
Commit: 1a7507709f113bb33b71693e983a8af3cce6b1ca
Author: Jacques Lucke
Date: Tue Jul 2 15:30:32 2019 +0200
Branches: functions
https://developer.blender.org/rB1a7507709f113bb33b71693e983a8af3cce6b1ca
get number of values stored per key in multimap
===================================================================
M source/blender/blenlib/BLI_multimap.hpp
M tests/gtests/blenlib/BLI_multimap_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_multimap.hpp b/source/blender/blenlib/BLI_multimap.hpp
index e6b2064d012..1e4e893fcc1 100644
--- a/source/blender/blenlib/BLI_multimap.hpp
+++ b/source/blender/blenlib/BLI_multimap.hpp
@@ -78,13 +78,18 @@ template<typename K, typename V> class MultiMap {
}
bool has_at_least_one_value(const K &key) const
+ {
+ return this->values_for_key(key) >= 1;
+ }
+
+ uint values_for_key(const K &key) const
{
Entry *entry = m_map.lookup_ptr(key);
if (entry == nullptr) {
- return false;
+ return 0;
}
else {
- return entry->length >= 1;
+ return entry->length;
}
}
diff --git a/tests/gtests/blenlib/BLI_multimap_test.cc b/tests/gtests/blenlib/BLI_multimap_test.cc
index 7638cf573a1..8fdee6a4713 100644
--- a/tests/gtests/blenlib/BLI_multimap_test.cc
+++ b/tests/gtests/blenlib/BLI_multimap_test.cc
@@ -49,3 +49,15 @@ TEST(multimap, AddMany)
EXPECT_EQ(map.lookup(6)[1], 16);
EXPECT_EQ(map.lookup(7).size(), 10);
}
+
+TEST(multimap, ValuesForKey)
+{
+ IntMap map;
+ map.add(3, 5);
+ map.add(3, 7);
+ map.add(3, 8);
+ map.add(4, 2);
+ map.add(4, 3);
+ EXPECT_EQ(map.values_for_key(3), 3);
+ EXPECT_EQ(map.values_for_key(4), 2);
+}
More information about the Bf-blender-cvs
mailing list