BitSet (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.util, class: BitSet

Package org.apache.lucene.util

# Class BitSet

java.lang.Object
org.apache.lucene.util.BitSet

All Implemented Interfaces:
  `Accountable`, `Bits`

Direct Known Subclasses:
  `FixedBitSet`, `SparseFixedBitSet`

public abstract class BitSet extends Object implements Bits, Accountable
Base implementation for a bit set.

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.Accountable

  `NULL_ACCOUNTABLE`

  ### Fields inherited from interface org.apache.lucene.util.Bits

  `EMPTY_ARRAY`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BitSet()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract int`
  `approximateCardinality()`
  Return an approximation of the cardinality of this set.
  `abstract int`
  `cardinality()`
  Return the number of bits that are set.
  `protected final void`
  `checkUnpositioned(DocIdSetIterator iter)`
  Assert that the current doc is -1.
  `void`
  `clear()`
  Clear all the bits of the set.
  `abstract void`
  `clear(int i)`
  Clear the bit at `i`.
  `abstract void`
  `clear(int startIndex, int endIndex)`
  Clears a range of bits.
  `abstract boolean`
  `getAndSet(int i)`
  Set the bit at `i`, returning `true` if it was previously set.
  `int`
  `nextClearBit(int index)`
  Returns the index of the first unset (clear) bit at or after `index`, or `DocIdSetIterator.NO_MORE_DOCS` if every bit in `[index, length())` is set.
  `abstract int`
  `nextClearBit(int start, int upperBound)`
  Returns the first unset bit in `[start, upperBound)`, or `DocIdSetIterator.NO_MORE_DOCS` if none.
  `int`
  `nextSetBit(int index)`
  Returns the index of the first set bit starting at the index specified.
  `abstract int`
  `nextSetBit(int start, int end)`
  Returns the index of the first set bit from start (inclusive) until end (exclusive).
  `static BitSet`
  `of(DocIdSetIterator it, int maxDoc)`
  Build a `BitSet` from the content of the provided `DocIdSetIterator`.
  `void`
  `or(DocIdSetIterator iter)`
  Does in-place OR of the bits provided by the iterator.
  `abstract int`
  `prevSetBit(int index)`
  Returns the index of the last set bit before or on the index specified.
  `abstract void`
  `set(int i)`
  Set the bit at `i`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.lucene.util.Accountable

  `getChildResources, ramBytesUsed`

  ### Methods inherited from interface org.apache.lucene.util.Bits

  `applyMask, get, length`

- ## Constructor Details

  - ### BitSet

    public BitSet()

- ## Method Details

  - ### of

    public static BitSet of(DocIdSetIterator it, int maxDoc) throws IOException
    Build a `BitSet` from the content of the provided `DocIdSetIterator`. NOTE: this will fully consume the `DocIdSetIterator`.
    Throws:
      `IOException`

  - ### clear

    public void clear()
    Clear all the bits of the set.

    Depending on the implementation, this may be significantly faster than clear(0, length).

  - ### set

    public abstract void set(int i)
    Set the bit at `i`.

  - ### getAndSet

    public abstract boolean getAndSet(int i)
    Set the bit at `i`, returning `true` if it was previously set.

  - ### clear

    public abstract void clear(int i)
    Clear the bit at `i`.

  - ### clear

    public abstract void clear(int startIndex, int endIndex)
    Clears a range of bits.
    Parameters:
      `startIndex` - lower index
      `endIndex` - one-past the last bit to clear

  - ### cardinality

    public abstract int cardinality()
    Return the number of bits that are set. NOTE: this method is likely to run in linear time

  - ### approximateCardinality

    public abstract int approximateCardinality()
    Return an approximation of the cardinality of this set. Some implementations may trade accuracy for speed if they have the ability to estimate the cardinality of the set without iterating over all the data. The default implementation returns `cardinality()`.

  - ### prevSetBit

    public abstract 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.

  - ### nextSetBit

    public int nextSetBit(int index)
    Returns the index of the first set bit starting at the index specified. `DocIdSetIterator.NO_MORE_DOCS` is returned if there are no more set bits.

  - ### nextSetBit

    public abstract int nextSetBit(int start, int end)
    Returns the index of the first set bit from start (inclusive) until end (exclusive). `DocIdSetIterator.NO_MORE_DOCS` is returned if there are no more set bits.

  - ### nextClearBit

    public int nextClearBit(int index)
    Returns the index of the first unset (clear) bit at or after `index`, or `DocIdSetIterator.NO_MORE_DOCS` if every bit in `[index, length())` is set.

  - ### nextClearBit

    public abstract int nextClearBit(int start, int upperBound)
    Returns the first unset bit in `[start, upperBound)`, or `DocIdSetIterator.NO_MORE_DOCS` if none.

  - ### checkUnpositioned

    protected final void checkUnpositioned(DocIdSetIterator iter)
    Assert that the current doc is -1.

  - ### or

    public void or(DocIdSetIterator iter) throws IOException
    Does in-place OR of the bits provided by the iterator. The state of the iterator after this operation terminates is undefined.
    Throws:
      `IOException`