BloombergLP::bdlc::BitArray

This class implements an efficient, value-semantic array of boolean (a.k.a. bit, i.e., binary digit) values stored in contiguous memory. The physical capacity of this array may grow, but never shrinks. Capacity may be reserved initially via a constructor, or at any time thereafter by using the reserveCapacity method; otherwise, capacity will be increased automatically as needed. Note that capacity is not a salient attribute of this object, and, as such, does not contribute to overall value. Also note that this class provides an implicit no-throw guarantee for all methods (including manipulators) that do not attempt to alter capacity.

Synopsis

Declared in <bdlc_bitarray.h>

class BitArray;

Enums

NameDescription
Unnamed enum Constants describing the storage representation of a BitArray.

Member Functions

NameDescription
BitArray [constructor]Constructors
~BitArray [destructor]Destroy this object.
operator= Assign to this array the value of the specified rhs array, and return a non-const reference to this array.
allocator Return the allocator used by this object to supply memory.
andEqual andEqual overloads
append append overloads
assign assign overloads
assign0 assign0 overloads
assign1 assign1 overloads
assignAll Set all bits in this array to the specified value.
assignAll0 Set to 0 the value of every bit in this array.
assignAll1 Set to 1 the value of every bit in this array.
assignBits Assign the low-order specified numBits from the specified srcBits to this object, starting at the specified index. The behavior is undefined unless numBits <= k_BITS_PER_UINT64 and index + numBits <= length().
bdexStreamIn Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated, but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state. Note that no version is read from stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
bdexStreamOut Write the value of this object, using the specified version format, to the specified output stream, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated, but otherwise unmodified. Note that version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
bits Return the specified numBits beginning at the specified index in this array as the low-order bits of the returned value. The behavior is undefined unless numBits <= sizeof(uint64_t) * CHAR_BIT and index + numBits <= length().
find0AtMaxIndex Return the index of the most-significant 0 bit in this array in the range optionally specified by begin and end, and k_INVALID_INDEX otherwise. The range is [begin .. effectiveEnd)], where effectiveEnd == length() if end is not specified and effectiveEnd == end otherwise. The behavior is undefined unless begin <= effectiveEnd <= length().
find0AtMinIndex Return the index of the least-significant 0 bit in this array in the range optionally specified by begin and end, and k_INVALID_INDEX otherwise. The range is [begin .. effectiveEnd)], where effectiveEnd == length() if end is not specified and effectiveEnd == end otherwise. The behavior is undefined unless begin <= effectiveEnd <= length().
find1AtMaxIndex Return the index of the most-significant 1 bit in this array in the range optionally specified by begin and end, and k_INVALID_INDEX otherwise. The range is [begin .. effectiveEnd)], where effectiveEnd == length() if end is not specified and effectiveEnd == end otherwise. The behavior is undefined unless begin <= effectiveEnd <= length().
find1AtMinIndex Return the index of the least-significant 1 bit in this array in the range optionally specified by begin and end, and k_INVALID_INDEX otherwise. The range is [begin .. effectiveEnd)], where effectiveEnd == length() if end is not specified and effectiveEnd == end otherwise. The behavior is undefined unless begin <= effectiveEnd <= length().
insert insert overloads
isAny0 Return true if the value of any bit in this array is 0, and false otherwise.
isAny1 Return true if the value of any bit in this array is 1, and false otherwise.
isEmpty Return true if the length of this bit array is 0, and false otherwise.
length Return the number of bits in this array.
minusEqual minusEqual overloads
num0 Return the number of bits in the range optionally specified by begin and end having a value of 0. The range is [begin .. effectiveEnd)], where effectiveEnd == length() if end is not specified and effectiveEnd == end otherwise. The behavior is undefined unless begin <= effectiveEnd <= length().
num1 Return the number of bits in the range optionally specified by begin and end having a value of 1. The range is [begin .. effectiveEnd)], where effectiveEnd == length() if end is not specified and effectiveEnd == end otherwise. The behavior is undefined unless begin <= effectiveEnd <= length().
operator&= Bitwise AND the value of the specified rhs array with the value of this array (retaining the results), and return a non-const reference to this object. The length of the result will be the maximum of the lengths of this object and rhs, where any most-significant bits that are represented in one of the two but not the other will be set to 0. Note that a &= b; will result in the same value of a as a = a & b;.
operator-= Bitwise MINUS the value of the specified rhs array from the value of this array (retaining the results), and return a non-const reference to this object. The length of the result will be the maximum of the lengths of this object and rhs. If length() > rhs.length(), the unmatched most-significant bits in this array are left unchanged; otherwise, any high-order bits of the result that were not present in this object prior to the operation will be set to 0. Note that a -= b; will result in the same value of a as a = a - b; and if a and b are the same length, a -= b; will result in the same value of a as a &= ~b; or a = a & ~b;.
operator<<= Shift the bits in this array LEFT by the specified numBits, filling lower-order bits with zeros (retaining the results), and return a non-const reference to this object. The behavior is undefined unless numBits <= length(). Note that the length of this array is unchanged and the highest-order numBits are discarded.
operator>>= Shift the bits in this array RIGHT by the specified numBits, filling higher-order bits with zeros and discarding low-order bits, and return a non-const reference to this object. The behavior is undefined unless numBits <= length(). Note that the length of this array is unchanged.
operator[] Return the value of the bit at the specified index in this array. The behavior is undefined unless index < length().
operator^= Bitwise XOR the value of the specified rhs array with the value of this array (retaining the results), and return a non-const reference to this object. If length() > rhs.length(), the unmatched most-significant bits in this array are left unchanged; otherwise, any unmatched most-significant bits in rhs are propagated to the result without modification. Note that a ^= b; will result in the same value of a as a = a ^ b;.
operator|= Bitwise OR the value of the specified rhs array with the value of this array (retaining the results), and return a non-const reference to this object. If length() > rhs.length(), the unmatched most-significant bits in this array are left unchanged; otherwise, any unmatched most-significant bits in rhs are propagated to the result without modification. Note that a |= b; will result in the same value of a as a = a | b;.
orEqual orEqual overloads
print Format this object to the specified output stream at the optionally specified indentation level and return a non-const reference to stream. If level is specified, optionally specify spacesPerLevel, the number of spaces per indentation level for this and all of its nested objects. Each line is indented by the absolute value of level * spacesPerLevel. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, suppress line breaks and format the entire output on one line. If stream is initially invalid, this operation has no effect. Note that a trailing newline is provided in multiline mode only.
remove remove overloads
removeAll Remove all of the bits in this array, leaving the length 0, but having no effect on capacity.
reserveCapacity Reserve sufficient internal capacity to accommodate a length of at least the specified numBits without reallocation. If an exception is thrown during this reallocation attempt (i.e., by the memory allocator indicated at construction) the value of this array is guaranteed to be unchanged.
rotateLeft Shift the values in this array to the left by the specified numBits positions, with the high-order values "rotating" into the low-order bits. The behavior is undefined unless numBits <= length(). Note that the length of this array remains unchanged.
rotateRight Shift the values in this array to the right by the specified numBits positions, with the low-order values "rotating" into the high-order bits. The behavior is undefined unless numBits <= length(). Note that the length of this array remains unchanged.
setLength Set the number of bits in this array to the specified newLength. If newLength < length(), bits at index positions at or above newLength are removed; otherwise, any new bits (at or above the current length) are initialized to the optionally specified value, or to 0 if value is not specified.
swap Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee. The behavior is undefined unless this object was created with the same allocator as other.
swapBits Efficiently exchange the values of the bits at the specified index1 and index2 indices. The behavior is undefined unless index1 < length() and index2 < length().
toggle toggle overloads
toggleAll Complement the value of every bit in this array. Note that the behavior is analogous to applying the ~ operator to an object of fundamental type unsigned int.
xorEqual xorEqual overloads

