summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaelyn Takata <rikka@google.com>2014-10-07 21:15:51 +0000
committerKaelyn Takata <rikka@google.com>2014-10-07 21:15:51 +0000
commit6ad1eb4b02523a08ef6583b9d9062e2e64e80d80 (patch)
tree1fbbac6936117a7db229dfddfca95d18acdec469
parent9b4d37e8f57e266cb3c2b7050cb2dc6113be3927 (diff)
downloadbcm5719-llvm-6ad1eb4b02523a08ef6583b9d9062e2e64e80d80.tar.gz
bcm5719-llvm-6ad1eb4b02523a08ef6583b9d9062e2e64e80d80.zip
Add size_t MapVector::erase(KeyT) similar to the one in std::map.
llvm-svn: 219240
-rw-r--r--llvm/include/llvm/ADT/MapVector.h11
-rw-r--r--llvm/unittests/ADT/MapVectorTest.cpp5
2 files changed, 16 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/MapVector.h b/llvm/include/llvm/ADT/MapVector.h
index 4e1fc152727..d82c5799f44 100644
--- a/llvm/include/llvm/ADT/MapVector.h
+++ b/llvm/include/llvm/ADT/MapVector.h
@@ -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
diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp
index 92f0dc41910..0580580977e 100644
--- a/llvm/unittests/ADT/MapVectorTest.cpp
+++ b/llvm/unittests/ADT/MapVectorTest.cpp
@@ -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) {
OpenPOWER on IntegriCloud