add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / index / DefaultSkipListReader.java
1 package org.apache.lucene.index;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.io.IOException;
21 import java.util.Arrays;
22
23 import org.apache.lucene.store.IndexInput;
24
25 /**
26  * Implements the skip list reader for the default posting list format
27  * that stores positions and payloads.
28  *
29  */
30 class DefaultSkipListReader extends MultiLevelSkipListReader {
31   private boolean currentFieldStoresPayloads;
32   private long freqPointer[];
33   private long proxPointer[];
34   private int payloadLength[];
35   
36   private long lastFreqPointer;
37   private long lastProxPointer;
38   private int lastPayloadLength;
39                            
40
41   DefaultSkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval) {
42     super(skipStream, maxSkipLevels, skipInterval);
43     freqPointer = new long[maxSkipLevels];
44     proxPointer = new long[maxSkipLevels];
45     payloadLength = new int[maxSkipLevels];
46   }
47   
48   void init(long skipPointer, long freqBasePointer, long proxBasePointer, int df, boolean storesPayloads) {
49     super.init(skipPointer, df);
50     this.currentFieldStoresPayloads = storesPayloads;
51     lastFreqPointer = freqBasePointer;
52     lastProxPointer = proxBasePointer;
53
54     Arrays.fill(freqPointer, freqBasePointer);
55     Arrays.fill(proxPointer, proxBasePointer);
56     Arrays.fill(payloadLength, 0);
57   }
58
59   /** Returns the freq pointer of the doc to which the last call of 
60    * {@link MultiLevelSkipListReader#skipTo(int)} has skipped.  */
61   long getFreqPointer() {
62     return lastFreqPointer;
63   }
64
65   /** Returns the prox pointer of the doc to which the last call of 
66    * {@link MultiLevelSkipListReader#skipTo(int)} has skipped.  */
67   long getProxPointer() {
68     return lastProxPointer;
69   }
70   
71   /** Returns the payload length of the payload stored just before 
72    * the doc to which the last call of {@link MultiLevelSkipListReader#skipTo(int)} 
73    * has skipped.  */
74   int getPayloadLength() {
75     return lastPayloadLength;
76   }
77   
78   @Override
79   protected void seekChild(int level) throws IOException {
80     super.seekChild(level);
81     freqPointer[level] = lastFreqPointer;
82     proxPointer[level] = lastProxPointer;
83     payloadLength[level] = lastPayloadLength;
84   }
85   
86   @Override
87   protected void setLastSkipData(int level) {
88     super.setLastSkipData(level);
89     lastFreqPointer = freqPointer[level];
90     lastProxPointer = proxPointer[level];
91     lastPayloadLength = payloadLength[level];
92   }
93
94
95   @Override
96   protected int readSkipData(int level, IndexInput skipStream) throws IOException {
97     int delta;
98     if (currentFieldStoresPayloads) {
99       // the current field stores payloads.
100       // if the doc delta is odd then we have
101       // to read the current payload length
102       // because it differs from the length of the
103       // previous payload
104       delta = skipStream.readVInt();
105       if ((delta & 1) != 0) {
106         payloadLength[level] = skipStream.readVInt();
107       }
108       delta >>>= 1;
109     } else {
110       delta = skipStream.readVInt();
111     }
112     freqPointer[level] += skipStream.readVInt();
113     proxPointer[level] += skipStream.readVInt();
114     
115     return delta;
116   }
117 }