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...
|
| 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...
|
|
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.
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] | bytes | the 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.