summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/MapVectorTest.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-07-15 18:32:30 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-07-15 18:32:30 +0000
commitdb88e31e1aad26f1067017a88234e261f369c682 (patch)
treee26b50ca93480b39d06e61124f85ff1584f71a52 /llvm/unittests/ADT/MapVectorTest.cpp
parenteeb7e65c5fca09825cfcd7a24a7670bbcb010cbb (diff)
downloadbcm5719-llvm-db88e31e1aad26f1067017a88234e261f369c682.tar.gz
bcm5719-llvm-db88e31e1aad26f1067017a88234e261f369c682.zip
ADT: Fix MapVector::erase()
Actually update the changed indexes in the map portion of `MapVector` when erasing from the middle. Add a unit test that checks for this. Note that `MapVector::erase()` is a linear time operation (it was and still is). I'll commit a new method in a moment called `MapVector::remove_if()` that deletes multiple entries in linear time, which should be slightly less painful. llvm-svn: 213084
Diffstat (limited to 'llvm/unittests/ADT/MapVectorTest.cpp')
-rw-r--r--llvm/unittests/ADT/MapVectorTest.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp
index 11178bc15e8..dd84e7ebd13 100644
--- a/llvm/unittests/ADT/MapVectorTest.cpp
+++ b/llvm/unittests/ADT/MapVectorTest.cpp
@@ -53,3 +53,18 @@ TEST(MapVectorTest, insert_pop) {
EXPECT_EQ(MV[1], 2);
EXPECT_EQ(MV[4], 7);
}
+
+TEST(MapVectorTest, erase) {
+ MapVector<int, int> MV;
+
+ MV.insert(std::make_pair(1, 2));
+ MV.insert(std::make_pair(3, 4));
+ MV.insert(std::make_pair(5, 6));
+ ASSERT_EQ(MV.size(), 3u);
+
+ MV.erase(MV.find(1));
+ ASSERT_EQ(MV.size(), 2u);
+ ASSERT_EQ(MV.find(1), MV.end());
+ ASSERT_EQ(MV[3], 4);
+ ASSERT_EQ(MV[5], 6);
+}
OpenPOWER on IntegriCloud