8#include "phraseanditerator.h"
9#include "positioninfo.h"
14 : m_iterators(iterators)
17 if (m_iterators.contains(
nullptr)) {
18 qDeleteAll(m_iterators);
23PhraseAndIterator::~PhraseAndIterator()
25 qDeleteAll(m_iterators);
28quint64 PhraseAndIterator::docId()
const
33bool PhraseAndIterator::checkIfPositionsMatch()
35 using Offset =
decltype(m_iterators[0]->positions().size());
36 using Position = std::remove_reference<
decltype(m_iterators[0]->positions()[0])>::type;
38 std::vector<Offset> offsets;
39 offsets.resize(m_iterators.size());
41 const auto firstPositions = m_iterators[0]->positions();
42 Position lower_bound = 0;
44 while (offsets[0] < firstPositions.size()) {
45 for (
int i = 0; i < m_iterators.size(); i++) {
46 const auto positions = m_iterators[i]->positions();
47 Offset off = offsets[i];
49 for (; off < positions.size(); ++off) {
50 Position pos = positions[off];
53 if (pos >= (lower_bound + i)) {
54 lower_bound = pos - i;
58 if (off >= positions.size()) {
64 if (lower_bound == firstPositions[offsets[0]]) {
66 for (
int i = 0; i < m_iterators.size(); i++) {
67 auto positions = m_iterators[i]->positions();
77quint64 PhraseAndIterator::skipTo(quint64
id)
79 if (m_iterators.isEmpty()) {
85 quint64 lower_bound = id;
87 lower_bound = iter->skipTo(lower_bound);
89 if (lower_bound == 0) {
95 if (lower_bound ==
id) {
96 if (checkIfPositionsMatch()) {
97 m_docId = lower_bound;
100 lower_bound = m_iterators[0]->next();
107quint64 PhraseAndIterator::next()
109 if (m_iterators.isEmpty()) {
114 m_docId = m_iterators[0]->next();
115 m_docId = skipTo(m_docId);
A PostingIterator is an abstract base class which can be used to iterate over all the "postings" or "...
Implements storage for docIds without any associated data Instantiated for: