}
bool next() {
- if (UNLIKELY(progress_ == list_.size)) {
- value_ = std::numeric_limits<ValueType>::max();
- return false;
+ if (UNLIKELY(progress_ >= list_.size)) {
+ return setDone();
}
value_ = readLowerPart(progress_) |
(upper_.next() << list_.numLowerBits);
return true;
}
- progress_ = list_.size;
- value_ = std::numeric_limits<ValueType>::max();
- return false;
+ return setDone();
}
bool skipTo(ValueType value) {
if (value <= value_) {
return true;
} else if (value > lastValue_) {
- progress_ = list_.size;
- value_ = std::numeric_limits<ValueType>::max();
- return false;
+ return setDone();
}
size_t upperValue = (value >> list_.numLowerBits);
reset();
return true;
}
- progress_ = list_.size;
- value_ = std::numeric_limits<ValueType>::max();
- return false;
+ return setDone();
}
- ValueType jumpTo(ValueType value) {
+ bool jumpTo(ValueType value) {
if (value <= 0) {
reset();
return true;
} else if (value > lastValue_) {
- progress_ = list_.size;
- value_ = std::numeric_limits<ValueType>::max();
- return false;
+ return setDone();
}
upper_.jumpToNext(value >> list_.numLowerBits);
ValueType value() const { return value_; }
private:
+ bool setDone() {
+ value_ = std::numeric_limits<ValueType>::max();
+ progress_ = list_.size + 1;
+ return false;
+ }
+
ValueType readLowerPart(size_t i) const {
DCHECK_LT(i, list_.size);
const size_t pos = i * list_.numLowerBits;
}
EXPECT_FALSE(reader.next());
EXPECT_EQ(reader.value(), std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(reader.position(), reader.size() - 1);
+ EXPECT_EQ(reader.position(), reader.size());
}
template <class Reader, class List>
}
EXPECT_FALSE(reader.skip(skipStep));
EXPECT_EQ(reader.value(), std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(reader.position(), reader.size() - 1);
+ EXPECT_EQ(reader.position(), reader.size());
EXPECT_FALSE(reader.next());
}
value = reader.value() + delta;
}
EXPECT_EQ(reader.value(), std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(reader.position(), reader.size() - 1);
+ EXPECT_EQ(reader.position(), reader.size());
EXPECT_FALSE(reader.next());
}
Reader reader(list);
EXPECT_FALSE(reader.skipTo(data.back() + 1));
EXPECT_EQ(reader.value(), std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(reader.position(), reader.size() - 1);
+ EXPECT_EQ(reader.position(), reader.size());
EXPECT_FALSE(reader.next());
}
}
}
EXPECT_FALSE(reader.jump(data.size() + 1));
EXPECT_EQ(reader.value(), std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(reader.position(), reader.size() - 1);
+ EXPECT_EQ(reader.position(), reader.size());
}
template <class Reader, class List>
EXPECT_FALSE(reader.jumpTo(data.back() + 1));
EXPECT_EQ(reader.value(), std::numeric_limits<uint32_t>::max());
- EXPECT_EQ(reader.position(), reader.size() - 1);
+ EXPECT_EQ(reader.position(), reader.size());
}
template <class Reader, class Encoder>