aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/MapVectorTest.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-07-15 20:24:56 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-07-15 20:24:56 +0000
commitf51601c856d38b5654f933e30b887282f7676399 (patch)
treea25d8458078def575156e718d748161fd3554009 /llvm/unittests/ADT/MapVectorTest.cpp
parente9fa3b8e6bb9a8d6d6674058c18b264cce83b026 (diff)
downloadllvm-f51601c856d38b5654f933e30b887282f7676399.zip
llvm-f51601c856d38b5654f933e30b887282f7676399.tar.gz
llvm-f51601c856d38b5654f933e30b887282f7676399.tar.bz2
ADT: Add MapVector::remove_if
Add a `MapVector::remove_if()` that erases items in bulk in linear time, as opposed to quadratic time for repeated calls to `MapVector::erase()`. llvm-svn: 213090
Diffstat (limited to 'llvm/unittests/ADT/MapVectorTest.cpp')
-rw-r--r--llvm/unittests/ADT/MapVectorTest.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp
index dd84e7e..92f0dc4 100644
--- a/llvm/unittests/ADT/MapVectorTest.cpp
+++ b/llvm/unittests/ADT/MapVectorTest.cpp
@@ -68,3 +68,24 @@ TEST(MapVectorTest, erase) {
ASSERT_EQ(MV[3], 4);
ASSERT_EQ(MV[5], 6);
}
+
+TEST(MapVectorTest, remove_if) {
+ MapVector<int, int> MV;
+
+ MV.insert(std::make_pair(1, 11));
+ MV.insert(std::make_pair(2, 12));
+ MV.insert(std::make_pair(3, 13));
+ MV.insert(std::make_pair(4, 14));
+ MV.insert(std::make_pair(5, 15));
+ MV.insert(std::make_pair(6, 16));
+ ASSERT_EQ(MV.size(), 6u);
+
+ MV.remove_if([](const std::pair<int, int> &Val) { return Val.second % 2; });
+ ASSERT_EQ(MV.size(), 3u);
+ ASSERT_EQ(MV.find(1), MV.end());
+ ASSERT_EQ(MV.find(3), MV.end());
+ ASSERT_EQ(MV.find(5), MV.end());
+ ASSERT_EQ(MV[2], 12);
+ ASSERT_EQ(MV[4], 14);
+ ASSERT_EQ(MV[6], 16);
+}