BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlb::BitStringUtil Struct Reference

#include <bdlb_bitstringutil.h>

Public Types

enum  { k_BITS_PER_UINT64 = 64 }
 

Static Public Member Functions

static void assign (bsl::uint64_t *bitString, bsl::size_t index, bool value)
 
static void assign (bsl::uint64_t *bitString, bsl::size_t index, bool value, bsl::size_t numBits)
 
static void assign0 (bsl::uint64_t *bitString, bsl::size_t index)
 
static void assign0 (bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static void assign1 (bsl::uint64_t *bitString, bsl::size_t index)
 
static void assign1 (bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static void assignBits (bsl::uint64_t *bitString, bsl::size_t index, bsl::uint64_t srcValue, bsl::size_t numBits)
 
static void andEqual (bsl::uint64_t *dstBitString, bsl::size_t dstIndex, const bsl::uint64_t *srcBitString, bsl::size_t srcIndex, bsl::size_t numBits)
 
static void minusEqual (bsl::uint64_t *dstBitString, bsl::size_t dstIndex, const bsl::uint64_t *srcBitString, bsl::size_t srcIndex, bsl::size_t numBits)
 
static void orEqual (bsl::uint64_t *dstBitString, bsl::size_t dstIndex, const bsl::uint64_t *srcBitString, bsl::size_t srcIndex, bsl::size_t numBits)
 
static void xorEqual (bsl::uint64_t *dstBitString, bsl::size_t dstIndex, const bsl::uint64_t *srcBitString, bsl::size_t srcIndex, bsl::size_t numBits)
 
static void copy (bsl::uint64_t *dstBitString, bsl::size_t dstIndex, const bsl::uint64_t *srcBitString, bsl::size_t srcIndex, bsl::size_t numBits)
 
static void copyRaw (bsl::uint64_t *dstBitString, bsl::size_t dstIndex, const bsl::uint64_t *srcBitString, bsl::size_t srcIndex, bsl::size_t numBits)
 
static void insert (bsl::uint64_t *bitString, bsl::size_t initialLength, bsl::size_t dstIndex, bool value, bsl::size_t numBits)
 
static void insert0 (bsl::uint64_t *bitString, bsl::size_t initialLength, bsl::size_t dstIndex, bsl::size_t numBits)
 
static void insert1 (bsl::uint64_t *bitString, bsl::size_t initialLength, bsl::size_t dstIndex, bsl::size_t numBits)
 
static void insertRaw (bsl::uint64_t *bitString, bsl::size_t initialLength, bsl::size_t dstIndex, bsl::size_t numBits)
 
static void remove (bsl::uint64_t *bitString, bsl::size_t length, bsl::size_t index, bsl::size_t numBits)
 
static void removeAndFill0 (bsl::uint64_t *bitString, bsl::size_t length, bsl::size_t index, bsl::size_t numBits)
 
static void removeAndFill1 (bsl::uint64_t *bitString, bsl::size_t length, bsl::size_t index, bsl::size_t numBits)
 
static void swapRaw (bsl::uint64_t *bitString1, bsl::size_t index1, bsl::uint64_t *bitString2, bsl::size_t index2, bsl::size_t numBits)
 
static void toggle (bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static bool areEqual (const bsl::uint64_t *bitString1, const bsl::uint64_t *bitString2, bsl::size_t numBits)
 
static bool areEqual (const bsl::uint64_t *bitString1, bsl::size_t index1, const bsl::uint64_t *bitString2, bsl::size_t index2, bsl::size_t numBits)
 
static bool bit (const bsl::uint64_t *bitString, bsl::size_t index)
 
static bsl::uint64_t bits (const bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static bsl::size_t find0AtMaxIndex (const bsl::uint64_t *bitString, bsl::size_t length)
 
static bsl::size_t find0AtMaxIndex (const bsl::uint64_t *bitString, bsl::size_t begin, bsl::size_t end)
 
static bsl::size_t find0AtMinIndex (const bsl::uint64_t *bitString, bsl::size_t length)
 
static bsl::size_t find0AtMinIndex (const bsl::uint64_t *bitString, bsl::size_t begin, bsl::size_t end)
 
static bsl::size_t find1AtMaxIndex (const bsl::uint64_t *bitString, bsl::size_t length)
 
static bsl::size_t find1AtMaxIndex (const bsl::uint64_t *bitString, bsl::size_t begin, bsl::size_t end)
 
static bsl::size_t find1AtMinIndex (const bsl::uint64_t *bitString, bsl::size_t length)
 
static bsl::size_t find1AtMinIndex (const bsl::uint64_t *bitString, bsl::size_t begin, bsl::size_t end)
 
static bool isAny0 (const bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static bool isAny1 (const bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static bsl::size_t num0 (const bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static bsl::size_t num1 (const bsl::uint64_t *bitString, bsl::size_t index, bsl::size_t numBits)
 
static bsl::ostream & print (bsl::ostream &stream, const bsl::uint64_t *bitString, bsl::size_t numBits, int level=1, int spacesPerLevel=4)
 

Static Public Attributes

static const bsl::size_t k_INVALID_INDEX = ~static_cast<bsl::size_t>(0)
 

Detailed Description

This struct provides a namespace for a suite of static functions to manipulate and access sequences of bits stored in an array of uint64_t (also known as a "bit string"; see {The "Bit String" Pseudo-Type}).

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
k_BITS_PER_UINT64 

Member Function Documentation

◆ andEqual()

static void bdlb::BitStringUtil::andEqual ( bsl::uint64_t *  dstBitString,
bsl::size_t  dstIndex,
const bsl::uint64_t *  srcBitString,
bsl::size_t  srcIndex,
bsl::size_t  numBits 
)
static

Bitwise AND the specified numBits of the specified dstBitString starting at the specified dstIndex with the numBits of the specified srcBitString starting at the specified srcIndex, and write the result over the bits that were read from dstBitString. The behavior is undefined unless dstBitString has a length of at least dstIndex + numBits and srcBitString has a length of at least srcIndex + numBits.

◆ areEqual() [1/2]

static bool bdlb::BitStringUtil::areEqual ( const bsl::uint64_t *  bitString1,
bsl::size_t  index1,
const bsl::uint64_t *  bitString2,
bsl::size_t  index2,
bsl::size_t  numBits 
)
static

Return true if the specified numBits beginning at the specified index1 in the specified bitString1 are bitwise equal to the numBits beginning at the specified index2 in the specified bitString2, and false otherwise. The behavior is undefined unless bitString1 has a length of at least index1 + numBits and bitString2 has a length of at least index2 + numBits.

◆ areEqual() [2/2]

static bool bdlb::BitStringUtil::areEqual ( const bsl::uint64_t *  bitString1,
const bsl::uint64_t *  bitString2,
bsl::size_t  numBits 
)
static

Return true if the specified low-order numBits in the specified bitString1 are bitwise equal to the corresponding bits in the specified bitString2, and false otherwise. The behavior is undefined unless both bitString1 and bitString2 have a length of at least numBits.

◆ assign() [1/2]

void bdlb::BitStringUtil::assign ( bsl::uint64_t *  bitString,
bsl::size_t  index,
bool  value 
)
inlinestatic

Set the bit at the specified index in the specified bitString to the specified value. The behavior is undefined unless index is less than the capacity of bitString.

◆ assign() [2/2]

static void bdlb::BitStringUtil::assign ( bsl::uint64_t *  bitString,
bsl::size_t  index,
bool  value,
bsl::size_t  numBits 
)
static

Set the specified numBits beginning at the specified index in the specified bitString to the specified value. The behavior is undefined unless bitString has a capacity of at least index + numBits.

◆ assign0() [1/2]

void bdlb::BitStringUtil::assign0 ( bsl::uint64_t *  bitString,
bsl::size_t  index 
)
inlinestatic

Set the bit at the specified index in the specified bitString to false. The behavior is undefined unless index is less than the capacity of bitString.

◆ assign0() [2/2]

static void bdlb::BitStringUtil::assign0 ( bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Set the specified numBits beginning at the specified index in the specified bitString to false. The behavior is undefined unless bitString has a capacity of at least index + numBits.

◆ assign1() [1/2]

void bdlb::BitStringUtil::assign1 ( bsl::uint64_t *  bitString,
bsl::size_t  index 
)
inlinestatic

Set the bit at the specified index in the specified bitString to true. The behavior is undefined unless index is less than the capacity of bitString.

◆ assign1() [2/2]

static void bdlb::BitStringUtil::assign1 ( bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Set the specified numBits beginning at the specified index in the specified bitString to true. The behavior is undefined unless bitString has a capacity of at least index + numBits.

◆ assignBits()

static void bdlb::BitStringUtil::assignBits ( bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::uint64_t  srcValue,
bsl::size_t  numBits 
)
static

Assign the low-order specified numBits from the specified srcValue to the numBits starting at the specified index in the specified bitString. The behavior is undefined unless numBits <= k_BITS_PER_UINT64 and bitString has a capacity of at least index + numBits.

◆ bit()

bool bdlb::BitStringUtil::bit ( const bsl::uint64_t *  bitString,
bsl::size_t  index 
)
inlinestatic

Return the bit value at the specified index in the specified bitString. The behavior is undefined unless index is less than the length of bitString.

◆ bits()

static bsl::uint64_t bdlb::BitStringUtil::bits ( const bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Return the specified numBits beginning at the specified index in the specified bitString as the low-order bits of the returned value. The behavior is undefined unless numBits <= k_BITS_PER_UINT64 and bitString has a length of at least index + numBits.

◆ copy()

static void bdlb::BitStringUtil::copy ( bsl::uint64_t *  dstBitString,
bsl::size_t  dstIndex,
const bsl::uint64_t *  srcBitString,
bsl::size_t  srcIndex,
bsl::size_t  numBits 
)
static

Copy to the specified dstBitString, beginning at the specified dstIndex, the specified numBits beginning at the specified srcIndex in the specified srcBitString. This function works correctly regardless of whether the source and destination ranges overlap. The behavior is undefined unless dstBitString has a capacity of at least dstIndex + numBits and srcBitString has a length of at least srcIndex + numBits.

◆ copyRaw()

static void bdlb::BitStringUtil::copyRaw ( bsl::uint64_t *  dstBitString,
bsl::size_t  dstIndex,
const bsl::uint64_t *  srcBitString,
bsl::size_t  srcIndex,
bsl::size_t  numBits 
)
static

Copy to the specified dstBitString, beginning at the specified dstIndex, the specified numBits beginning at the specified srcIndex in the specified srcBitString. The behavior is undefined unless dstBitString has a capacity of at least dstIndex + numBits, srcBitString has a length of at least srcIndex + numBits, and the source and destination ranges either do not overlap, or the destination range is equal to the source range, or the start of the destination range is below the start of the source range.

◆ find0AtMaxIndex() [1/2]

static bsl::size_t bdlb::BitStringUtil::find0AtMaxIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  begin,
bsl::size_t  end 
)
static

Return the index of the most-significant 0 bit in the specified bitString in the specified range [begin .. end), if such a bit exists, and k_INVALID_INDEX otherwise. The behavior is undefined unless begin <= end and end is less than or equal to the length of bitString.

◆ find0AtMaxIndex() [2/2]

static bsl::size_t bdlb::BitStringUtil::find0AtMaxIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  length 
)
static

Return the index of the most-significant 0 bit in the specified bitString having the specified length, if such a bit exists, and k_INVALID_INDEX otherwise.

◆ find0AtMinIndex() [1/2]

static bsl::size_t bdlb::BitStringUtil::find0AtMinIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  begin,
bsl::size_t  end 
)
static

Return the index of the least-significant 0 bit in the specified bitString in the specified range [begin .. end), if such a bit exists, and k_INVALID_INDEX otherwise. The behavior is undefined unless begin <= end and end is less than or equal to the length of bitString.

◆ find0AtMinIndex() [2/2]

static bsl::size_t bdlb::BitStringUtil::find0AtMinIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  length 
)
static

Return the index of the least-significant 0 bit in the specified bitString having the specified length, if such a bit exists, and k_INVALID_INDEX otherwise.

◆ find1AtMaxIndex() [1/2]

static bsl::size_t bdlb::BitStringUtil::find1AtMaxIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  begin,
bsl::size_t  end 
)
static

Return the index of the most-significant 1 bit in the specified bitString in the specified range [begin .. end), if such a bit exists, and k_INVALID_INDEX otherwise. The behavior is undefined unless begin <= end and end is less than or equal to the length of bitString.

◆ find1AtMaxIndex() [2/2]

static bsl::size_t bdlb::BitStringUtil::find1AtMaxIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  length 
)
static

Return the index of the most-significant 1 bit in the specified bitString having the specified length, if such a bit exists, and k_INVALID_INDEX otherwise.

◆ find1AtMinIndex() [1/2]

static bsl::size_t bdlb::BitStringUtil::find1AtMinIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  begin,
bsl::size_t  end 
)
static

Return the index of the least-significant 1 bit in the specified bitString in the specified range [begin .. end), if such a bit exists, and k_INVALID_INDEX otherwise. The behavior is undefined unless begin <= end and end is less than or equal to the length of bitString.

◆ find1AtMinIndex() [2/2]

static bsl::size_t bdlb::BitStringUtil::find1AtMinIndex ( const bsl::uint64_t *  bitString,
bsl::size_t  length 
)
static

Return the index of the least-significant 1 bit in the specified bitString having the specified length, if such a bit exists, and k_INVALID_INDEX otherwise.

◆ insert()

void bdlb::BitStringUtil::insert ( bsl::uint64_t *  bitString,
bsl::size_t  initialLength,
bsl::size_t  dstIndex,
bool  value,
bsl::size_t  numBits 
)
inlinestatic

Insert the specified numBits, each having the specified value, into the specified bitString having the specified initialLength, beginning at the specified dstIndex. Bits at or above dstIndex are shifted up by numBits index positions and the length of bitString is increased by numBits. The behavior is undefined unless dstIndex <= initialLength and bitString has a capacity of at least initialLength + numBits.

◆ insert0()

void bdlb::BitStringUtil::insert0 ( bsl::uint64_t *  bitString,
bsl::size_t  initialLength,
bsl::size_t  dstIndex,
bsl::size_t  numBits 
)
inlinestatic

Insert the specified numBits 0 bits into the specified bitString having the specified initialLength beginning at the specified dstIndex. Bits at or above dstIndex are shifted up by numBits index positions and the length of bitString is increased by numBits. The behavior is undefined unless dstIndex <= initialLength and bitString has a capacity of at least initialLength + numBits.

◆ insert1()

void bdlb::BitStringUtil::insert1 ( bsl::uint64_t *  bitString,
bsl::size_t  initialLength,
bsl::size_t  dstIndex,
bsl::size_t  numBits 
)
inlinestatic

Insert the specified numBits 1 bits into the specified bitString having the specified initialLength beginning at the specified dstIndex. Bits at or above dstIndex are shifted up by numBits index positions and the length of bitString is increased by numBits. The behavior is undefined unless dstIndex <= initialLength and bitString has a capacity of at least initialLength + numBits.

◆ insertRaw()

static void bdlb::BitStringUtil::insertRaw ( bsl::uint64_t *  bitString,
bsl::size_t  initialLength,
bsl::size_t  dstIndex,
bsl::size_t  numBits 
)
static

Insert the specified numBits into the specified bitString having the specified initialLength beginning at the specified dstIndex. Bits at or above dstIndex are shifted up by numBits index positions and the length of bitString is increased by numBits. The values of the inserted bits are undefined. The behavior is undefined unless dstIndex <= initialLength and bitString has a capacity of at least initialLength + numBits. Note that the inserted bits are not assigned any value.

◆ isAny0()

static bool bdlb::BitStringUtil::isAny0 ( const bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Return true if any of the specified numBits beginning at the specified index in the specified bitString are 0, and false otherwise. The behavior is undefined unless bitString has a length of at least index + numBits.

◆ isAny1()

static bool bdlb::BitStringUtil::isAny1 ( const bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Return true if any of the specified numBits beginning at the specified index in the specified bitString are 1, and false otherwise. The behavior is undefined unless bitString has a length of at least index + numBits.

◆ minusEqual()

static void bdlb::BitStringUtil::minusEqual ( bsl::uint64_t *  dstBitString,
bsl::size_t  dstIndex,
const bsl::uint64_t *  srcBitString,
bsl::size_t  srcIndex,
bsl::size_t  numBits 
)
static

Bitwise MINUS the specified numBits of the specified srcBitString starting at the specified srcIndex from the numBits of the specified dstBitString starting at the specified dstIndex, and write the result over the bits that were read from dstBitString. The behavior is undefined unless dstBitString has a length of at least dstIndex + numBits and srcBitString has a length of at least srcIndex + numBits. Note that the logical difference A - B is defined to be A & !B.

◆ num0()

bsl::size_t bdlb::BitStringUtil::num0 ( const bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
inlinestatic

Return the number of 0 bits in the specified numBits beginning at the specified index in the specified bitString. The behavior is undefined unless bitString has a length of at least index + numBits.

◆ num1()

static bsl::size_t bdlb::BitStringUtil::num1 ( const bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Return the number of 1 bits in the specified numBits beginning at the specified index in the specified bitString. The behavior is undefined unless bitString has a length of at least index + numBits.

◆ orEqual()

static void bdlb::BitStringUtil::orEqual ( bsl::uint64_t *  dstBitString,
bsl::size_t  dstIndex,
const bsl::uint64_t *  srcBitString,
bsl::size_t  srcIndex,
bsl::size_t  numBits 
)
static

Bitwise OR the specified numBits of the specified dstBitString starting at the specified dstIndex with the numBits of the specified srcBitString starting at the specified srcIndex, and write the result over the bits that were read from dstBitString. The behavior is undefined unless dstBitString has a length of at least dstIndex + numBits and srcBitString has a length of at least srcIndex + numBits.

◆ print()

static bsl::ostream & bdlb::BitStringUtil::print ( bsl::ostream &  stream,
const bsl::uint64_t *  bitString,
bsl::size_t  numBits,
int  level = 1,
int  spacesPerLevel = 4 
)
static

Format to the specified output stream the specified low-order numBits in the specified bitString in hexadecimal, and return a reference to stream. The highest order bits are printed first, in groups of 16 nibbles, 64 nibbles per line (in the case of multi-line output). Optionally specify level, the indentation level for each line output. Optionally specify spacesPerLevel, the number of spaces per indentation level. Each line is indented by the absolute value of level * spacesPerLevel. 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()

static void bdlb::BitStringUtil::remove ( bsl::uint64_t *  bitString,
bsl::size_t  length,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Remove the specified numBits from the specified bitString of the specified length beginning at the specified index. Bits above index + numBits are shifted down by numBits index positions and the length of bitString is reduced by numBits. The values of the vacated high-order bits are not modified. The behavior is undefined unless index + numBits <= length.

◆ removeAndFill0()

void bdlb::BitStringUtil::removeAndFill0 ( bsl::uint64_t *  bitString,
bsl::size_t  length,
bsl::size_t  index,
bsl::size_t  numBits 
)
inlinestatic

Remove the specified numBits from the specified bitString having the specified length beginning at the specified index. Bits above index + numBits are shifted down by numBits index positions and the last numBits of bitString are set to 0. The length of bitString is not changed. The behavior is undefined unless index + numBits <= length.

◆ removeAndFill1()

void bdlb::BitStringUtil::removeAndFill1 ( bsl::uint64_t *  bitString,
bsl::size_t  length,
bsl::size_t  index,
bsl::size_t  numBits 
)
inlinestatic

Remove the specified numBits from the specified bitString having the specified length beginning at the specified index. Bits above index + numBits are shifted down by numBits index positions and the last numBits of bitString are set to 1. The length of bitString is not changed. The behavior is undefined unless index + numBits <= length.

◆ swapRaw()

static void bdlb::BitStringUtil::swapRaw ( bsl::uint64_t *  bitString1,
bsl::size_t  index1,
bsl::uint64_t *  bitString2,
bsl::size_t  index2,
bsl::size_t  numBits 
)
static

Exchange the specified numBits beginning at the specified index1 in the specified bitString1 with the numBits beginning at the specified index2 in the specified bitString2. The behavior is undefined unless bitString1 has a length of at least index1 + numBits, bitString2 has a length of at least index2 + numBits, and there is no overlap between the swapped ranges of bits.

◆ toggle()

static void bdlb::BitStringUtil::toggle ( bsl::uint64_t *  bitString,
bsl::size_t  index,
bsl::size_t  numBits 
)
static

Invert the values of the specified numBits in the specified bitString beginning at the specified index. The behavior is undefined unless bitString has a length of at least index + numBits.

◆ xorEqual()

static void bdlb::BitStringUtil::xorEqual ( bsl::uint64_t *  dstBitString,
bsl::size_t  dstIndex,
const bsl::uint64_t *  srcBitString,
bsl::size_t  srcIndex,
bsl::size_t  numBits 
)
static

Bitwise XOR the specified numBits of the specified dstBitString starting at the specified dstIndex with the numBits of the specified srcBitString starting at the specified srcIndex, and write the result over the bits that were read from dstBitString. The behavior is undefined unless dstBitString has a length of at least dstIndex + numBits and srcBitString has a length of at least srcIndex + numBits.

Member Data Documentation

◆ k_INVALID_INDEX

const bsl::size_t bdlb::BitStringUtil::k_INVALID_INDEX = ~static_cast<bsl::size_t>(0)
static

The documentation for this struct was generated from the following file: