aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.cpp
blob: 3bd1682c4708eae6282e84e9cea55010c32dc5da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "posting_iterator_pack.h"
#include <vespa/searchlib/common/bitvector.h>
#include <limits>

namespace search {

template <typename IteratorType, typename RefType>
PostingIteratorPack<IteratorType, RefType>::~PostingIteratorPack() = default;

template <typename IteratorType, typename RefType>
PostingIteratorPack<IteratorType, RefType>::PostingIteratorPack(std::vector<IteratorType> &&children) noexcept
    : _children(std::move(children))
{
    assert(_children.size() <= std::numeric_limits<ref_t>::max());
}

template <typename IteratorType, typename RefType>
std::unique_ptr<BitVector>
PostingIteratorPack<IteratorType, RefType>::get_hits(uint32_t begin_id, uint32_t end_id) {
    BitVector::UP result(BitVector::create(begin_id, end_id));
    or_hits_into(*result, begin_id);
    return result;
}

template <typename IteratorType, typename RefType>
void
PostingIteratorPack<IteratorType, RefType>::or_hits_into(BitVector &result, uint32_t begin_id) {
    for (size_t i = 0; i < size(); ++i) {
        uint32_t docId = get_docid(i);
        if (begin_id > docId) {
            docId = seek(i, begin_id);
        }
        for (uint32_t limit = result.size(); docId < limit; docId = next(i)) {
            result.setBit(docId);
        }
    }
    result.invalidateCachedCount();
}

template <>
int32_t
PostingIteratorPack<DocidIterator, uint16_t>::get_weight(ref_t, uint32_t) noexcept
{
    return 1;
}

template <>
int32_t
PostingIteratorPack<DocidIterator, uint32_t>::get_weight(ref_t, uint32_t) noexcept
{
    return 1;
}

template class PostingIteratorPack<DocidIterator, uint16_t>;
template class PostingIteratorPack<DocidIterator, uint32_t>;
template class PostingIteratorPack<DocidWithWeightIterator, uint16_t>;
template class PostingIteratorPack<DocidWithWeightIterator, uint32_t>;

}