/// either meets end.
/// Don't move the iterators if they are already overlapping.
void advance() {
+ if (!valid())
+ return;
for (;;) {
// Make a.end > b.start.
posA.advanceTo(posB.start());
/// IntervalMapOverlaps - Create an iterator for the overlaps of a and b.
IntervalMapOverlaps(const MapA &a, const MapB &b)
: posA(b.empty() ? a.end() : a.find(b.start())),
- posB(posA.valid() ? b.find(posA.start()) : b.end()) {
- if (valid())
- advance();
- }
+ posB(posA.valid() ? b.find(posA.start()) : b.end()) { advance(); }
/// valid - Return true if iterator is at an overlap.
bool valid() const {
// Second half-loop of advance().
posB.advanceTo(posA.start());
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
- return ;
+ return;
advance();
}
void skipB() {
++posB;
if (!posB.valid() || !Traits::stopLess(posA.stop(), posB.start()))
- return;
+ return;
advance();
}
ASSERT_TRUE(BA.valid());
EXPECT_EQ(3u, BA.a().start());
EXPECT_EQ(4u, BA.b().start());
- ++BA;
+ // advance past end.
+ BA.advanceTo(6);
+ EXPECT_FALSE(BA.valid());
+ // advance an invalid iterator.
+ BA.advanceTo(7);
EXPECT_FALSE(BA.valid());
}