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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "zc4_posting_reader.h"
#include "zc4_posting_header.h"
#include <vespa/searchlib/index/docidandfeatures.h>
namespace search::diskindex {
using index::PostingListCounts;
using index::DocIdAndFeatures;
using bitcompression::FeatureEncodeContext;
template <bool bigEndian>
Zc4PostingReader<bigEndian>::Zc4PostingReader(bool dynamic_k)
: Zc4PostingReaderBase(dynamic_k),
_decodeContext(nullptr)
{
}
template <bool bigEndian>
Zc4PostingReader<bigEndian>::~Zc4PostingReader()
{
}
template <bool bigEndian>
void
Zc4PostingReader<bigEndian>::read_doc_id_and_features(DocIdAndFeatures &features)
{
if (_residue == 0) {
if (_has_more) {
read_word_start();
assert(_residue != 0);
} else {
// Don't read past end of posting list.
features.clear(static_cast<uint32_t>(-1));
return;
}
}
if (_last_doc_id > 0) {
// Split docid & features.
read_common_word_doc_id(*_decodeContext);
} else {
// Interleaves docid & features
using EC = FeatureEncodeContext<bigEndian>;
DecodeContext &d = *_decodeContext;
uint32_t length;
uint64_t val64;
UC64_DECODECONTEXT_CONSTRUCTOR(o, d._);
UC64_DECODEEXPGOLOMB_SMALL_NS(o, _doc_id_k, EC);
_no_skip.set_doc_id(_no_skip.get_doc_id() + 1 + val64);
if (_posting_params._encode_interleaved_features) {
if (__builtin_expect(oCompr >= d._valE, false)) {
UC64_DECODECONTEXT_STORE(o, d._);
_readContext.readComprBuffer();
UC64_DECODECONTEXT_LOAD(o, d._);
}
UC64_DECODEEXPGOLOMB_SMALL_NS(o, K_VALUE_ZCPOSTING_FIELD_LENGTH, EC);
_no_skip.set_field_length(val64 + 1);
if (__builtin_expect(oCompr >= d._valE, false)) {
UC64_DECODECONTEXT_STORE(o, d._);
_readContext.readComprBuffer();
UC64_DECODECONTEXT_LOAD(o, d._);
}
UC64_DECODEEXPGOLOMB_SMALL_NS(o, K_VALUE_ZCPOSTING_NUM_OCCS, EC);
_no_skip.set_num_occs(val64 + 1);
}
UC64_DECODECONTEXT_STORE(o, d._);
if (__builtin_expect(oCompr >= d._valE, false)) {
_readContext.readComprBuffer();
}
}
features.set_doc_id(_no_skip.get_doc_id());
if (_posting_params._encode_features) {
if (_posting_params._encode_interleaved_features) {
features.set_field_length(_no_skip.get_field_length());
features.set_num_occs(_no_skip.get_num_occs());
}
_decodeContext->readFeatures(features);
}
--_residue;
}
template <bool bigEndian>
void
Zc4PostingReader<bigEndian>::read_word_start()
{
Zc4PostingReaderBase::read_word_start(*_decodeContext);
}
template <bool bigEndian>
void
Zc4PostingReader<bigEndian>::set_counts(const PostingListCounts &counts)
{
Zc4PostingReaderBase::set_counts(*_decodeContext, counts);
}
template <bool bigEndian>
void
Zc4PostingReader<bigEndian>::set_decode_features(DecodeContext *decode_features)
{
_decodeContext = decode_features;
_decodeContext->setReadContext(&_readContext);
_readContext.setDecodeContext(_decodeContext);
}
template class Zc4PostingReader<false>;
template class Zc4PostingReader<true>;
}
|