![]() |
MySQL 8.0.41
Source Code Documentation
|
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... | |
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.
Returns a wrapper around fragment of the buffer starting at pos, where pos is measured in bytes.
[in] | byte_offset | position of first byte of selected slice |
|
inline |
Returns a wrapper around [pos,pos+len) fragment of the buffer, where pos and len are measured in bytes.
[in] | byte_offset | position of first byte of selected slice |
[in] | bytes_count | length of the slice in bytes |
Copy a bits from other buffer into this one.
[in] | bitset | byte array to bits copy from |
|
inline |
Get the bitset's bytes buffer.
|
inline |
Finds the smallest position which is set and is not smaller than start_pos.
[in] | start_pos | The position from which to start the search. |
|
inline |
Set all bits to false.
|
inline |
Sets the specified bit to false.
[in] | pos | specified bit |
|
inline |
Set all bits to true.
|
inline |
Set the specified bit to the value 'bit'.
[in] | pos | specified bit |
[in] | v | true or false |
|
inline |
Get the size of current bitset in bytes.
|
inline |
Test if the specified bit is set or not.
[in] | pos | the specified bit |
|
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.
|
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.
[in] | bytes | the bytes to convert |
|
private |
The buffer containing the bitmap.
First bit is the lowest bit of the first byte of this buffer.
|
private |
The length of the buffer containing the bitmap in bytes.
Number of bits is 8 times larger than this
|
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.