Package org.apache.lucene.util
Class LongBitSet
java.lang.Object
org.apache.lucene.util.LongBitSet
- All Implemented Interfaces:
Accountable
BitSet of fixed length (numBits), backed by accessible (
getBits()) long[], accessed with a
long index. Use it only if you intend to store more than 2.1B bits, otherwise you should use
FixedBitSet.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Field Summary
FieldsFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
ConstructorsConstructorDescriptionLongBitSet(long numBits) Creates a new LongBitSet.LongBitSet(long[] storedBits, long numBits) Creates a new LongBitSet using the provided long[] array as backing store. -
Method Summary
Modifier and TypeMethodDescriptionvoidand(LongBitSet other) this = this AND othervoidandNot(LongBitSet other) this = this AND NOT otherstatic intbits2words(long numBits) Returns the number of 64 bit words it would take to hold numBitslongReturns number of set bits.voidclear(long index) voidclear(long startIndex, long endIndex) Clears a range of bits.clone()static LongBitSetensureCapacity(LongBitSet bits, long numBits) If the givenLongBitSetis large enough to holdnumBits+1, returns the given bits, otherwise returns a newLongBitSetwhich can hold the requested number of bits.booleanreturns true if both sets have the same bits setvoidflip(long index) Flip the bit at the provided index.voidflip(long startIndex, long endIndex) Flips a range of bitsbooleanget(long index) booleangetAndClear(long index) booleangetAndSet(long index) long[]getBits()Expert.inthashCode()booleanintersects(LongBitSet other) returns true if the sets have any elements in commonlonglength()Returns the number of bits stored in this bitset.longnextSetBit(long index) Returns the index of the first set bit starting at the index specified.voidor(LongBitSet other) this = this OR otherlongprevSetBit(long index) Returns the index of the last set bit before or on the index specified.longReturn the memory usage of this object in bytes.booleanScans the backing store to check if all bits are clear.voidset(long index) voidset(long startIndex, long endIndex) Sets a range of bitsvoidxor(LongBitSet other) this = this XOR otherMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Field Details
-
MAX_NUM_BITS
public static final long MAX_NUM_BITSThe maximumnumBitssupported.
-
-
Constructor Details
-
LongBitSet
public LongBitSet(long numBits) Creates a new LongBitSet. The internally allocated long array will be exactly the size needed to accommodate the numBits specified.- Parameters:
numBits- the number of bits needed
-
LongBitSet
public LongBitSet(long[] storedBits, long numBits) Creates a new LongBitSet using the provided long[] array as backing store. The storedBits array must be large enough to accommodate the numBits specified, but may be larger. In that case the 'extra' or 'ghost' bits must be clear (or they may provoke spurious side-effects)- Parameters:
storedBits- the array to use as backing storenumBits- the number of bits actually needed
-
-
Method Details
-
ensureCapacity
If the givenLongBitSetis large enough to holdnumBits+1, returns the given bits, otherwise returns a newLongBitSetwhich can hold the requested number of bits.NOTE: the returned bitset reuses the underlying
long[]of the givenbitsif possible. Also, callinglength()on the returned bits may return a value greater thannumBits. -
bits2words
public static int bits2words(long numBits) Returns the number of 64 bit words it would take to hold numBits -
length
public long length()Returns the number of bits stored in this bitset. -
getBits
public long[] getBits()Expert. -
cardinality
public long cardinality()Returns number of set bits. NOTE: this visits every long in the backing bits array, and the result is not internally cached! -
get
public boolean get(long index) -
set
public void set(long index) -
getAndSet
public boolean getAndSet(long index) -
clear
public void clear(long index) -
getAndClear
public boolean getAndClear(long index) -
nextSetBit
public long nextSetBit(long index) Returns the index of the first set bit starting at the index specified. -1 is returned if there are no more set bits. -
prevSetBit
public long prevSetBit(long index) Returns the index of the last set bit before or on the index specified. -1 is returned if there are no more set bits. -
or
this = this OR other -
xor
this = this XOR other -
intersects
returns true if the sets have any elements in common -
and
this = this AND other -
andNot
this = this AND NOT other -
scanIsEmpty
public boolean scanIsEmpty()Scans the backing store to check if all bits are clear. The method is deliberately not called "isEmpty" to emphasize it is not low cost (as isEmpty usually is).- Returns:
- true if all bits are clear.
-
flip
public void flip(long startIndex, long endIndex) Flips a range of bits- Parameters:
startIndex- lower indexendIndex- one-past the last bit to flip
-
flip
public void flip(long index) Flip the bit at the provided index. -
set
public void set(long startIndex, long endIndex) Sets a range of bits- Parameters:
startIndex- lower indexendIndex- one-past the last bit to set
-
clear
public void clear(long startIndex, long endIndex) Clears a range of bits.- Parameters:
startIndex- lower indexendIndex- one-past the last bit to clear
-
clone
-
equals
returns true if both sets have the same bits set -
hashCode
public int hashCode() -
ramBytesUsed
public long ramBytesUsed()Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-