[llvm] r219240 - Add size_t MapVector::erase(KeyT) similar to the one in std::map.

Kaelyn Takata rikka at google.com
Tue Oct 7 14:15:52 PDT 2014


Author: rikka
Date: Tue Oct  7 16:15:51 2014
New Revision: 219240

URL: http://llvm.org/viewvc/llvm-project?rev=219240&view=rev
Log:
Add size_t MapVector::erase(KeyT) similar to the one in std::map.

Modified:
    llvm/trunk/include/llvm/ADT/MapVector.h
    llvm/trunk/unittests/ADT/MapVectorTest.cpp

Modified: llvm/trunk/include/llvm/ADT/MapVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=219240&r1=219239&r2=219240&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/MapVector.h (original)
+++ llvm/trunk/include/llvm/ADT/MapVector.h Tue Oct  7 16:15:51 2014
@@ -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

Modified: llvm/trunk/unittests/ADT/MapVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/MapVectorTest.cpp?rev=219240&r1=219239&r2=219240&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/MapVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/MapVectorTest.cpp Tue Oct  7 16:15:51 2014
@@ -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) {





More information about the llvm-commits mailing list