1 package org.apache.lucene.util;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.IOException;
21 import org.apache.lucene.search.DocIdSetIterator;
23 public class OpenBitSetDISI extends OpenBitSet {
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.
30 public OpenBitSetDISI(DocIdSetIterator disi, int maxSize) throws IOException {
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.
39 public OpenBitSetDISI(int maxSize) {
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
49 public void inPlaceOr(DocIdSetIterator disi) throws IOException {
52 while ((doc = disi.nextDoc()) < size) {
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
63 public void inPlaceAnd(DocIdSetIterator disi) throws IOException {
64 int bitSetDoc = nextSetBit(0);
66 while (bitSetDoc != -1 && (disiDoc = disi.advance(bitSetDoc)) != DocIdSetIterator.NO_MORE_DOCS) {
67 clear(bitSetDoc, disiDoc);
68 bitSetDoc = nextSetBit(disiDoc + 1);
70 if (bitSetDoc != -1) {
71 clear(bitSetDoc, size());
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
81 public void inPlaceNot(DocIdSetIterator disi) throws IOException {
84 while ((doc = disi.nextDoc()) < size) {
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
95 public void inPlaceXor(DocIdSetIterator disi) throws IOException {
98 while ((doc = disi.nextDoc()) < size) {