Package org.apache.lucene.util
Class BitVector
- java.lang.Object
-
- org.apache.lucene.util.BitVector
-
public final class BitVector extends Object implements Cloneable, Bits
Optimized implementation of a vector of bits. This is more-or-less like java.util.BitSet, but also includes the following:- a count() method, which efficiently computes the number of one bits;
- optimized read from and write to disk;
- inlinable get() method;
- store and load, as bit set or d-gaps, depending on sparseness;
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.lucene.util.Bits
Bits.MatchAllBits, Bits.MatchNoBits
-
-
Field Summary
-
Fields inherited from interface org.apache.lucene.util.Bits
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Constructor Description BitVector(int n)
Constructs a vector capable of holdingn
bits.BitVector(Directory d, String name)
Constructs a bit vector from the filename
in Directoryd
, as written by thewrite(org.apache.lucene.store.Directory, java.lang.String)
method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear(int bit)
Sets the value ofbit
to zero.Object
clone()
int
count()
Returns the total number of one bits in this vector.boolean
get(int bit)
Returnstrue
ifbit
is one andfalse
if it is zero.boolean
getAndSet(int bit)
Sets the value ofbit
to true, and returns true if bit was already setint
getRecomputedCount()
For testingint
length()
Returns the number of bits in this vector.void
set(int bit)
Sets the value ofbit
to one.int
size()
Returns the number of bits in this vector.void
write(Directory d, String name)
Writes this vector to the filename
in Directoryd
, in a format that can be read by the constructorBitVector(Directory, String)
.
-
-
-
Constructor Detail
-
BitVector
public BitVector(int n)
Constructs a vector capable of holdingn
bits.
-
BitVector
public BitVector(Directory d, String name) throws IOException
Constructs a bit vector from the filename
in Directoryd
, as written by thewrite(org.apache.lucene.store.Directory, java.lang.String)
method.- Throws:
IOException
-
-
Method Detail
-
set
public final void set(int bit)
Sets the value ofbit
to one.
-
getAndSet
public final boolean getAndSet(int bit)
Sets the value ofbit
to true, and returns true if bit was already set
-
clear
public final void clear(int bit)
Sets the value ofbit
to zero.
-
get
public final boolean get(int bit)
Returnstrue
ifbit
is one andfalse
if it is zero.
-
size
public final int size()
Returns the number of bits in this vector. This is also one greater than the number of the largest valid bit number.
-
length
public final int length()
Returns the number of bits in this vector. This is also one greater than the number of the largest valid bit number.
-
count
public final int count()
Returns the total number of one bits in this vector. This is efficiently computed and cached, so that, if the vector is not changed, no recomputation is done for repeated calls.
-
getRecomputedCount
public final int getRecomputedCount()
For testing
-
write
public final void write(Directory d, String name) throws IOException
Writes this vector to the filename
in Directoryd
, in a format that can be read by the constructorBitVector(Directory, String)
.- Throws:
IOException
-
-