Class ConcurrentBitSet
java.lang.Object
java.util.BitSet
org.apache.pulsar.common.util.collections.ConcurrentBitSet
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
ConcurrentBitSetRecyclable
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 Summary
ConstructorsConstructorDescriptionConcurrentBitSet(int nbits) Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range0throughnbits-1. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidintvoidclear()voidclear(int bitIndex) voidclear(int fromIndex, int toIndex) clone()Returns the clone of the internal wrappedBitSet.booleanvoidflip(int bitIndex) voidflip(int fromIndex, int toIndex) booleanget(int bitIndex) get(int fromIndex, int toIndex) inthashCode()booleanintersects(BitSet set) booleanisEmpty()intnextClearBit(int fromIndex) intnextSetBit(int fromIndex) voidintpreviousClearBit(int fromIndex) intpreviousSetBit(int fromIndex) intThread-safe version oflength().voidset(int bitIndex) voidset(int bitIndex, boolean value) voidset(int fromIndex, int toIndex) voidset(int fromIndex, int toIndex, boolean value) intsize()stream()This operation is not supported onConcurrentBitSet.byte[]long[]toString()void
-
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 range0throughnbits-1. All bits are initiallyfalse.- 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) -
set
public void set(int bitIndex) -
clear
public void clear(int bitIndex) -
set
public void set(int fromIndex, int toIndex) -
clear
public void clear(int fromIndex, int toIndex) -
clear
public void clear() -
nextSetBit
public int nextSetBit(int fromIndex) - Overrides:
nextSetBitin classBitSet
-
nextClearBit
public int nextClearBit(int fromIndex) - Overrides:
nextClearBitin classBitSet
-
previousSetBit
public int previousSetBit(int fromIndex) - Overrides:
previousSetBitin classBitSet
-
previousClearBit
public int previousClearBit(int fromIndex) - Overrides:
previousClearBitin classBitSet
-
isEmpty
public boolean isEmpty() -
cardinality
public int cardinality()- Overrides:
cardinalityin classBitSet
-
size
public int size() -
toByteArray
public byte[] toByteArray()- Overrides:
toByteArrayin classBitSet
-
toLongArray
public long[] toLongArray()- Overrides:
toLongArrayin classBitSet
-
flip
public void flip(int bitIndex) -
flip
public void flip(int fromIndex, int toIndex) -
set
public void set(int bitIndex, boolean value) -
set
public void set(int fromIndex, int toIndex, boolean value) -
get
-
safeLength
public int safeLength()Thread-safe version oflength(). 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
- Overrides:
intersectsin classBitSet
-
and
-
or
-
xor
-
andNot
-
clone
Returns the clone of the internal wrappedBitSet. This won't be a clone of theConcurrentBitSetobject. -
toString
-
stream
This operation is not supported onConcurrentBitSet. -
equals
-
hashCode
public int hashCode()
-