Class GrowableBitSet

java.lang.Object
io.github.jbellis.jvector.util.BitSet
io.github.jbellis.jvector.util.GrowableBitSet
All Implemented Interfaces:
Accountable, Bits

public class GrowableBitSet extends BitSet
A BitSet implementation that grows as needed to accommodate set(index) calls. When it does so, it will grow its internal storage multiplicatively, assuming that more growth will be needed in the future. This is the important difference from FixedBitSet + FBS.ensureCapacity, which grows the minimum necessary each time.

For thread-safe version see SynchronizedGrowableBitSet.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.github.jbellis.jvector.util.Bits

    Bits.MatchAllBits, Bits.MatchNoBits
  • Field Summary

    Fields inherited from interface io.github.jbellis.jvector.util.Bits

    ALL, NONE
  • Constructor Summary

    Constructors
    Constructor
    Description
    GrowableBitSet(int initialBits)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Return an approximation of the cardinality of this set.
    int
    Return the number of bits that are set.
    void
    Clear all the bits of the set.
    void
    clear(int index)
    Clear the bit at i.
    void
    clear(int startIndex, int endIndex)
    Clears a range of bits.
    boolean
    get(int index)
    Returns the value of the bit with the specified index.
    boolean
    getAndSet(int index)
    Set the bit at i, returning true if it was previously set.
    int
    Returns the number of bits in this set
    int
    nextSetBit(int i)
    Returns the index of the first set bit starting at the index specified.
    int
    prevSetBit(int index)
    Returns the index of the last set bit before or on the index specified.
    long
     
    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
  • Constructor Details

    • GrowableBitSet

      public GrowableBitSet(BitSet bitSet)
    • GrowableBitSet

      public GrowableBitSet(int initialBits)
  • Method Details

    • clear

      public void clear(int index)
      Description copied from class: BitSet
      Clear the bit at i.
      Specified by:
      clear in class BitSet
    • clear

      public void clear()
      Description copied from class: BitSet
      Clear all the bits of the set.

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

      Overrides:
      clear in class BitSet
    • get

      public boolean get(int index)
      Description copied from interface: Bits
      Returns the value of the bit with the specified index.
      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.
    • getAndSet

      public boolean getAndSet(int index)
      Description copied from class: BitSet
      Set the bit at i, returning true if it was previously set.
      Specified by:
      getAndSet in class BitSet
    • length

      public int length()
      Description copied from interface: Bits
      Returns the number of bits in this set
    • set

      public void set(int i)
      Description copied from class: BitSet
      Set the bit at i.
      Specified by:
      set in class BitSet
    • 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
    • cardinality

      public int cardinality()
      Description copied from class: BitSet
      Return the number of bits that are set. NOTE: this method is likely to run in linear time
      Specified by:
      cardinality in class BitSet
    • approximateCardinality

      public int approximateCardinality()
      Description copied from class: BitSet
      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 BitSet.cardinality().
      Specified by:
      approximateCardinality in class BitSet
    • 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
    • nextSetBit

      public int nextSetBit(int i)
      Description copied from class: BitSet
      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.
      Specified by:
      nextSetBit in class BitSet
    • ramBytesUsed

      public long ramBytesUsed()