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
ConstructorDescriptionConcurrentBitSet
(int nbits) Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range0
throughnbits-1
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
int
void
clear()
void
clear
(int bitIndex) void
clear
(int fromIndex, int toIndex) clone()
Returns the clone of the internal wrappedBitSet
.boolean
void
flip
(int bitIndex) void
flip
(int fromIndex, int toIndex) boolean
get
(int bitIndex) get
(int fromIndex, int toIndex) int
hashCode()
boolean
intersects
(BitSet set) boolean
isEmpty()
int
nextClearBit
(int fromIndex) int
nextSetBit
(int fromIndex) void
int
previousClearBit
(int fromIndex) int
previousSetBit
(int fromIndex) int
Thread-safe version oflength()
.void
set
(int bitIndex) void
set
(int bitIndex, boolean value) void
set
(int fromIndex, int toIndex) void
set
(int fromIndex, int toIndex, boolean value) int
size()
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 range0
throughnbits-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:
nextSetBit
in classBitSet
-
nextClearBit
public int nextClearBit(int fromIndex) - Overrides:
nextClearBit
in classBitSet
-
previousSetBit
public int previousSetBit(int fromIndex) - Overrides:
previousSetBit
in classBitSet
-
previousClearBit
public int previousClearBit(int fromIndex) - Overrides:
previousClearBit
in classBitSet
-
isEmpty
public boolean isEmpty() -
cardinality
public int cardinality()- Overrides:
cardinality
in classBitSet
-
size
public int size() -
toByteArray
public byte[] toByteArray()- Overrides:
toByteArray
in classBitSet
-
toLongArray
public long[] toLongArray()- Overrides:
toLongArray
in 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:
intersects
in classBitSet
-
and
-
or
-
xor
-
andNot
-
clone
Returns the clone of the internal wrappedBitSet
. This won't be a clone of theConcurrentBitSet
object. -
toString
-
stream
This operation is not supported onConcurrentBitSet
. -
equals
-
hashCode
public int hashCode()
-