[Bf-blender-cvs] [3708e233b5e] functions: add multiple in multimap
Jacques Lucke
noreply at git.blender.org
Fri Jul 12 14:50:16 CEST 2019
Commit: 3708e233b5ef4e343f8aab87e211d48642bf31f9
Author: Jacques Lucke
Date: Fri Jul 12 09:16:44 2019 +0200
Branches: functions
https://developer.blender.org/rB3708e233b5ef4e343f8aab87e211d48642bf31f9
add multiple in multimap
===================================================================
M source/blender/blenlib/BLI_small_multimap.hpp
M tests/gtests/blenlib/BLI_small_multimap_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_small_multimap.hpp b/source/blender/blenlib/BLI_small_multimap.hpp
index 625d9107e7a..b075f71a790 100644
--- a/source/blender/blenlib/BLI_small_multimap.hpp
+++ b/source/blender/blenlib/BLI_small_multimap.hpp
@@ -69,6 +69,13 @@ template<typename K, typename V, uint N = 4> class SmallMultiMap {
return newly_inserted;
}
+ void add_multiple(const K &key, ArrayRef<V> values)
+ {
+ for (const V &value : values) {
+ this->add(key, value);
+ }
+ }
+
void add_new(const K &key, const V &value)
{
BLI_assert(!m_map.contains(key));
diff --git a/tests/gtests/blenlib/BLI_small_multimap_test.cc b/tests/gtests/blenlib/BLI_small_multimap_test.cc
index 5c6df5fa3bf..db7943e76b3 100644
--- a/tests/gtests/blenlib/BLI_small_multimap_test.cc
+++ b/tests/gtests/blenlib/BLI_small_multimap_test.cc
@@ -50,6 +50,22 @@ TEST(multimap, AddMany)
EXPECT_EQ(map.lookup(7).size(), 10);
}
+TEST(multimap, AddMultiple)
+{
+ IntMultiMap map;
+ map.add_multiple(2, {6, 7, 8});
+ map.add_multiple(3, {1, 2});
+ map.add_multiple(2, {9, 1});
+ EXPECT_EQ(map.key_amount(), 2);
+ EXPECT_EQ(map.lookup_default(2).size(), 5);
+ EXPECT_EQ(map.lookup_default(3).size(), 2);
+ EXPECT_EQ(map.lookup_default(2)[0], 6);
+ EXPECT_EQ(map.lookup_default(2)[1], 7);
+ EXPECT_EQ(map.lookup_default(2)[2], 8);
+ EXPECT_EQ(map.lookup_default(2)[3], 9);
+ EXPECT_EQ(map.lookup_default(2)[4], 1);
+}
+
TEST(multimap, AddMultipleNew)
{
IntMultiMap map;
More information about the Bf-blender-cvs
mailing list