java.lang.Object
org.apache.lucene.util.BitSet
org.apache.lucene.util.SparseFixedBitSet
- All Implemented Interfaces:
Accountable,Bits
A bit set that only stores longs that have at least one bit which is set. The way it works is
that the space of bits is divided into blocks of 4096 bits, which is 64 longs. Then for each
block, we have:
- a long[] which stores the non-zero longs for that block
- a long so that bit
ibeing set means that thei-thlong of the block is non-null, and its offset in the array of longs is the number of one bits on the right of thei-thbit.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.lucene.util.Bits
Bits.MatchAllBits, Bits.MatchNoBits -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long(package private) final long[][](package private) final long[](package private) final intprivate static final int(package private) int(package private) longprivate static final longFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLEFields inherited from interface org.apache.lucene.util.Bits
EMPTY_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidand(int i4096, int i64, long mask) intReturn an approximation of the cardinality of this set.private static intblockCount(int length) intReturn the number of bits that are set.voidclear()Clear all the bits of the set.voidclear(int i) Clear the bit at indexi.voidclear(int from, int to) Clears a range of bits.private voidclearWithinBlock(int i4096, int from, int to) private booleanconsistent(int index) private intfirstDoc(int i4096) Return the first document that occurs on or after the provided block index.booleanget(int i) Returns the value of the bit with the specifiedindex.booleangetAndSet(int i) Set the bit ati, returningtrueif it was previously set.private voidinsertBlock(int i4096, long i64bit, int i) private voidinsertLong(int i4096, long i64bit, int i, long index) private intlastDoc(int i4096) Return the last document that occurs on or before the provided block index.intlength()Returns the number of bits in this setprivate longlongBits(long index, long[] bits, int i64) Return the long bits at the giveni64index.private static longmask(int from, int to) intnextSetBit(int i) Returns the index of the first set bit starting at the index specified.private voidor(int i4096, long index, long[] bits, int nonZeroLongCount) voidor(DocIdSetIterator it) Does in-place OR of the bits provided by the iterator.private voidor(SparseFixedBitSet other) private voidor(DocIdSetIterator)impl that works best whenitis denseprivate static intoversize(int s) intprevSetBit(int i) Returns the index of the last set bit before or on the index specified.longReturn the memory usage of this object in bytes.private voidremoveLong(int i4096, int i64, long index, int o) voidset(int i) Set the bit at indexi.toString()Methods inherited from class org.apache.lucene.util.BitSet
checkUnpositioned, ofMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Field Details
-
BASE_RAM_BYTES_USED
private static final long BASE_RAM_BYTES_USED -
SINGLE_ELEMENT_ARRAY_BYTES_USED
private static final long SINGLE_ELEMENT_ARRAY_BYTES_USED -
MASK_4096
private static final int MASK_4096- See Also:
-
indices
final long[] indices -
bits
final long[][] bits -
length
final int length -
nonZeroLongCount
int nonZeroLongCount -
ramBytesUsed
long ramBytesUsed
-
-
Constructor Details
-
SparseFixedBitSet
public SparseFixedBitSet(int length)
-
-
Method Details
-
blockCount
private static int blockCount(int length) -
clear
public void clear()Description copied from class:BitSetClear all the bits of the set.Depending on the implementation, this may be significantly faster than clear(0, length).
-
length
public int length()Description copied from interface:BitsReturns the number of bits in this set -
consistent
private boolean consistent(int index) -
cardinality
public int cardinality()Description copied from class:BitSetReturn the number of bits that are set. NOTE: this method is likely to run in linear time- Specified by:
cardinalityin classBitSet
-
approximateCardinality
public int approximateCardinality()Description copied from class:BitSetReturn an approximation of the cardinality of this set. Some implementations may trade accuracy for speed if they have the ability to estimate the cardinality of the set without iterating over all the data. The default implementation returnsBitSet.cardinality().- Specified by:
approximateCardinalityin classBitSet
-
get
public boolean get(int i) Description copied from interface:BitsReturns the value of the bit with the specifiedindex.- Parameters:
i- index, should be non-negative and <Bits.length(). The result of passing negative or out of bounds values is undefined by this interface, just don't do it!- Returns:
trueif the bit is set,falseotherwise.
-
getAndSet
public boolean getAndSet(int i) Description copied from class:BitSetSet the bit ati, returningtrueif it was previously set. -
oversize
private static int oversize(int s) -
set
public void set(int i) Set the bit at indexi. -
insertBlock
private void insertBlock(int i4096, long i64bit, int i) -
insertLong
private void insertLong(int i4096, long i64bit, int i, long index) -
clear
public void clear(int i) Clear the bit at indexi. -
and
private void and(int i4096, int i64, long mask) -
removeLong
private void removeLong(int i4096, int i64, long index, int o) -
clear
public void clear(int from, int to) Description copied from class:BitSetClears a range of bits. -
mask
private static long mask(int from, int to) -
clearWithinBlock
private void clearWithinBlock(int i4096, int from, int to) -
firstDoc
private int firstDoc(int i4096) Return the first document that occurs on or after the provided block index. -
nextSetBit
public int nextSetBit(int i) Description copied from class:BitSetReturns the index of the first set bit starting at the index specified.DocIdSetIterator.NO_MORE_DOCSis returned if there are no more set bits.- Specified by:
nextSetBitin classBitSet
-
lastDoc
private int lastDoc(int i4096) Return the last document that occurs on or before the provided block index. -
prevSetBit
public int prevSetBit(int i) Description copied from class:BitSetReturns the index of the last set bit before or on the index specified. -1 is returned if there are no more set bits.- Specified by:
prevSetBitin classBitSet
-
longBits
private long longBits(long index, long[] bits, int i64) Return the long bits at the giveni64index. -
or
private void or(int i4096, long index, long[] bits, int nonZeroLongCount) -
or
-
orDense
or(DocIdSetIterator)impl that works best whenitis dense- Throws:
IOException
-
or
Description copied from class:BitSetDoes in-place OR of the bits provided by the iterator. The state of the iterator after this operation terminates is undefined.- Overrides:
orin classBitSet- Throws:
IOException
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal. -
toString
-