Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
DefaultSkipListReader.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using Lucene.Net.Support;
19 using IndexInput = Lucene.Net.Store.IndexInput;
20 
21 namespace Lucene.Net.Index
22 {
23 
24  /// <summary> Implements the skip list reader for the default posting list format
25  /// that stores positions and payloads.
26  ///
27  /// </summary>
29  {
30  private bool currentFieldStoresPayloads;
31  private readonly long[] freqPointer;
32  private readonly long[] proxPointer;
33  private readonly int[] payloadLength;
34 
35  private long lastFreqPointer;
36  private long lastProxPointer;
37  private int lastPayloadLength;
38 
39 
40  internal DefaultSkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval):base(skipStream, maxSkipLevels, skipInterval)
41  {
42  freqPointer = new long[maxSkipLevels];
43  proxPointer = new long[maxSkipLevels];
44  payloadLength = new int[maxSkipLevels];
45  }
46 
47  internal virtual void Init(long skipPointer, long freqBasePointer, long proxBasePointer, int df, bool storesPayloads)
48  {
49  base.Init(skipPointer, df);
50  this.currentFieldStoresPayloads = storesPayloads;
51  lastFreqPointer = freqBasePointer;
52  lastProxPointer = proxBasePointer;
53 
54  for (int i = 0; i < freqPointer.Length; i++) freqPointer[i] = freqBasePointer;
55  for (int i = 0; i < proxPointer.Length; i++) proxPointer[i] = proxBasePointer;
56  for (int i = 0; i < payloadLength.Length; i++) payloadLength[i] = 0;
57  }
58 
59  /// <summary>Returns the freq pointer of the doc to which the last call of
60  /// <see cref="MultiLevelSkipListReader.SkipTo(int)" /> has skipped.
61  /// </summary>
62  internal virtual long GetFreqPointer()
63  {
64  return lastFreqPointer;
65  }
66 
67  /// <summary>Returns the prox pointer of the doc to which the last call of
68  /// <see cref="MultiLevelSkipListReader.SkipTo(int)" /> has skipped.
69  /// </summary>
70  internal virtual long GetProxPointer()
71  {
72  return lastProxPointer;
73  }
74 
75  /// <summary>Returns the payload length of the payload stored just before
76  /// the doc to which the last call of <see cref="MultiLevelSkipListReader.SkipTo(int)" />
77  /// has skipped.
78  /// </summary>
79  internal virtual int GetPayloadLength()
80  {
81  return lastPayloadLength;
82  }
83 
84  protected internal override void SeekChild(int level)
85  {
86  base.SeekChild(level);
87  freqPointer[level] = lastFreqPointer;
88  proxPointer[level] = lastProxPointer;
89  payloadLength[level] = lastPayloadLength;
90  }
91 
92  protected internal override void SetLastSkipData(int level)
93  {
94  base.SetLastSkipData(level);
95  lastFreqPointer = freqPointer[level];
96  lastProxPointer = proxPointer[level];
97  lastPayloadLength = payloadLength[level];
98  }
99 
100 
101  protected internal override int ReadSkipData(int level, IndexInput skipStream)
102  {
103  int delta;
104  if (currentFieldStoresPayloads)
105  {
106  // the current field stores payloads.
107  // if the doc delta is odd then we have
108  // to read the current payload length
109  // because it differs from the length of the
110  // previous payload
111  delta = skipStream.ReadVInt();
112  if ((delta & 1) != 0)
113  {
114  payloadLength[level] = skipStream.ReadVInt();
115  }
116  delta = Number.URShift(delta, 1);
117  }
118  else
119  {
120  delta = skipStream.ReadVInt();
121  }
122  freqPointer[level] += skipStream.ReadVInt();
123  proxPointer[level] += skipStream.ReadVInt();
124 
125  return delta;
126  }
127  }
128 }