MySQL 9.1.0
Source Code Documentation
Bitset< B > Class Template Reference

A simple bitset wrapper class, which lets you access an existing range of bytes (not owned by it!) as if it was a std::bitset or std::vector<bool>. More...

#include <ut0bitset.h>

Public Member Functions

 Bitset ()
 Constructor. More...
 
 Bitset (B *data, size_t size_bytes)
 
Bitset bytes_subspan (size_t byte_offset, size_t bytes_count) const
 Returns a wrapper around [pos,pos+len) fragment of the buffer, where pos and len are measured in bytes. More...
 
Bitset bytes_subspan (size_t byte_offset) const
 Returns a wrapper around fragment of the buffer starting at pos, where pos is measured in bytes. More...
 
void copy_from (const byte *bitset) const
 Copy a bits from other buffer into this one. More...
 
void set (size_t pos, bool v=true) const
 Set the specified bit to the value 'bit'. More...
 
void set () const
 Set all bits to true. More...
 
void reset () const
 Set all bits to false. More...
 
void reset (size_t pos) const
 Sets the specified bit to false. More...
 
uint64_t to_uint64 () const
 Converts the content of the bitset to an uint64_t value, such that (value>>i&1) if and only if test(i). More...
 
size_t find_set (size_t start_pos) const
 Finds the smallest position which is set and is not smaller than start_pos. More...
 
bool test (size_t pos) const
 Test if the specified bit is set or not. More...
 
size_t size_bytes () const
 Get the size of current bitset in bytes. More...
 
B * data () const
 Get the bitset's bytes buffer. More...
 

Static Public Attributes

constexpr static size_t NOT_FOUND = std::numeric_limits<size_t>::max()
 Value used by find_set to indicate it could not find a bit set to 1. More...
 

Static Private Member Functions

static constexpr uint64_t to_uint64 (const byte *bytes)
 Converts 8 bytes to uint64_t value, such that (value>>i&1) equals the i-th bit, i.e. More...
 

Private Attributes

B * m_data
 The buffer containing the bitmap. More...
 
size_t m_size_bytes
 The length of the buffer containing the bitmap in bytes. More...
 

Detailed Description

template<typename B = byte>
class Bitset< B >

A simple bitset wrapper class, which lets you access an existing range of bytes (not owned by it!) as if it was a std::bitset or std::vector<bool>.

NOTE: Because it is a wrapper, its semantics are similar to std::span. For example const Bitset<> can still let someone modify the bits via set() or reset(). If you want to prevent someone from editing the buffer, you'd need Bitset<const byte>. For same reason, bitset1=bitset2 will just repoint bitset1 to the same range of bytes as bitset2 without copying any bits. If you want to copy the bits use bitset1.copy_from(bitset2.bitset()) instead.

Constructor & Destructor Documentation

◆ Bitset() [1/2]

template<typename B = byte>
Bitset< B >::Bitset ( )
inline

Constructor.

◆ Bitset() [2/2]

template<typename B = byte>
Bitset< B >::Bitset ( B *  data,
size_t  size_bytes 
)
inline

Member Function Documentation

◆ bytes_subspan() [1/2]

template<typename B = byte>
Bitset Bitset< B >::bytes_subspan ( size_t  byte_offset) const
inline

Returns a wrapper around fragment of the buffer starting at pos, where pos is measured in bytes.

Parameters
[in]byte_offsetposition of first byte of selected slice
Returns
Bitset wrapping the sub-array

◆ bytes_subspan() [2/2]

template<typename B = byte>
Bitset Bitset< B >::bytes_subspan ( size_t  byte_offset,
size_t  bytes_count 
) const
inline

Returns a wrapper around [pos,pos+len) fragment of the buffer, where pos and len are measured in bytes.

Parameters
[in]byte_offsetposition of first byte of selected slice
[in]bytes_countlength of the slice in bytes
Returns
Bitset wrapping the sub-array

◆ copy_from()

template<typename B = byte>
void Bitset< B >::copy_from ( const byte bitset) const
inline

Copy a bits from other buffer into this one.

Parameters
[in]bitsetbyte array to bits copy from

◆ data()

template<typename B = byte>
B * Bitset< B >::data ( ) const
inline

Get the bitset's bytes buffer.

Returns
current bitset

◆ find_set()

template<typename B = byte>
size_t Bitset< B >::find_set ( size_t  start_pos) const
inline

Finds the smallest position which is set and is not smaller than start_pos.

Parameters
[in]start_posThe position from which to start the search.
Returns
Smallest pos for which test(pos)==true and start_pos<=pos. In case there's no such pos, returns NOT_FOUND

◆ reset() [1/2]

template<typename B = byte>
void Bitset< B >::reset ( void  ) const
inline

Set all bits to false.

◆ reset() [2/2]

template<typename B = byte>
void Bitset< B >::reset ( size_t  pos) const
inline

Sets the specified bit to false.

Parameters
[in]posspecified bit

◆ set() [1/2]

template<typename B = byte>
void Bitset< B >::set ( ) const
inline

Set all bits to true.

◆ set() [2/2]

template<typename B = byte>
void Bitset< B >::set ( size_t  pos,
bool  v = true 
) const
inline

Set the specified bit to the value 'bit'.

Parameters
[in]posspecified bit
[in]vtrue or false

◆ size_bytes()

template<typename B = byte>
size_t Bitset< B >::size_bytes ( ) const
inline

Get the size of current bitset in bytes.

Returns
the size of the bitset

◆ test()

template<typename B = byte>
bool Bitset< B >::test ( size_t  pos) const
inline

Test if the specified bit is set or not.

Parameters
[in]posthe specified bit
Returns
True if this bit is set, otherwise false

◆ to_uint64() [1/2]

template<typename B = byte>
uint64_t Bitset< B >::to_uint64 ( ) const
inline

Converts the content of the bitset to an uint64_t value, such that (value>>i&1) if and only if test(i).

The m_size must be at most 8 bytes.

Returns
content of the bitset as uint64_t mapping i-th bit to 2^i

◆ to_uint64() [2/2]

template<typename B = byte>
static constexpr uint64_t Bitset< B >::to_uint64 ( const byte bytes)
inlinestaticconstexprprivate

Converts 8 bytes to uint64_t value, such that (value>>i&1) equals the i-th bit, i.e.

(bytes[i/8]>>i%8 & 1). For example, the returned value equals bytes[0] modulo 256.

Parameters
[in]bytesthe bytes to convert
Returns
uint64_t created by concatenating the bytes in the right order: on Little-Endian it's an identity, on Big-Endian it's std::byteswap.

Member Data Documentation

◆ m_data

template<typename B = byte>
B* Bitset< B >::m_data
private

The buffer containing the bitmap.

First bit is the lowest bit of the first byte of this buffer.

◆ m_size_bytes

template<typename B = byte>
size_t Bitset< B >::m_size_bytes
private

The length of the buffer containing the bitmap in bytes.

Number of bits is 8 times larger than this

◆ NOT_FOUND

template<typename B = byte>
constexpr static size_t Bitset< B >::NOT_FOUND = std::numeric_limits<size_t>::max()
staticconstexpr

Value used by find_set to indicate it could not find a bit set to 1.

It is guaranteed to be larger than the size of the vector.


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