Baloo

andpostingiterator.cpp
1/*
2 This file is part of the KDE Baloo project.
3 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "andpostingiterator.h"
9
10using namespace Baloo;
11
12AndPostingIterator::AndPostingIterator(const QVector<PostingIterator*>& iterators)
13 : m_iterators(iterators)
14 , m_docId(0)
15{
16 if (m_iterators.contains(nullptr)) {
17 qDeleteAll(m_iterators);
18 m_iterators.clear();
19 }
20}
21
22AndPostingIterator::~AndPostingIterator()
23{
24 qDeleteAll(m_iterators);
25}
26
27quint64 AndPostingIterator::docId() const
28{
29 return m_docId;
30}
31
32quint64 AndPostingIterator::skipTo(quint64 id)
33{
34 if (m_iterators.isEmpty()) {
35 m_docId = 0;
36 return 0;
37 }
38
39 while (true) {
40 quint64 lower_bound = id;
41 for (PostingIterator* iter : std::as_const(m_iterators)) {
42 lower_bound = iter->skipTo(lower_bound);
43
44 if (lower_bound == 0) {
45 m_docId = 0;
46 return 0;
47 }
48 }
49
50 if (lower_bound == id) {
51 m_docId = lower_bound;
52 return lower_bound;
53 }
54 id = lower_bound;
55 }
56}
57
58quint64 AndPostingIterator::next()
59{
60 if (m_iterators.isEmpty()) {
61 m_docId = 0;
62 return 0;
63 }
64
65 m_docId = m_iterators[0]->next();
66 m_docId = skipTo(m_docId);
67
68 return m_docId;
69}
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:
Definition coding.cpp:11
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.