Class BitSet¶
Defined in File bitSet.h
Inheritance Relationships¶
Base Type¶
public epics::pvData::Serializable
(Class Serializable)
Class Documentation¶
-
class BitSet : public epics::pvData::Serializable¶
A vector of bits.
This class implements a vector of bits that grows as needed. Each component of the bit set has a
bool
value. The bits of aBitSet
are indexed by nonnegative integers. Individual indexed bits can be examined, set, or cleared. OneBitSet
may be used to modify the contents of anotherBitSet
through logical AND, logical inclusive OR, and logical exclusive OR operations.By default, all bits in the set initially have the value
false
.Every bit set has a current size, which is the number of bits of space currently in use by the bit set. Note that the size is related to the implementation of a bit set, so it may change with implementation. The length of a bit set relates to logical length of a bit set and is defined independently of implementation.
A
BitSet
is not safe for multithreaded use without external synchronization.Based on Java implementation.
- Since
7.0.0 Many methods return BitSet& to facilite method chaining.
Public Functions
-
BitSet()¶
Creates a new bit set. All bits are initially
false
.
-
BitSet(uint32 nbits)¶
Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range
0
throughnbits-1
. All bits are initiallyfalse
.- Parameters
nbits – the initial size of the bit set
-
virtual ~BitSet()¶
Destructor.
-
BitSet &flip(uint32 bitIndex)¶
Sets the bit at the specified index to the complement of its current value.
- Parameters
bitIndex – the index of the bit to flip
-
BitSet &set(uint32 bitIndex)¶
Sets the bit at the specified index to
true
.- Parameters
bitIndex – a bit index
-
BitSet &clear(uint32 bitIndex)¶
Sets the bit specified by the index to
false
.- Parameters
bitIndex – the index of the bit to be cleared
-
void set(uint32 bitIndex, bool value)¶
Sets the bit at the specified index to the specified value.
- Parameters
bitIndex – a bit index
value – a boolean value to set
-
bool get(uint32 bitIndex) const¶
Returns the value of the bit with the specified index. The value is
true
if the bit with the indexbitIndex
is currently set in thisBitSet
; otherwise, the result isfalse
.- Parameters
bitIndex – the bit index
- Returns
the value of the bit with the specified index
-
int32 nextSetBit(uint32 fromIndex) const¶
Returns the index of the first bit that is set to
true
that occurs on or after the specified starting index. If no such bit exists then-1
is returned.To iterate over the
true
bits in aBitSet
, use the following loop:- Parameters
fromIndex – the index to start checking from (inclusive)
- Returns
the index of the next set bit, or
-1
if there is no such bit
-
int32 nextClearBit(uint32 fromIndex) const¶
Returns the index of the first bit that is set to
false
that occurs on or after the specified starting index.- Parameters
fromIndex – the index to start checking from (inclusive)
- Returns
the index of the next clear bit
-
bool isEmpty() const¶
Returns true if this
BitSet
contains no bits that are set totrue
.- Returns
indicating whether this
BitSet
is empty
-
uint32 cardinality() const¶
Returns the number of bits set to
true
in thisBitSet
.- Returns
the number of bits set to
true
in thisBitSet
-
uint32 size() const¶
Returns the number of bits of space actually in use by this
BitSet
to represent bit values. The maximum element in the set is the size - 1st element.- Returns
the number of bits currently in this bit set
-
bool logical_and(const BitSet &other) const¶
Returns true if any bit is set in both *this and other.
-
BitSet &operator&=(const BitSet &set)¶
Performs a bitwise AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value
true
if and only if it both initially had the valuetrue
and the corresponding bit in the bit set argument also had the valuetrue
.- Parameters
set – a bit set
-
BitSet &operator|=(const BitSet &set)¶
Performs a bitwise OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
true
if and only if it either already had the valuetrue
or the corresponding bit in the bit set argument has the valuetrue
.- Parameters
set – a bit set
-
BitSet &operator^=(const BitSet &set)¶
Performs a bitwise XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value
true
if and only if one of the following statements holds:The bit initially has the value
true
, and the corresponding bit in the argument has the valuefalse
.The bit initially has the value
false
, and the corresponding bit in the argument has the valuetrue
.
- Parameters
set – a bit set
-
void or_and(const BitSet &set1, const BitSet &set2)¶
Perform AND operation on
set1
andset2
, and OR on result and this instance.- Parameters
set1 –
set2 –
-
virtual void serialize(ByteBuffer *buffer, SerializableControl *flusher) const¶
Serialize field into given buffer.
- Parameters
buffer – serialization buffer.
flusher – flush interface.
-
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *flusher)¶
Deserialize buffer.
- Parameters
buffer – serialization buffer.
flusher – deserialization control.