Class ConcurrentBitSet

java.lang.Object
java.util.BitSet
org.apache.pulsar.common.util.collections.ConcurrentBitSet
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
ConcurrentBitSetRecyclable

public class ConcurrentBitSet extends BitSet
A BitSet that is protected by a StampedLock to provide thread-safe access. The BitSet.length() method is not thread safe and is not overridden because StampedLock is not reentrant. Use the safeLength() method to get the length of the bit set in a thread-safe manner.
See Also:
  • Constructor Details

    • ConcurrentBitSet

      public ConcurrentBitSet()
    • ConcurrentBitSet

      public ConcurrentBitSet(int nbits)
      Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1. All bits are initially false.
      Parameters:
      nbits - the initial size of the bit set
      Throws:
      NegativeArraySizeException - if the specified initial size is negative
  • Method Details

    • get

      public boolean get(int bitIndex)
      Overrides:
      get in class BitSet
    • set

      public void set(int bitIndex)
      Overrides:
      set in class BitSet
    • clear

      public void clear(int bitIndex)
      Overrides:
      clear in class BitSet
    • set

      public void set(int fromIndex, int toIndex)
      Overrides:
      set in class BitSet
    • clear

      public void clear(int fromIndex, int toIndex)
      Overrides:
      clear in class BitSet
    • clear

      public void clear()
      Overrides:
      clear in class BitSet
    • nextSetBit

      public int nextSetBit(int fromIndex)
      Overrides:
      nextSetBit in class BitSet
    • nextClearBit

      public int nextClearBit(int fromIndex)
      Overrides:
      nextClearBit in class BitSet
    • previousSetBit

      public int previousSetBit(int fromIndex)
      Overrides:
      previousSetBit in class BitSet
    • previousClearBit

      public int previousClearBit(int fromIndex)
      Overrides:
      previousClearBit in class BitSet
    • isEmpty

      public boolean isEmpty()
      Overrides:
      isEmpty in class BitSet
    • cardinality

      public int cardinality()
      Overrides:
      cardinality in class BitSet
    • size

      public int size()
      Overrides:
      size in class BitSet
    • toByteArray

      public byte[] toByteArray()
      Overrides:
      toByteArray in class BitSet
    • toLongArray

      public long[] toLongArray()
      Overrides:
      toLongArray in class BitSet
    • flip

      public void flip(int bitIndex)
      Overrides:
      flip in class BitSet
    • flip

      public void flip(int fromIndex, int toIndex)
      Overrides:
      flip in class BitSet
    • set

      public void set(int bitIndex, boolean value)
      Overrides:
      set in class BitSet
    • set

      public void set(int fromIndex, int toIndex, boolean value)
      Overrides:
      set in class BitSet
    • get

      public BitSet get(int fromIndex, int toIndex)
      Overrides:
      get in class BitSet
    • safeLength

      public int safeLength()
      Thread-safe version of length(). StampedLock is not reentrant and that's why the length() method is not overridden. Overriding length() method would require to use a reentrant lock which would be less performant.
      Returns:
      length of the bit set
    • intersects

      public boolean intersects(BitSet set)
      Overrides:
      intersects in class BitSet
    • and

      public void and(BitSet set)
      Overrides:
      and in class BitSet
    • or

      public void or(BitSet set)
      Overrides:
      or in class BitSet
    • xor

      public void xor(BitSet set)
      Overrides:
      xor in class BitSet
    • andNot

      public void andNot(BitSet set)
      Overrides:
      andNot in class BitSet
    • clone

      public Object clone()
      Returns the clone of the internal wrapped BitSet. This won't be a clone of the ConcurrentBitSet object.
      Overrides:
      clone in class BitSet
      Returns:
      a clone of the internal wrapped BitSet
    • toString

      public String toString()
      Overrides:
      toString in class BitSet
    • stream

      public IntStream stream()
      This operation is not supported on ConcurrentBitSet.
      Overrides:
      stream in class BitSet
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class BitSet
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class BitSet