[Bf-blender-cvs] [d037390cd2f] functions: iterate keys of multimap

Jacques Lucke noreply at git.blender.org
Wed Jul 3 19:14:07 CEST 2019


Commit: d037390cd2fa7a0442369fd7424627cf11bef3f3
Author: Jacques Lucke
Date:   Wed Jul 3 16:13:35 2019 +0200
Branches: functions
https://developer.blender.org/rBd037390cd2fa7a0442369fd7424627cf11bef3f3

iterate keys of multimap

===================================================================

M	source/blender/blenlib/BLI_multimap.hpp
M	source/blender/blenlib/BLI_small_map.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 48a6d9dcd4f..eb66416ff88 100644
--- a/source/blender/blenlib/BLI_multimap.hpp
+++ b/source/blender/blenlib/BLI_multimap.hpp
@@ -110,6 +110,11 @@ template<typename K, typename V> class MultiMap {
       return ArrayRef<V>(entry->ptr, entry->length);
     }
   }
+
+  typename SmallMap<K, Entry>::KeysReturnT keys() const
+  {
+    return m_map.keys();
+  }
 };
 
 } /* namespace BLI */
diff --git a/source/blender/blenlib/BLI_small_map.hpp b/source/blender/blenlib/BLI_small_map.hpp
index e010fe4198d..f986c66ede6 100644
--- a/source/blender/blenlib/BLI_small_map.hpp
+++ b/source/blender/blenlib/BLI_small_map.hpp
@@ -231,7 +231,8 @@ template<typename K, typename V, uint N = 4> class SmallMap {
     return entry.key;
   }
 
-  MappedArrayRef<Entry, const K &, get_key_from_entry> keys() const
+  using KeysReturnT = MappedArrayRef<Entry, const K &, get_key_from_entry>;
+  KeysReturnT keys() const
   {
     return MappedArrayRef<Entry, const K &, get_key_from_entry>(m_entries.begin(),
                                                                 m_entries.size());
diff --git a/tests/gtests/blenlib/BLI_multimap_test.cc b/tests/gtests/blenlib/BLI_multimap_test.cc
index 8fdee6a4713..9f3f73dd9de 100644
--- a/tests/gtests/blenlib/BLI_multimap_test.cc
+++ b/tests/gtests/blenlib/BLI_multimap_test.cc
@@ -61,3 +61,22 @@ TEST(multimap, ValuesForKey)
   EXPECT_EQ(map.values_for_key(3), 3);
   EXPECT_EQ(map.values_for_key(4), 2);
 }
+
+TEST(multimap, Keys)
+{
+  IntMap map;
+  map.add(3, 6);
+  map.add(3, 3);
+  map.add(3, 4);
+  map.add(4, 1);
+  map.add(2, 1);
+
+  SmallVector<int> values;
+  for (auto value : map.keys()) {
+    values.append(value);
+  }
+  EXPECT_EQ(values.size(), 3);
+  EXPECT_TRUE(values.contains(3));
+  EXPECT_TRUE(values.contains(4));
+  EXPECT_TRUE(values.contains(2));
+}



More information about the Bf-blender-cvs mailing list