Package org.apache.lucene.util
Class LongBitSet
- java.lang.Object
-
- org.apache.lucene.util.LongBitSet
-
public final class LongBitSet extends Object
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 useFixedBitSet
.
-
-
Constructor Summary
Constructors Constructor Description LongBitSet(long numBits)
LongBitSet(long[] storedBits, long numBits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
and(LongBitSet other)
this = this AND othervoid
andNot(LongBitSet other)
this = this AND NOT otherstatic int
bits2words(long numBits)
returns the number of 64 bit words it would take to hold numBitslong
cardinality()
Returns number of set bits.void
clear(long index)
void
clear(long startIndex, long endIndex)
Clears a range of bits.LongBitSet
clone()
static LongBitSet
ensureCapacity(LongBitSet bits, long numBits)
If the givenLongBitSet
is large enough to holdnumBits
, returns the given bits, otherwise returns a newLongBitSet
which can hold the requested number of bits.boolean
equals(Object o)
returns true if both sets have the same bits setvoid
flip(long startIndex, long endIndex)
Flips a range of bitsboolean
get(long index)
boolean
getAndClear(long index)
boolean
getAndSet(long index)
long[]
getBits()
Expert.int
hashCode()
boolean
intersects(LongBitSet other)
returns true if the sets have any elements in commonlong
length()
Returns the number of bits stored in this bitset.long
nextSetBit(long index)
Returns the index of the first set bit starting at the index specified.void
or(LongBitSet other)
this = this OR otherlong
prevSetBit(long index)
Returns the index of the last set bit before or on the index specified.void
set(long index)
void
set(long startIndex, long endIndex)
Sets a range of bitsvoid
xor(LongBitSet other)
this = this XOR other
-
-
-
Method Detail
-
ensureCapacity
public static LongBitSet ensureCapacity(LongBitSet bits, long numBits)
If the givenLongBitSet
is large enough to holdnumBits
, returns the given bits, otherwise returns a newLongBitSet
which can hold the requested number of bits.NOTE: the returned bitset reuses the underlying
long[]
of the givenbits
if 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
public void or(LongBitSet other)
this = this OR other
-
xor
public void xor(LongBitSet other)
this = this XOR other
-
intersects
public boolean intersects(LongBitSet other)
returns true if the sets have any elements in common
-
and
public void and(LongBitSet other)
this = this AND other
-
andNot
public void andNot(LongBitSet other)
this = this AND NOT other
-
flip
public void flip(long startIndex, long endIndex)
Flips a range of bits- Parameters:
startIndex
- lower indexendIndex
- one-past the last bit to flip
-
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
public LongBitSet clone()
-
equals
public boolean equals(Object o)
returns true if both sets have the same bits set
-
-