Static Member Functions

NameDescription
maxSupportedBdexVersion maxSupportedBdexVersion overloads

Static Data Members

NameDescription
k_INVALID_INDEX Sentinel index value indicating an invalid bit position.

Friends

NameDescription
BloombergLP::bdlc::operator==Return true if the specified lhs and rhs arrays have the same value, and false otherwise. Two arrays have the same value if they have the same length, and corresponding bits at each bit position have the same value.

Non-Member Functions

NameDescription
operator!=Return true if the specified lhs and rhs arrays do not have the same value, and false otherwise. Two arrays do not have the same value if they do not have the same length, or there is at least one valid index position at which corresponding bits do not have the same value.
operator&Return the value that is the bitwise AND of the specified lhs and rhs arrays. The length of the resulting bit array will be the maximum of that of lhs and rhs, with any unmatched high-order bits set to 0. Note that this behavior is consistent with zero-extending a copy of the shorter array.
operator-Return the value that is the bitwise MINUS of the specified lhs and rhs arrays. The length of the resulting bit array will be the maximum of that of lhs and rhs, with any unmatched high-order lhs bits copied unchanged, and any unmatched high-order rhs bits set to 0. Note that this behavior is consistent with zero-extending a copy of the shorter array.
operator<<Return the value of the specified array left-shifted by the specified numBits positions, having filled the lower-index positions with zeros. The behavior is undefined unless numBits <= array.length(). Note that the length of the result equals the length of the original array, and that the highest-order numBits are discarded in the result.
operator>>Return the value of the specified array right-shifted by the specified numBits positions, having filled the higher-index positions with zeros. The behavior is undefined unless numBits <= array.length(). Note that the length of the result equals the length of the original array, and that the lowest-order numBits are discarded in the result.
operator^Return the value that is the bitwise XOR of the specified lhs and rhs arrays. The length of the resulting bit array will be the maximum of that of lhs and rhs, with any unmatched high-order bits copied unchanged. Note that this behavior is consistent with zero-extending a copy of the shorter array.
operator|Return the value that is the bitwise OR of the specified lhs and rhs arrays. The length of the resulting bit array will be the maximum of that of lhs and rhs, with any unmatched high-order bits copied unchanged. Note that this behavior is consistent with zero-extending a copy of the shorter array.
operator~Return the bitwise complement ("toggle") of the specified array.
swapExchange the values of the specified a and b objects. This function provides the no-throw exception-safety guarantee if the two objects were created with the same allocator and the basic guarantee otherwise.