org.apache.lucene.util

Class FixedBitSet

    • Constructor Detail

      • FixedBitSet

        public FixedBitSet(int 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
      • FixedBitSet

        public FixedBitSet(long[] storedBits,
                           int 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 store
        numBits - the number of bits actually needed
    • Method Detail

      • ensureCapacity

        public static FixedBitSet ensureCapacity(FixedBitSet bits,
                                                 int numBits)
        If the given FixedBitSet is large enough to hold numBits+1, returns the given bits, otherwise returns a new FixedBitSet which can hold the requested number of bits.

        NOTE: the returned bitset reuses the underlying long[] of the given bits if possible. Also, calling length() on the returned bits may return a value greater than numBits.

      • bits2words

        public static int bits2words(int numBits)
        returns the number of 64 bit words it would take to hold numBits
      • 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.
      • length

        public int length()
        Description copied from interface: Bits
        Returns the number of bits in this set
        Specified by:
        length in interface Bits
      • 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!
        Specified by:
        cardinality in class BitSet
      • get

        public boolean get(int index)
        Description copied from interface: Bits
        Returns the value of the bit with the specified index.
        Specified by:
        get in interface Bits
        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)
        Description copied from class: BitSet
        Set the bit at i.
        Specified by:
        set in class BitSet
      • getAndSet

        public boolean getAndSet(int index)
      • clear

        public void clear(int index)
        Description copied from interface: MutableBits
        Sets the bit specified by index to false.
        Specified by:
        clear in interface MutableBits
        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!
      • prevSetBit

        public int prevSetBit(int index)
        Description copied from class: BitSet
        Returns the index of the last set bit before or on the index specified. -1 is returned if there are no more set bits.
        Specified by:
        prevSetBit in class BitSet
      • or

        public void or(DocIdSetIterator iter)
                throws IOException
        Description copied from class: BitSet
        Does in-place OR of the bits provided by the iterator. The state of the iterator after this operation terminates is undefined.
        Overrides:
        or in class BitSet
        Throws:
        IOException
      • intersects

        public boolean intersects(FixedBitSet other)
        returns true if the sets have any elements in common
      • 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(int startIndex,
                         int endIndex)
        Flips a range of bits
        Parameters:
        startIndex - lower index
        endIndex - one-past the last bit to flip
      • flip

        public void flip(int index)
        Flip the bit at the provided index.
      • set

        public void set(int startIndex,
                        int endIndex)
        Sets a range of bits
        Parameters:
        startIndex - lower index
        endIndex - one-past the last bit to set
      • clear

        public void clear(int startIndex,
                          int endIndex)
        Description copied from class: BitSet
        Clears a range of bits.
        Specified by:
        clear in class BitSet
        Parameters:
        startIndex - lower index
        endIndex - one-past the last bit to clear