Add size_t MapVector::erase(KeyT) similar to the one in std::map.
authorKaelyn Takata <rikka@google.com>
Tue, 7 Oct 2014 21:15:51 +0000 (21:15 +0000)
committerKaelyn Takata <rikka@google.com>
Tue, 7 Oct 2014 21:15:51 +0000 (21:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219240 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/MapVector.h
unittests/ADT/MapVectorTest.cpp

index 4e1fc1527270f27e06a7094602a887bbc4041d7b..d82c5799f4415faecf446cff8e868889037c48de 100644 (file)
@@ -147,6 +147,17 @@ public:
     return Next;
   }
 
+  /// \brief Remove all elements with the key value Key.
+  ///
+  /// Returns the number of elements removed.
+  size_type erase(const KeyT &Key) {
+    auto Iterator = find(Key);
+    if (Iterator == end())
+      return 0;
+    erase(Iterator);
+    return 1;
+  }
+
   /// \brief Remove the elements that match the predicate.
   ///
   /// Erase all elements that match \c Pred in a single pass.  Takes linear
index 92f0dc41910b2ff8c6924c3fb7f03f68d20bc12e..0580580977e6ae95d0abebd18eaba689e04fb08c 100644 (file)
@@ -67,6 +67,11 @@ TEST(MapVectorTest, erase) {
   ASSERT_EQ(MV.find(1), MV.end());
   ASSERT_EQ(MV[3], 4);
   ASSERT_EQ(MV[5], 6);
+
+  MV.erase(3);
+  ASSERT_EQ(MV.size(), 1u);
+  ASSERT_EQ(MV.find(3), MV.end());
+  ASSERT_EQ(MV[5], 6);
 }
 
 TEST(MapVectorTest, remove_if) {