Class ThreadSafeBitSet

  • public class ThreadSafeBitSet
    extends Object
    This is a lock-free, thread-safe version of a BitSet.

    Instead of a long array to hold the bits, this implementation uses an AtomicLongArray, then does the appropriate compare-and-swap operations when setting the bits.

    • Field Detail


        public static final int DEFAULT_LOG2_SEGMENT_SIZE_IN_BITS
        See Also:
        Constant Field Values
    • Constructor Detail

      • ThreadSafeBitSet

        public ThreadSafeBitSet()
      • ThreadSafeBitSet

        public ThreadSafeBitSet​(int log2SegmentSizeInBits)
      • ThreadSafeBitSet

        public ThreadSafeBitSet​(int log2SegmentSizeInBits,
                                int numBitsToPreallocate)
    • Method Detail

      • set

        public void set​(int position)
      • setUntil

        public void setUntil​(int position)
      • clear

        public void clear​(int position)
      • get

        public boolean get​(int position)
      • maxSetBit

        public long maxSetBit()
      • nextSetBit

        public int nextSetBit​(int fromIndex)
      • cardinality

        public int cardinality()
        the number of bits which are set in this bit set.
      • getWords

        public long[] getWords()
      • currentCapacity

        public int currentCapacity()
        the number of bits which are current specified by this bit set. This is the maximum value to which you might need to iterate, if you were to iterate over all bits in this set.
      • clearAll

        public void clearAll()
        Clear all bits to 0.
      • andNot

        public ThreadSafeBitSet andNot​(ThreadSafeBitSet other)
        Return a new bit set which contains all bits which are contained in this bit set, and which are NOT contained in the other bit set.

        In other words, return a new bit set, which is a bitwise and with the bitwise not of the other bit set.

        other - the other bit set
        the resulting bit set
      • orAll

        public static ThreadSafeBitSet orAll​(ThreadSafeBitSet... bitSets)
        Return a new bit set which contains all bits which are contained in *any* of the specified bit sets.
        bitSets - the other bit sets
        the resulting bit set
      • hashCode

        public int hashCode()
        hashCode in class Object
      • toBitSet

        public BitSet toBitSet()
        a new BitSet with same bits set