Package org.apache.lucene.util
Class FixedBitSet
- java.lang.Object
-
- org.apache.lucene.search.DocIdSet
-
- org.apache.lucene.util.FixedBitSet
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFixedBitSet.FixedBitSetIteratorADocIdSetIteratorwhich 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 Constructor Description FixedBitSet(int numBits)FixedBitSet(long[] storedBits, int numBits)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidand(DocIdSetIterator iter)Does in-place AND of the bits provided by the iterator.voidand(FixedBitSet other)this = this AND othervoidandNot(DocIdSetIterator iter)Does in-place AND NOT of the bits provided by the iterator.voidandNot(FixedBitSet other)this = this AND NOT otherstatic longandNotCount(FixedBitSet a, FixedBitSet b)Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))".Bitsbits()Optionally provides aBitsinterface for random access to matching documents.static intbits2words(int numBits)returns the number of 64 bit words it would take to hold numBitsintcardinality()Returns number of set bits.voidclear(int index)voidclear(int startIndex, int endIndex)Clears a range of bits.FixedBitSetclone()static FixedBitSetensureCapacity(FixedBitSet bits, int numBits)If the givenFixedBitSetis large enough to holdnumBits, returns the given bits, otherwise returns a newFixedBitSetwhich can hold the requested number of bits.booleanequals(java.lang.Object o)returns true if both sets have the same bits setvoidflip(int startIndex, int endIndex)Flips a range of bitsbooleanget(int index)Returns the value of the bit with the specifiedindex.booleangetAndClear(int index)booleangetAndSet(int index)long[]getBits()Expert.inthashCode()static longintersectionCount(FixedBitSet a, FixedBitSet b)Returns the popcount or cardinality of the intersection of the two sets.booleanintersects(FixedBitSet other)returns true if the sets have any elements in commonbooleanisCacheable()This DocIdSet implementation is cacheable.DocIdSetIteratoriterator()Provides aDocIdSetIteratorto access the set.intlength()Returns the number of bits in this setintnextSetBit(int index)Returns the index of the first set bit starting at the index specified.voidor(DocIdSetIterator iter)Does in-place OR of the bits provided by the iterator.voidor(FixedBitSet other)this = this OR otherintprevSetBit(int index)Returns the index of the last set bit before or on the index specified.voidset(int index)voidset(int startIndex, int endIndex)Sets a range of bitsstatic longunionCount(FixedBitSet a, FixedBitSet b)Returns the popcount or cardinality of the union of the two sets.voidxor(DocIdSetIterator iter)Does in-place XOR of the bits provided by the iterator.voidxor(FixedBitSet other)this = this XOR other
-
-
-
Method Detail
-
ensureCapacity
public static FixedBitSet ensureCapacity(FixedBitSet bits, int numBits)
If the givenFixedBitSetis large enough to holdnumBits, returns the given bits, otherwise returns a newFixedBitSetwhich 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(int numBits)
returns the number of 64 bit words it would take to hold numBits
-
intersectionCount
public static long intersectionCount(FixedBitSet a, FixedBitSet b)
Returns the popcount or cardinality of the intersection of the two sets. Neither set is modified.
-
unionCount
public static long unionCount(FixedBitSet a, FixedBitSet b)
Returns the popcount or cardinality of the union of the two sets. Neither set is modified.
-
andNotCount
public static long andNotCount(FixedBitSet a, FixedBitSet b)
Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))". Neither set is modified.
-
iterator
public DocIdSetIterator iterator()
Description copied from class:DocIdSetProvides aDocIdSetIteratorto access the set. This implementation can returnnullif there are no docs that match.
-
bits
public Bits bits()
Description copied from class:DocIdSetOptionally provides aBitsinterface for random access to matching documents.- Overrides:
bitsin classDocIdSet- Returns:
null, if thisDocIdSetdoes not support random access. In contrast toDocIdSet.iterator(), a return value ofnulldoes 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 (asBitsinterface 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:BitsReturns the number of bits in this set
-
isCacheable
public boolean isCacheable()
This DocIdSet implementation is cacheable.- Overrides:
isCacheablein 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:BitsReturns the value of the bit with the specifiedindex.- Specified by:
getin 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:
trueif the bit is set,falseotherwise.
-
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
public void or(DocIdSetIterator iter) throws java.io.IOException
Does in-place OR of the bits provided by the iterator.- Throws:
java.io.IOException
-
or
public void or(FixedBitSet other)
this = this OR other
-
xor
public void xor(FixedBitSet other)
this = this XOR other
-
xor
public void xor(DocIdSetIterator iter) throws java.io.IOException
Does in-place XOR of the bits provided by the iterator.- Throws:
java.io.IOException
-
and
public void and(DocIdSetIterator iter) throws java.io.IOException
Does in-place AND of the bits provided by the iterator.- Throws:
java.io.IOException
-
intersects
public boolean intersects(FixedBitSet other)
returns true if the sets have any elements in common
-
and
public void and(FixedBitSet other)
this = this AND other
-
andNot
public void andNot(DocIdSetIterator iter) throws java.io.IOException
Does in-place AND NOT of the bits provided by the iterator.- Throws:
java.io.IOException
-
andNot
public void andNot(FixedBitSet other)
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
public FixedBitSet clone()
-
equals
public boolean equals(java.lang.Object o)
returns true if both sets have the same bits set- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-