add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / util / OpenBitSetDISI.java
1 package org.apache.lucene.util;
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 org.apache.lucene.search.DocIdSetIterator;
22  
23 public class OpenBitSetDISI extends OpenBitSet {
24
25   /** Construct an OpenBitSetDISI with its bits set
26    * from the doc ids of the given DocIdSetIterator.
27    * Also give a maximum size one larger than the largest doc id for which a
28    * bit may ever be set on this OpenBitSetDISI.
29    */
30   public OpenBitSetDISI(DocIdSetIterator disi, int maxSize) throws IOException {
31     super(maxSize);
32     inPlaceOr(disi);
33   }
34
35   /** Construct an OpenBitSetDISI with no bits set, and a given maximum size
36    * one larger than the largest doc id for which a bit may ever be set
37    * on this OpenBitSetDISI.
38    */
39   public OpenBitSetDISI(int maxSize) {
40     super(maxSize);
41   }
42
43   /**
44    * Perform an inplace OR with the doc ids from a given DocIdSetIterator,
45    * setting the bit for each such doc id.
46    * These doc ids should be smaller than the maximum size passed to the
47    * constructor.
48    */   
49   public void inPlaceOr(DocIdSetIterator disi) throws IOException {
50     int doc;
51     long size = size();
52     while ((doc = disi.nextDoc()) < size) {
53       fastSet(doc);
54     }
55   }
56
57   /**
58    * Perform an inplace AND with the doc ids from a given DocIdSetIterator,
59    * leaving only the bits set for which the doc ids are in common.
60    * These doc ids should be smaller than the maximum size passed to the
61    * constructor.
62    */   
63   public void inPlaceAnd(DocIdSetIterator disi) throws IOException {
64     int bitSetDoc = nextSetBit(0);
65     int disiDoc;
66     while (bitSetDoc != -1 && (disiDoc = disi.advance(bitSetDoc)) != DocIdSetIterator.NO_MORE_DOCS) {
67       clear(bitSetDoc, disiDoc);
68       bitSetDoc = nextSetBit(disiDoc + 1);
69     }
70     if (bitSetDoc != -1) {
71       clear(bitSetDoc, size());
72     }
73   }
74
75   /**
76    * Perform an inplace NOT with the doc ids from a given DocIdSetIterator,
77    * clearing all the bits for each such doc id.
78    * These doc ids should be smaller than the maximum size passed to the
79    * constructor.
80    */   
81   public void inPlaceNot(DocIdSetIterator disi) throws IOException {
82     int doc;
83     long size = size();
84     while ((doc = disi.nextDoc()) < size) {
85       fastClear(doc);
86     }
87   }
88
89   /**
90    * Perform an inplace XOR with the doc ids from a given DocIdSetIterator,
91    * flipping all the bits for each such doc id.
92    * These doc ids should be smaller than the maximum size passed to the
93    * constructor.
94    */   
95   public void inPlaceXor(DocIdSetIterator disi) throws IOException {
96     int doc;
97     long size = size();
98     while ((doc = disi.nextDoc()) < size) {
99       fastFlip(doc);
100     }
101   }
102 }