aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/IntervalMapTest.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2010-11-27 21:12:36 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2010-11-27 21:12:36 +0000
commitbb4bece21169df26fe98aa056be59e22d1957284 (patch)
tree53c2d3a08c7baf3dcac9e30f94b21131bece91ef /llvm/unittests/ADT/IntervalMapTest.cpp
parent5d882894d849cbb7bd9d4520beb71ef395fb7f84 (diff)
downloadllvm-bb4bece21169df26fe98aa056be59e22d1957284.zip
llvm-bb4bece21169df26fe98aa056be59e22d1957284.tar.gz
llvm-bb4bece21169df26fe98aa056be59e22d1957284.tar.bz2
Add test case with randomly ordered insertions, massive coalescing.
Implement iterator::erase() in a simple version that erases nodes when they become empty, but doesn't try to redistribute elements among siblings for better packing. Handle coalescing across leaf nodes which may require erasing entries. llvm-svn: 120226
Diffstat (limited to 'llvm/unittests/ADT/IntervalMapTest.cpp')
-rw-r--r--llvm/unittests/ADT/IntervalMapTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/IntervalMapTest.cpp b/llvm/unittests/ADT/IntervalMapTest.cpp
index 36476a4..c0653621 100644
--- a/llvm/unittests/ADT/IntervalMapTest.cpp
+++ b/llvm/unittests/ADT/IntervalMapTest.cpp
@@ -424,4 +424,28 @@ TEST(IntervalMapTest, Branched2) {
EXPECT_TRUE(map.begin() == map.end());
}
+// Random insertions, coalescing to a single interval.
+TEST(IntervalMapTest, RandomCoalescing) {
+ UU4Map::Allocator allocator;
+ UU4Map map(allocator);
+
+ // This is a poor PRNG with maximal period:
+ // x_n = 5 x_{n-1} + 1 mod 2^N
+
+ unsigned x = 100;
+ for (unsigned i = 0; i != 4096; ++i) {
+ map.insert(10*x, 10*x+9, 1);
+ EXPECT_GE(10*x, map.start());
+ EXPECT_LE(10*x+9, map.stop());
+ x = (5*x+1)%4096;
+ }
+
+ // Map should be fully coalesced after that exercise.
+ EXPECT_FALSE(map.empty());
+ EXPECT_EQ(0u, map.start());
+ EXPECT_EQ(40959u, map.stop());
+ EXPECT_EQ(1, std::distance(map.begin(), map.end()));
+
+}
+
} // namespace