54template <
typename B =
byte>
56 static_assert(std::is_same_v<std::decay_t<B>,
byte>,
57 "Bitset<B> requires B to be a byte or const byte");
91 void set(
size_t pos,
bool v =
true)
const {
93 m_data[pos / 8] &= ~(0x1 << (pos & 0x7));
94 m_data[pos / 8] |= (
static_cast<byte>(v) << (pos & 0x7));
119 constexpr static size_t NOT_FOUND = std::numeric_limits<size_t>::max();
144 const uint64_t earlier = (uint64_t{1} << start_pos) - 1;
145 const uint64_t unseen =
all & ~earlier;
147 return std::countr_zero(unseen);
151 const auto start_addr =
reinterpret_cast<uintptr_t
>(
m_data);
152 const size_t start_word_byte_idx =
153 ut::div_ceil(start_addr, uintptr_t{8}) * 8 - start_addr;
154 const auto translate_result = [&start_pos,
this](
size_t offset) {
156 return found ==
NOT_FOUND ? found : found + offset;
158 if (start_word_byte_idx == 0) {
160 auto *words =
reinterpret_cast<const uint64_t *
>(
m_data);
161 size_t word_idx = start_pos / 64;
163 if (word_idx < full_words_count) {
164 const uint64_t earlier = (uint64_t{1} << start_pos % 64) - 1;
167 return word_idx * 64 + std::countr_zero(unseen);
171 while (word_idx < full_words_count) {
172 if (words[word_idx]) {
173 return word_idx * 64 +
178 start_pos = full_words_count * 64;
180 return translate_result(full_words_count * 64);
183 if (start_pos < start_word_byte_idx * 8) {
189 start_pos = start_word_byte_idx * 8;
191 return translate_result(start_word_byte_idx * 8);
199 return ((
m_data[pos / 8] >> (pos & 0x7)) & 0x1);
217 static constexpr uint64_t
to_uint64(
const byte *bytes) {
221 return ((uint64_t)(bytes[7]) << 7 * 8) | ((uint64_t)(bytes[6]) << 6 * 8) |
222 ((uint64_t)(bytes[5]) << 5 * 8) | ((uint64_t)(bytes[4]) << 4 * 8) |
223 ((uint64_t)(bytes[3]) << 3 * 8) | ((uint64_t)(bytes[2]) << 2 * 8) |
224 ((uint64_t)(bytes[1]) << 1 * 8) | ((uint64_t)(bytes[0]) << 0 * 8);
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
A simple bitset wrapper class, which lets you access an existing range of bytes (not owned by it!...
Definition: ut0bitset.h:55
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...
Definition: ut0bitset.h:111
size_t size_bytes() const
Get the size of current bitset in bytes.
Definition: ut0bitset.h:204
B * m_data
The buffer containing the bitmap.
Definition: ut0bitset.h:229
void reset() const
Set all bits to false.
Definition: ut0bitset.h:101
B * data() const
Get the bitset's bytes buffer.
Definition: ut0bitset.h:208
bool test(size_t pos) const
Test if the specified bit is set or not.
Definition: ut0bitset.h:197
Bitset(B *data, size_t size_bytes)
Definition: ut0bitset.h:62
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.
Definition: ut0bitset.h:77
void reset(size_t pos) const
Sets the specified bit to false.
Definition: ut0bitset.h:105
size_t m_size_bytes
The length of the buffer containing the bitmap in bytes.
Definition: ut0bitset.h:233
void copy_from(const byte *bitset) const
Copy a bits from other buffer into this one.
Definition: ut0bitset.h:84
Bitset()
Constructor.
Definition: ut0bitset.h:61
void set() const
Set all bits to true.
Definition: ut0bitset.h:98
constexpr static size_t NOT_FOUND
Value used by find_set to indicate it could not find a bit set to 1.
Definition: ut0bitset.h:119
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 byte...
Definition: ut0bitset.h:69
size_t find_set(size_t start_pos) const
Finds the smallest position which is set and is not smaller than start_pos.
Definition: ut0bitset.h:125
void set(size_t pos, bool v=true) const
Set the specified bit to the value 'bit'.
Definition: ut0bitset.h:91
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....
Definition: ut0bitset.h:217
constexpr T div_ceil(T numerator, T denominator)
Computes the result of division rounded towards positive infinity.
Definition: ut0math.h:49
Version control for database, common definitions, and include files.
Debug utilities for Innobase.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93