-
Notifications
You must be signed in to change notification settings - Fork 623
/
Lucene40SkipListReader.cs
155 lines (139 loc) · 6.1 KB
/
Lucene40SkipListReader.cs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using J2N.Numerics;
using Lucene.Net.Support;
using System;
using System.Runtime.CompilerServices;
namespace Lucene.Net.Codecs.Lucene40
{
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using IndexInput = Lucene.Net.Store.IndexInput;
/// <summary>
/// Implements the skip list reader for the 4.0 posting list format
/// that stores positions and payloads.
/// </summary>
/// <seealso cref="Lucene40PostingsFormat"/>
[Obsolete("Only for reading old 4.0 segments")]
public class Lucene40SkipListReader : MultiLevelSkipListReader
{
private bool currentFieldStoresPayloads;
private bool currentFieldStoresOffsets;
private readonly long[] freqPointer; // LUCENENET: marked readonly
private readonly long[] proxPointer; // LUCENENET: marked readonly
private readonly int[] payloadLength; // LUCENENET: marked readonly
private readonly int[] offsetLength; // LUCENENET: marked readonly
private long lastFreqPointer;
private long lastProxPointer;
private int lastPayloadLength;
private int lastOffsetLength;
/// <summary>
/// Sole constructor. </summary>
public Lucene40SkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval)
: base(skipStream, maxSkipLevels, skipInterval)
{
freqPointer = new long[maxSkipLevels];
proxPointer = new long[maxSkipLevels];
payloadLength = new int[maxSkipLevels];
offsetLength = new int[maxSkipLevels];
}
/// <summary>
/// Per-term initialization. </summary>
public virtual void Init(long skipPointer, long freqBasePointer, long proxBasePointer, int df, bool storesPayloads, bool storesOffsets)
{
base.Init(skipPointer, df);
this.currentFieldStoresPayloads = storesPayloads;
this.currentFieldStoresOffsets = storesOffsets;
lastFreqPointer = freqBasePointer;
lastProxPointer = proxBasePointer;
Arrays.Fill(freqPointer, freqBasePointer);
Arrays.Fill(proxPointer, proxBasePointer);
Arrays.Fill(payloadLength, 0);
Arrays.Fill(offsetLength, 0);
}
/// <summary>
/// Returns the freq pointer of the doc to which the last call of
/// <see cref="MultiLevelSkipListReader.SkipTo(int)"/> has skipped.
/// </summary>
public virtual long FreqPointer => lastFreqPointer;
/// <summary>
/// Returns the prox pointer of the doc to which the last call of
/// <see cref="MultiLevelSkipListReader.SkipTo(int)"/> has skipped.
/// </summary>
public virtual long ProxPointer => lastProxPointer;
/// <summary>
/// Returns the payload length of the payload stored just before
/// the doc to which the last call of <see cref="MultiLevelSkipListReader.SkipTo(int)"/>
/// has skipped.
/// </summary>
public virtual int PayloadLength => lastPayloadLength;
/// <summary>
/// Returns the offset length (endOffset-startOffset) of the position stored just before
/// the doc to which the last call of <see cref="MultiLevelSkipListReader.SkipTo(int)"/>
/// has skipped.
/// </summary>
public virtual int OffsetLength => lastOffsetLength;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void SeekChild(int level)
{
base.SeekChild(level);
freqPointer[level] = lastFreqPointer;
proxPointer[level] = lastProxPointer;
payloadLength[level] = lastPayloadLength;
offsetLength[level] = lastOffsetLength;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void SetLastSkipData(int level)
{
base.SetLastSkipData(level);
lastFreqPointer = freqPointer[level];
lastProxPointer = proxPointer[level];
lastPayloadLength = payloadLength[level];
lastOffsetLength = offsetLength[level];
}
protected override int ReadSkipData(int level, IndexInput skipStream)
{
int delta;
if (currentFieldStoresPayloads || currentFieldStoresOffsets)
{
// the current field stores payloads and/or offsets.
// if the doc delta is odd then we have
// to read the current payload/offset lengths
// because it differs from the lengths of the
// previous payload/offset
delta = skipStream.ReadVInt32();
if ((delta & 1) != 0)
{
if (currentFieldStoresPayloads)
{
payloadLength[level] = skipStream.ReadVInt32();
}
if (currentFieldStoresOffsets)
{
offsetLength[level] = skipStream.ReadVInt32();
}
}
delta = delta.TripleShift(1);
}
else
{
delta = skipStream.ReadVInt32();
}
freqPointer[level] += skipStream.ReadVInt32();
proxPointer[level] += skipStream.ReadVInt32();
return delta;
}
}
}