public class LongValueBitSet extends net.openhft.chronicle.core.io.AbstractCloseable implements Marshallable, ChronicleBitSet
ChronicleBitSet implementation backed by an array of
LongValues. The backing
words may reside in off-heap memory so the bit set can be shared
between processes. Operations are performed using compare-and-swap
loops rather than explicit locks.
Note: the capacity is fixed on construction and cannot be
expanded later.closedHere, DISABLE_DISCARD_WARNING, WARN_NSBITS_PER_WORDEMPTYDISCARD| Constructor and Description |
|---|
LongValueBitSet(int maxNumberOfBits)
Creates a bit set sized for
maxNumberOfBits bits. |
LongValueBitSet(int maxNumberOfBits,
Wire w)
Creates a bit set sized for
maxNumberOfBits bits and immediately
binds the backing array to the supplied Wire for serialisation. |
LongValueBitSet(long maxNumberOfBits)
Creates a bit set sized for
maxNumberOfBits bits. |
LongValueBitSet(long maxNumberOfBits,
Wire w)
Creates a bit set sized for
maxNumberOfBits bits and binds its
storage to a Wire for marshalling. |
| Modifier and Type | Method and Description |
|---|---|
void |
and(ChronicleBitSet set)
Performs a logical AND operation between this
ChronicleBitSet and the specified ChronicleBitSet. |
void |
and(LongValueBitSet set)
Performs a logical AND operation between this
ChronicleBitSet and the specified LongValueBitSet. |
void |
andNot(ChronicleBitSet set)
Clears all the bits in this
ChronicleBitSet where the corresponding bit is set in the specified ChronicleBitSet. |
void |
andNot(LongValueBitSet set)
Clears all the bits in this
ChronicleBitSet where the corresponding bit is set in the specified LongValueBitSet. |
int |
cardinality()
Counts the bits set to
true. |
void |
clear()
Sets all of the bits in this ChronicleBitSet to
false. |
void |
clear(int bitIndex)
Sets the bit specified by the index to
false. |
void |
clear(int fromIndex,
int toIndex)
Sets the bits from the specified
fromIndex (inclusive) to the specified toIndex (exclusive) to false. |
void |
copyFrom(ChronicleBitSet bitSet)
Copies the contents of
bitSet into this instance. |
boolean |
equals(Object obj)
Compares this
ChronicleBitSet object against the specified object. |
void |
flip(int bitIndex)
Atomically toggles the bit at
bitIndex. |
void |
flip(int fromIndex,
int toIndex)
Atomically flips bits in the range [
fromIndex, toIndex). |
boolean |
get(int bitIndex)
Returns the value of the bit with the specified index.
|
long |
getWord(int wordIndex)
Returns the raw word at
wordIndex. |
int |
getWordsInUse()
Returns the number of
LongValue words available in the backing
array. |
int |
hashCode()
Computes the hash code for this
ChronicleBitSet. |
boolean |
intersects(ChronicleBitSet set)
Checks if the current
ChronicleBitSet has any common set bits with the specified ChronicleBitSet. |
boolean |
intersects(LongValueBitSet set)
Checks if the current
ChronicleBitSet intersects with the provided LongValueBitSet. |
int |
nextClearBit(int fromIndex)
Returns the index of the first bit that is set to
false that occurs on or after the specified starting index. |
int |
nextSetBit(int fromIndex)
Returns the index of the first bit that is set to
true that occurs on or after the specified starting index. |
int |
nextSetBit(int fromIndex,
int toIndex)
Returns the index of the first bit that is set to
true that occurs on or after the specified starting index but before the toIndex. |
void |
or(ChronicleBitSet set)
Executes a logical OR operation between this
ChronicleBitSet and the provided ChronicleBitSet. |
void |
or(LongValueBitSet set)
Performs a logical OR operation between this
ChronicleBitSet and the provided LongValueBitSet. |
protected void |
performClose() |
int |
previousClearBit(int fromIndex)
This method searches for the closest bit set to
false from the specified starting index moving backwards. |
int |
previousSetBit(int fromIndex)
This method searches for the closest bit set to
true from the specified starting index moving backwards. |
void |
readMarshallable(@NotNull WireIn wire)
Deserialises the backing words from
wire. |
void |
set(int bitIndex)
Atomically sets the bit at
bitIndex. |
void |
set(int bitIndex,
boolean value)
Sets the bit at
bitIndex to value. |
void |
set(int fromIndex,
int toIndex)
Atomically sets all bits in the range [
fromIndex, toIndex) to true. |
void |
set(int fromIndex,
int toIndex,
boolean value)
Atomically sets all bits in the range to
value. |
void |
set(net.openhft.chronicle.core.values.LongValue word,
long newValue)
Atomically sets
word to newValue. |
void |
set(net.openhft.chronicle.core.values.LongValue word,
long param,
net.openhft.chronicle.wire.LongValueBitSet.LongFunction function)
Atomically updates
word using a compare‑and‑swap loop. |
void |
setWord(int wordIndex,
long bits)
Sets the raw word at
wordIndex to bits. |
int |
size()
Retrieves the number of bits that are actually being used by this
ChronicleBitSet to represent bit values. |
IntStream |
stream()
Returns a stream of indices for which this
ChronicleBitSet contains a bit in the set state. |
byte[] |
toByteArray()
Returns a little‑endian byte array representing this set.
|
String |
toString()
Returns a string representation of this bit set.
|
static BitSet |
valueOf(byte[] bytes)
Creates a new BitSet from a given byte array.
|
void |
writeMarshallable(@NotNull WireOut wire)
Serialises the backing words to
wire. |
void |
xor(ChronicleBitSet set)
Performs a logical XOR of this bit set with the bit set argument.
|
void |
xor(LongValueBitSet set)
Performs a logical XOR operation between this
ChronicleBitSet and the specified LongValueBitSet. |
assertCloseable, assertCloseablesClosed, close, createdHere, disableCloseableTracing, enableCloseableTracing, gcAndWaitForCloseablesToClose, isClosed, isClosing, isInUserThread, referenceId, shouldPerformCloseInBackground, shouldWaitForClosed, singleThreadedCheckDisabled, singleThreadedCheckDisabled, singleThreadedCheckReset, threadSafetyCheck, throwExceptionIfClosed, throwExceptionIfClosedInSetter, unmonitor, waitForCloseablesToClose, waitForClosed, warnAndCloseIfNotClosedclone, finalize, getClass, notify, notifyAll, wait, wait, waitisEmpty, length$equals, $fieldInfoMap, $fieldInfos, $hashCode, $toString, className, copyTo, deepCopy, fromFile, fromFile, fromString, fromString, fromString, getField, getLongField, mergeToMap, reset, setField, setLongField, streamFromFile, streamFromFilebinaryLengthLength, writeValueunexpectedFieldusesSelfDescribingMessageclose, closeQuietly, closeQuietlypublic LongValueBitSet(int maxNumberOfBits)
maxNumberOfBits bits.
The backing array is allocated but not bound to any Wire.maxNumberOfBits - maximum number of bits this set can holdpublic LongValueBitSet(int maxNumberOfBits,
Wire w)
maxNumberOfBits bits and immediately
binds the backing array to the supplied Wire for serialisation.maxNumberOfBits - maximum number of bits this set can holdw - wire used to marshal the initial statepublic LongValueBitSet(long maxNumberOfBits)
maxNumberOfBits bits.maxNumberOfBits - maximum number of bits this set can holdpublic static BitSet valueOf(byte[] bytes)
bytes - The byte array containing the bits.public long getWord(int wordIndex)
wordIndex. If the index is beyond the
backing array the value 0 is returned.getWord in interface ChronicleBitSetwordIndex - zero-based index of the word0 if out of rangepublic void setWord(int wordIndex,
long bits)
wordIndex to bits. The array is
not expanded; expandTo(int) will throw if the index is beyond the
configured capacity.setWord in interface ChronicleBitSetwordIndex - zero-based index of the word to modifybits - the 64 bits to storeprotected void performClose()
performClose in class net.openhft.chronicle.core.io.AbstractCloseablepublic int getWordsInUse()
LongValue words available in the backing
array. This is the fixed capacity rather than a logical size.getWordsInUse in interface ChronicleBitSetpublic void set(net.openhft.chronicle.core.values.LongValue word,
long param,
net.openhft.chronicle.wire.LongValueBitSet.LongFunction function)
word using a compare‑and‑swap loop. The
function computes a new value from the current one and
param. The pauser() is used between failed CAS
attempts to reduce contention.public void set(net.openhft.chronicle.core.values.LongValue word,
long newValue)
word to newValue. A CAS loop is used
with pauser() invoked between attempts when contention occurs.public byte[] toByteArray()
public void flip(int bitIndex)
bitIndex.flip in interface ChronicleBitSetbitIndex - zero-based index of the bit to flippublic void flip(int fromIndex,
int toIndex)
fromIndex, toIndex).flip in interface ChronicleBitSetfromIndex - zero-based start of the rangetoIndex - end of the range (exclusive)public void set(int bitIndex)
bitIndex.set in interface ChronicleBitSetbitIndex - index of the bit to setpublic void set(int bitIndex,
boolean value)
bitIndex to value.set in interface ChronicleBitSetbitIndex - zero-based index of the bit to modifyvalue - the value to store at that indexpublic void set(int fromIndex,
int toIndex)
fromIndex, toIndex) to true.set in interface ChronicleBitSetfromIndex - index of the first bit to set, zero-basedtoIndex - index after the last bit to setpublic void set(int fromIndex,
int toIndex,
boolean value)
value.set in interface ChronicleBitSetfromIndex - zero-based index of the first bit to modifytoIndex - index after the last bit to modifyvalue - value to store in the selected rangepublic void clear(int bitIndex)
false.clear in interface ChronicleBitSetbitIndex - index of the bit to clearpublic void clear(int fromIndex,
int toIndex)
fromIndex (inclusive) to the specified toIndex (exclusive) to false.clear in interface ChronicleBitSetfromIndex - zero-based start of the rangetoIndex - end of the range (exclusive)public void clear()
false.clear in interface ChronicleBitSetpublic boolean get(int bitIndex)
true if the bit with the index bitIndex
is currently set in this ChronicleBitSet; otherwise, the result is false.get in interface ChronicleBitSetbitIndex - the index of the bit to checkpublic int nextSetBit(int fromIndex)
true that occurs on or after the specified starting index.
If no such bit exists then -1 is returned.nextSetBit in interface ChronicleBitSetfromIndex - the index to start checking frompublic int nextSetBit(int fromIndex,
int toIndex)
true that occurs on or after the specified starting index but before the toIndex.
If no such bit exists then -1 is returned.nextSetBit in interface ChronicleBitSetfromIndex - the index to start checking fromtoIndex - the index to stop checking (exclusive)public int nextClearBit(int fromIndex)
false that occurs on or after the specified starting index.nextClearBit in interface ChronicleBitSetfromIndex - the index to start checking frompublic int previousSetBit(int fromIndex)
true from the specified starting index moving backwards.
If the bit at the specified starting index is set to true, it will return the index itself.
If no such bit exists before the given index, or if -1 is the specified index, then -1 is returned.fromIndex - The starting index to begin the search. The search moves towards the index 0 from this point.true) before the specified starting index, or -1 if none exists.IndexOutOfBoundsException - if fromIndex is less than -1public int previousClearBit(int fromIndex)
false from the specified starting index moving backwards.
If the bit at the specified starting index is set to false, it will return the index itself.
If no such unset bit exists before the given index, or if -1 is the specified index, then -1 is returned.fromIndex - The starting index to begin the search. The search moves towards the index 0 from this point.false) before the specified starting index, or -1 if none exists.IndexOutOfBoundsException - if fromIndex is less than -1public boolean intersects(ChronicleBitSet set)
ChronicleBitSet has any common set bits with the specified ChronicleBitSet.
If any bits set to true in the provided set are also set to true in this set, then the method returns true.intersects in interface ChronicleBitSetset - The ChronicleBitSet to compare with the current instance.true if there's an intersection, otherwise false.public boolean intersects(LongValueBitSet set)
ChronicleBitSet intersects with the provided LongValueBitSet.
This method is an overloaded version of the intersects method, designed to work specifically with LongValueBitSet.set - The LongValueBitSet to compare with the current instance.true if there's an intersection, otherwise false.public int cardinality()
true. Each word is read
with LongValue.getVolatileValue() for visibility.cardinality in interface ChronicleBitSetpublic void and(ChronicleBitSet set)
ChronicleBitSet and the specified ChronicleBitSet.
After this operation, a bit in this set will be set to true only if it was originally true and the corresponding bit in the specified set is true.and in interface ChronicleBitSetset - The ChronicleBitSet to perform the logical AND operation with.public void and(LongValueBitSet set)
ChronicleBitSet and the specified LongValueBitSet.
This is an overloaded version of the method that accepts ChronicleBitSet, designed to work with LongValueBitSet.
The logic of the operation is handled by the base method.set - The LongValueBitSet to perform the logical AND operation with.public void or(LongValueBitSet set)
ChronicleBitSet and the provided LongValueBitSet.
This overloaded version casts the provided set to its base type ChronicleBitSet before performing the operation.set - The LongValueBitSet to perform the logical OR operation with.public void or(ChronicleBitSet set)
ChronicleBitSet and the provided ChronicleBitSet.
Each bit in this set will be set to true if it was originally true or the corresponding bit in the provided set is true.or in interface ChronicleBitSetset - The ChronicleBitSet to perform the logical OR operation with.public void xor(ChronicleBitSet set)
true if and only if one of the following statements holds:
true, and the
corresponding bit in the argument has the value false.
false, and the
corresponding bit in the argument has the value true.
xor in interface ChronicleBitSetset - The ChronicleBitSet to perform the logical XOR operation with.public void xor(LongValueBitSet set)
ChronicleBitSet and the specified LongValueBitSet.
This is an overloaded version of the method that accepts ChronicleBitSet, designed to work with LongValueBitSet.
The logic of the operation is handled by the base method.set - The LongValueBitSet to perform the logical XOR operation with.public void andNot(ChronicleBitSet set)
ChronicleBitSet where the corresponding bit is set in the specified ChronicleBitSet.
Effectively performs a logical AND NOT operation on this bit set with the given set.andNot in interface ChronicleBitSetset - The ChronicleBitSet to use for clearing matching bits.public void andNot(LongValueBitSet set)
ChronicleBitSet where the corresponding bit is set in the specified LongValueBitSet.
This is an overloaded version designed to work with LongValueBitSet.set - The LongValueBitSet to use for clearing matching bits.public int hashCode()
ChronicleBitSet. The hash code is calculated based on the bit values that are set.public int size()
ChronicleBitSet to represent bit values.
Essentially, this is the highest set bit plus one.size in interface ChronicleBitSetpublic boolean equals(Object obj)
ChronicleBitSet object against the specified object. The result is true if and only if:
null.
ChronicleBitSet.
ChronicleBitSet objects have the exact same set of bits set to true.
int index k, the bits of both ChronicleBitSet objects at index k should be identical.public String toString()
ChronicleBitSet contains a bit in the set state, the decimal
representation of that index is included in the result. Such indices are listed in order from lowest to highest, separated by ", " (a
comma and a space) and surrounded by braces, resulting in the usual mathematical notation for a set of integers.toString in class net.openhft.chronicle.core.io.AbstractCloseablepublic IntStream stream()
ChronicleBitSet contains a bit in the set state. The indices are returned in order, from lowest to
highest. The size of the stream is the number of bits in the set state, equal to the value returned by the cardinality() method.public void writeMarshallable(@NotNull
@NotNull WireOut wire)
wire.writeMarshallable in interface MarshallablewriteMarshallable in interface WriteMarshallablewire - The wire output destination.public void readMarshallable(@NotNull
@NotNull WireIn wire)
throws net.openhft.chronicle.core.io.IORuntimeException
wire.readMarshallable in interface MarshallablereadMarshallable in interface ReadMarshallablewire - The wire input source.net.openhft.chronicle.core.io.IORuntimeException - If an IO error occurs during the read operation.public void copyFrom(ChronicleBitSet bitSet)
bitSet into this instance.copyFrom in interface ChronicleBitSetbitSet - source bit setCopyright © 2026 Chronicle Software Ltd. All rights reserved.