Skip to content

Commit

Permalink
Make it readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Jan 11, 2023
1 parent 42ae1b4 commit 0f12598
Showing 1 changed file with 13 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.RamUsageEstimator;

import java.io.IOException;
Expand All @@ -21,7 +20,6 @@
public final class MatchAllBitSet extends BitSet {
private static final long RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(MatchAllBitSet.class);

private FixedBitSet bits;
private final int numBits;

public MatchAllBitSet(int numBits) {
Expand All @@ -30,89 +28,54 @@ public MatchAllBitSet(int numBits) {

@Override
public void set(int i) {
if (bits != null) {
bits.set(i);
}

}

@Override
public boolean getAndSet(int i) {
if (bits != null) {
return bits.getAndSet(i);
} else {
return true;
}
}

private void initializeBitSet() {
bits = new FixedBitSet(numBits);
bits.set(0, bits.length());
return true;
}

@Override
public void clear(int i) {
if (bits == null) {
initializeBitSet();
}
bits.clear(i);
assert false : "MatchAllBitSet doesn't support clear";
throw new UnsupportedOperationException("MatchAllBitSet doesn't support clear");
}

@Override
public void clear(int startIndex, int endIndex) {
if (bits == null) {
initializeBitSet();
}
bits.clear(startIndex, endIndex);
assert false : "MatchAllBitSet doesn't support clear";
throw new UnsupportedOperationException("MatchAllBitSet doesn't support clear");
}

@Override
public int cardinality() {
if (bits != null) {
return bits.cardinality();
} else {
return numBits;
}
return numBits;
}

@Override
public int approximateCardinality() {
if (bits != null) {
return bits.approximateCardinality();
} else {
return numBits;
}
return numBits;
}

@Override
public int prevSetBit(int index) {
if (bits != null) {
return bits.prevSetBit(index);
} else {
return index;
}
return index;
}

@Override
public int nextSetBit(int index) {
if (bits != null) {
return bits.nextSetBit(index);
} else {
return index;
}
return index;
}

@Override
public long ramBytesUsed() {
return RAM_BYTES_USED + (bits != null ? bits.ramBytesUsed() : 0);
return RAM_BYTES_USED;
}

@Override
public boolean get(int index) {
if (bits != null) {
return bits.get(index);
} else {
return true;
}
return true;
}

@Override
Expand All @@ -122,8 +85,6 @@ public int length() {

@Override
public void or(DocIdSetIterator iter) throws IOException {
if (bits != null) {
bits.or(iter);
}

}
}

0 comments on commit 0f12598

Please sign in to comment.