Package org.apache.lucene.util
Class FixedBitSet
java.lang.Object
org.apache.lucene.search.DocIdSet
org.apache.lucene.util.FixedBitSet
- All Implemented Interfaces:
Bits
BitSet of fixed length (numBits), backed by accessible (
getBits()
)
long[], accessed with an int index, implementing Bits
and
DocIdSet
. If you need to manage more than 2.1B bits, use
LongBitSet
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
ADocIdSetIterator
which iterates over set bits in aFixedBitSet
.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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
and
(DocIdSetIterator iter) Does in-place AND of the bits provided by the iterator.void
and
(FixedBitSet other) this = this AND othervoid
andNot
(DocIdSetIterator iter) Does in-place AND NOT of the bits provided by the iterator.void
andNot
(FixedBitSet other) this = this AND NOT otherstatic long
Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))".bits()
Optionally provides aBits
interface for random access to matching documents.static int
bits2words
(int numBits) returns the number of 64 bit words it would take to hold numBitsint
Returns number of set bits.void
clear
(int index) void
clear
(int startIndex, int endIndex) Clears a range of bits.clone()
static FixedBitSet
ensureCapacity
(FixedBitSet bits, int numBits) If the givenFixedBitSet
is large enough to holdnumBits
, returns the given bits, otherwise returns a newFixedBitSet
which can hold the requested number of bits.boolean
returns true if both sets have the same bits setvoid
flip
(int startIndex, int endIndex) Flips a range of bitsboolean
get
(int index) Returns the value of the bit with the specifiedindex
.boolean
getAndClear
(int index) boolean
getAndSet
(int index) long[]
getBits()
Expert.int
hashCode()
static long
Returns the popcount or cardinality of the intersection of the two sets.boolean
intersects
(FixedBitSet other) returns true if the sets have any elements in commonboolean
This DocIdSet implementation is cacheable.iterator()
Provides aDocIdSetIterator
to access the set.int
length()
Returns the number of bits in this setint
nextSetBit
(int index) Returns the index of the first set bit starting at the index specified.void
or
(DocIdSetIterator iter) Does in-place OR of the bits provided by the iterator.void
or
(FixedBitSet other) this = this OR otherint
prevSetBit
(int index) Returns the index of the last set bit before or on the index specified.void
set
(int index) void
set
(int startIndex, int endIndex) Sets a range of bitsstatic long
unionCount
(FixedBitSet a, FixedBitSet b) Returns the popcount or cardinality of the union of the two sets.void
xor
(DocIdSetIterator iter) Does in-place XOR of the bits provided by the iterator.void
xor
(FixedBitSet other) this = this XOR other
-
Constructor Details
-
FixedBitSet
public FixedBitSet(int numBits) -
FixedBitSet
public FixedBitSet(long[] storedBits, int numBits)
-
-
Method Details
-
ensureCapacity
If the givenFixedBitSet
is large enough to holdnumBits
, returns the given bits, otherwise returns a newFixedBitSet
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(int numBits) returns the number of 64 bit words it would take to hold numBits -
intersectionCount
Returns the popcount or cardinality of the intersection of the two sets. Neither set is modified. -
unionCount
Returns the popcount or cardinality of the union of the two sets. Neither set is modified. -
andNotCount
Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))". Neither set is modified. -
iterator
Description copied from class:DocIdSet
Provides aDocIdSetIterator
to access the set. This implementation can returnnull
if there are no docs that match. -
bits
Description copied from class:DocIdSet
Optionally provides aBits
interface for random access to matching documents.- Overrides:
bits
in classDocIdSet
- Returns:
null
, if thisDocIdSet
does not support random access. In contrast toDocIdSet.iterator()
, a return value ofnull
does not imply that no documents match the filter! The default implementation does not provide random access, so you only need to implement this method if your DocIdSet can guarantee random access to every docid in O(1) time without external disk access (asBits
interface cannot throwIOException
). This is generally true for bit sets likeFixedBitSet
, which return itself if they are used asDocIdSet
.
-
length
public int length()Description copied from interface:Bits
Returns the number of bits in this set -
isCacheable
public boolean isCacheable()This DocIdSet implementation is cacheable.- Overrides:
isCacheable
in classDocIdSet
-
getBits
public long[] getBits()Expert. -
cardinality
public int 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(int index) Description copied from interface:Bits
Returns the value of the bit with the specifiedindex
.- Specified by:
get
in interfaceBits
- Parameters:
index
- 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:
true
if the bit is set,false
otherwise.
-
set
public void set(int index) -
getAndSet
public boolean getAndSet(int index) -
clear
public void clear(int index) -
getAndClear
public boolean getAndClear(int index) -
nextSetBit
public int nextSetBit(int 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 int prevSetBit(int 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
Does in-place OR of the bits provided by the iterator.- Throws:
IOException
-
or
this = this OR other -
xor
this = this XOR other -
xor
Does in-place XOR of the bits provided by the iterator.- Throws:
IOException
-
and
Does in-place AND of the bits provided by the iterator.- Throws:
IOException
-
intersects
returns true if the sets have any elements in common -
and
this = this AND other -
andNot
Does in-place AND NOT of the bits provided by the iterator.- Throws:
IOException
-
andNot
this = this AND NOT other -
flip
public void flip(int startIndex, int endIndex) Flips a range of bits- Parameters:
startIndex
- lower indexendIndex
- one-past the last bit to flip
-
set
public void set(int startIndex, int endIndex) Sets a range of bits- Parameters:
startIndex
- lower indexendIndex
- one-past the last bit to set
-
clear
public void clear(int startIndex, int 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()
-