Class BitSet

Inheritance Relationships

Base Type

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 a BitSet are indexed by nonnegative integers. Individual indexed bits can be examined, set, or cleared. One BitSet may be used to modify the contents of another BitSet 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

POINTER_DEFINITIONS(BitSet)
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 through nbits-1. All bits are initially false.

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 index bitIndex is currently set in this BitSet; otherwise, the result is false.

Parameters

bitIndex – the bit index

Returns

the value of the bit with the specified index

void clear()

Sets all of the bits in this BitSet to false.

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 a BitSet, 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 to true.

Returns

indicating whether this BitSet is empty

uint32 cardinality() const

Returns the number of bits set to true in this BitSet.

Returns

the number of bits set to true in this BitSet

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.

bool logical_or(const BitSet &other) const

Returns true if any bit is set in both *this or 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 value true and the corresponding bit in the bit set argument also had the value true.

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 value true or the corresponding bit in the bit set argument has the value true.

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 value false.

  • The bit initially has the value false, and the corresponding bit in the argument has the value true.

Parameters

set – a bit set

BitSet &operator=(const BitSet &set)

Assignment operator.

void swap(BitSet &set)

Swap contents.

void or_and(const BitSet &set1, const BitSet &set2)

Perform AND operation on set1 and set2, and OR on result and this instance.

Parameters
  • set1

  • set2

bool operator==(const BitSet &set) const

Comparison operator.

bool operator!=(const BitSet &set) const
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.

Public Static Functions

static BitSetPtr create(uint32 nbits)