/// Advances cursor to the next item.
void advance() override {
- assert(!reachedEnd() && "DocumentIterator can't advance at the end.");
+ assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
++Index;
}
/// Applies binary search to advance cursor to the next item with DocID equal
/// or higher than the given one.
void advanceTo(DocID ID) override {
- assert(!reachedEnd() && "DocumentIterator can't advance at the end.");
+ assert(!reachedEnd() && "DOCUMENT iterator can't advance() at the end.");
Index = std::lower_bound(Index, std::end(Documents), ID);
}
DocID peek() const override {
- assert(!reachedEnd() && "DocumentIterator can't call peek() at the end.");
+ assert(!reachedEnd() && "DOCUMENT iterator can't peek() at the end.");
return *Index;
}
- float consume() override { return DEFAULT_BOOST_SCORE; }
+ float consume() override {
+ assert(!reachedEnd() && "DOCUMENT iterator can't consume() at the end.");
+ return DEFAULT_BOOST_SCORE;
+ }
size_t estimateSize() const override { return Documents.size(); }
public:
AndIterator(std::vector<std::unique_ptr<Iterator>> AllChildren)
: Children(std::move(AllChildren)) {
- assert(!Children.empty() && "AndIterator should have at least one child.");
+ assert(!Children.empty() && "AND iterator should have at least one child.");
// Establish invariants.
sync();
// When children are sorted by the estimateSize(), sync() calls are more
/// Advances all children to the next common item.
void advance() override {
- assert(!reachedEnd() && "AndIterator can't call advance() at the end.");
+ assert(!reachedEnd() && "AND iterator can't advance() at the end.");
Children.front()->advance();
sync();
}
/// Advances all children to the next common item with DocumentID >= ID.
void advanceTo(DocID ID) override {
- assert(!reachedEnd() && "AndIterator can't call advanceTo() at the end.");
+ assert(!reachedEnd() && "AND iterator can't advanceTo() at the end.");
Children.front()->advanceTo(ID);
sync();
}
DocID peek() const override { return Children.front()->peek(); }
float consume() override {
- assert(!reachedEnd() && "AndIterator can't consume() at the end.");
+ assert(!reachedEnd() && "AND iterator can't consume() at the end.");
return std::accumulate(
begin(Children), end(Children), DEFAULT_BOOST_SCORE,
[&](float Current, const std::unique_ptr<Iterator> &Child) {
public:
OrIterator(std::vector<std::unique_ptr<Iterator>> AllChildren)
: Children(std::move(AllChildren)) {
- assert(Children.size() > 0 && "Or Iterator must have at least one child.");
+ assert(Children.size() > 0 && "OR iterator must have at least one child.");
}
/// Returns true if all children are exhausted.
/// Moves each child pointing to the smallest DocID to the next item.
void advance() override {
- assert(!reachedEnd() &&
- "OrIterator can't call advance() after it reached the end.");
+ assert(!reachedEnd() && "OR iterator can't advance() at the end.");
const auto SmallestID = peek();
for (const auto &Child : Children)
if (!Child->reachedEnd() && Child->peek() == SmallestID)
/// Advances each child to the next existing element with DocumentID >= ID.
void advanceTo(DocID ID) override {
- assert(!reachedEnd() && "Can't advance iterator after it reached the end.");
+ assert(!reachedEnd() && "OR iterator can't advanceTo() at the end.");
for (const auto &Child : Children)
if (!Child->reachedEnd())
Child->advanceTo(ID);
/// Returns the element under cursor of the child with smallest Child->peek()
/// value.
DocID peek() const override {
- assert(!reachedEnd() &&
- "OrIterator can't peek() after it reached the end.");
+ assert(!reachedEnd() && "OR iterator can't peek() at the end.");
DocID Result = std::numeric_limits<DocID>::max();
for (const auto &Child : Children)
// Returns the maximum boosting score among all Children when iterator is not
// exhausted and points to the given ID, DEFAULT_BOOST_SCORE otherwise.
float consume() override {
- assert(!reachedEnd() &&
- "OrIterator can't consume() after it reached the end.");
+ assert(!reachedEnd() && "OR iterator can't consume() at the end.");
const DocID ID = peek();
return std::accumulate(
begin(Children), end(Children), DEFAULT_BOOST_SCORE,
bool reachedEnd() const override { return Index >= Size; }
void advance() override {
- assert(!reachedEnd() && "Can't advance iterator after it reached the end.");
+ assert(!reachedEnd() && "TRUE iterator can't advance() at the end.");
++Index;
}
void advanceTo(DocID ID) override {
- assert(!reachedEnd() && "Can't advance iterator after it reached the end.");
+ assert(!reachedEnd() && "TRUE iterator can't advanceTo() at the end.");
Index = std::min(ID, Size);
}
DocID peek() const override {
- assert(!reachedEnd() && "TrueIterator can't call peek() at the end.");
+ assert(!reachedEnd() && "TRUE iterator can't peek() at the end.");
return Index;
}
- float consume() override { return DEFAULT_BOOST_SCORE; }
+ float consume() override {
+ assert(!reachedEnd() && "TRUE iterator can't consume() at the end.");
+ return DEFAULT_BOOST_SCORE;
+ }
size_t estimateSize() const override { return Size; }
/// Decreases the limit in case the element consumed at top of the query tree
/// comes from the underlying iterator.
float consume() override {
- assert(!reachedEnd() && "LimitIterator can't consume at the end.");
+ assert(!reachedEnd() && "LimitIterator can't consume() at the end.");
--ItemsLeft;
return Child->consume();
}
std::vector<std::pair<DocID, float>> consume(Iterator &It) {
std::vector<std::pair<DocID, float>> Result;
for (; !It.reachedEnd(); It.advance())
- Result.push_back(std::make_pair(It.peek(), It.consume()));
+ Result.emplace_back(It.peek(), It.consume());
return Result;
}
}
std::unique_ptr<Iterator> createLimit(std::unique_ptr<Iterator> Child,
- size_t Size) {
- return llvm::make_unique<LimitIterator>(move(Child), Size);
+ size_t Limit) {
+ return llvm::make_unique<LimitIterator>(move(Child), Limit);
}
} // namespace dex