[llvm-commits] [llvm] r122093 - in /llvm/trunk: include/llvm/ADT/IntervalMap.h unittests/ADT/IntervalMapTest.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Fri Dec 17 14:07:55 PST 2010
Author: stoklund
Date: Fri Dec 17 16:07:54 2010
New Revision: 122093
URL: http://llvm.org/viewvc/llvm-project?rev=122093&view=rev
Log:
Add more checks to IntervalMapOverlaps::advance() to ensure that advanceTo sees
monotonic keys.
Modified:
llvm/trunk/include/llvm/ADT/IntervalMap.h
llvm/trunk/unittests/ADT/IntervalMapTest.cpp
Modified: llvm/trunk/include/llvm/ADT/IntervalMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntervalMap.h?rev=122093&r1=122092&r2=122093&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IntervalMap.h (original)
+++ llvm/trunk/include/llvm/ADT/IntervalMap.h Fri Dec 17 16:07:54 2010
@@ -2040,6 +2040,21 @@
void advance() {
if (!valid())
return;
+
+ if (Traits::stopLess(posA.stop(), posB.start())) {
+ // A ends before B begins. Catch up.
+ posA.advanceTo(posB.start());
+ if (!posA.valid() || !Traits::stopLess(posB.stop(), posA.start()))
+ return;
+ } else if (Traits::stopLess(posB.stop(), posA.start())) {
+ // B ends before A begins. Catch up.
+ posB.advanceTo(posA.start());
+ if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
+ return;
+ } else
+ // Already overlapping.
+ return;
+
for (;;) {
// Make a.end > b.start.
posA.advanceTo(posB.start());
@@ -2076,7 +2091,7 @@
return Traits::startLess(ak, bk) ? bk : ak;
}
- /// stop - End of the overlaping interval.
+ /// stop - End of the overlapping interval.
KeyType stop() const {
KeyType ak = a().stop();
KeyType bk = b().stop();
@@ -2086,20 +2101,12 @@
/// skipA - Move to the next overlap that doesn't involve a().
void skipA() {
++posA;
- if (!posA.valid() || !Traits::stopLess(posB.stop(), posA.start()))
- return;
- // Second half-loop of advance().
- posB.advanceTo(posA.start());
- if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
- return;
advance();
}
/// skipB - Move to the next overlap that doesn't involve b().
void skipB() {
++posB;
- if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
- return;
advance();
}
@@ -2116,8 +2123,13 @@
/// advanceTo - Move to the first overlapping interval with
/// stopLess(x, stop()).
void advanceTo(KeyType x) {
- posA.advanceTo(x);
- posB.advanceTo(x);
+ if (!valid())
+ return;
+ // Make sure advanceTo sees monotonic keys.
+ if (Traits::stopLess(posA.stop(), x))
+ posA.advanceTo(x);
+ if (Traits::stopLess(posB.stop(), x))
+ posB.advanceTo(x);
advance();
}
};
Modified: llvm/trunk/unittests/ADT/IntervalMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/IntervalMapTest.cpp?rev=122093&r1=122092&r2=122093&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/IntervalMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/IntervalMapTest.cpp Fri Dec 17 16:07:54 2010
@@ -659,6 +659,19 @@
++AB;
EXPECT_FALSE(AB.valid());
+ // Test advanceTo.
+ UUOverlaps AB2(mapA, mapB);
+ AB2.advanceTo(410);
+ ASSERT_TRUE(AB2.valid());
+ EXPECT_EQ(410u, AB2.a().start());
+ EXPECT_EQ(402u, AB2.b().start());
+
+ // It is valid to advanceTo with any monotonic sequence.
+ AB2.advanceTo(411);
+ ASSERT_TRUE(AB2.valid());
+ EXPECT_EQ(410u, AB2.a().start());
+ EXPECT_EQ(402u, AB2.b().start());
+
// Check reversed maps.
UUOverlaps BA(mapB, mapA);
ASSERT_TRUE(BA.valid());
@@ -686,6 +699,18 @@
EXPECT_EQ(600u, BA.a().start());
++BA;
EXPECT_FALSE(BA.valid());
+
+ // Test advanceTo.
+ UUOverlaps BA2(mapB, mapA);
+ BA2.advanceTo(410);
+ ASSERT_TRUE(BA2.valid());
+ EXPECT_EQ(410u, BA2.b().start());
+ EXPECT_EQ(402u, BA2.a().start());
+
+ BA2.advanceTo(411);
+ ASSERT_TRUE(BA2.valid());
+ EXPECT_EQ(410u, BA2.b().start());
+ EXPECT_EQ(402u, BA2.a().start());
}
} // namespace
More information about the llvm-commits
mailing list