24#ifndef SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
25#define SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
84 assert((
m_bits >> 1) == bits);
133 static_assert(
alignof(
Ext) % 2 == 0,
"The lowest bit must be zero.");
158 template <
size_t N,
class Combine>
164 "OverflowBitset is intended to be as compact as a regular 64-bit set.");
194 assert(bit_num >= 0);
195 assert(
static_cast<size_t>(bit_num) <
capacity());
196 const unsigned bn = bit_num;
198 assert(bit_num < 63);
199 m_bits |= uint64_t{1} << (bn + 1);
201 m_ext->
m_bits[bn / 64] |= uint64_t{1} << (bn % 64);
206 assert(begin_bit_num >= 0);
207 assert(end_bit_num >= 0);
208 assert(begin_bit_num <= end_bit_num);
209 assert(
static_cast<size_t>(begin_bit_num) <=
capacity());
210 assert(
static_cast<size_t>(end_bit_num) <=
capacity());
212 m_bits &= ~BitsBetween(begin_bit_num + 1, end_bit_num + 1);
335template <
size_t N,
class Combine>
363 const Combine *combine)
371 for (
size_t i = 0; i <
N; ++i) {
394 for (
size_t i = 0; i <
N; ++i) {
408 std::array<uint64_t, N> bits;
409 for (
size_t i = 0; i <
N; ++i) {
413 uint64_t state = std::apply(
m_combine, bits);
416 std::array<const uint64_t *, N> ptrs;
417 for (
size_t i = 0; i <
N; ++i) {
422 const uint64_t *
end =
431 std::array<const uint64_t *, N> ptrs;
432 for (
size_t i = 0; i <
N; ++i) {
443 const std::array<const uint64_t *, N> &ptrs,
const Combine *combine) {
444 std::array<uint64_t, N> bits;
445 for (
size_t i = 0; i <
N; ++i) {
448 return std::apply(*combine, bits);
463 uint64_t
operator()(uint64_t x, uint64_t y)
const {
return x & y; }
513 assert(bit_num >= 0);
514 assert(
static_cast<size_t>(bit_num) < x.
capacity());
515 const unsigned bn = bit_num;
size_t FindLowestBitSet(uint64_t x)
Definition: bit_utils.h:71
Definition: overflow_bitset.h:168
void ClearBits(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.h:205
MutableOverflowBitset(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:183
friend int PopulationCount(const MutableOverflowBitset &x)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:570
friend bool IsBitSet(int bit_num, const MutableOverflowBitset &x)
Definition: overflow_bitset.h:523
void ClearBitsOverflow(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.cc:80
void SetBit(int bit_num)
Definition: overflow_bitset.h:193
friend bool IsSubset(OverflowBitset a, const MutableOverflowBitset &b)
Definition: overflow_bitset.h:527
MutableOverflowBitset & operator=(const MutableOverflowBitset &)=delete
friend bool Overlaps(OverflowBitset a, const MutableOverflowBitset &b)
Definition: overflow_bitset.h:488
MutableOverflowBitset(MEM_ROOT *mem_root, size_t capacity)
Definition: overflow_bitset.h:172
friend class OverflowBitset
Definition: overflow_bitset.h:243
friend bool IsEmpty(const MutableOverflowBitset &x)
Definition: overflow_bitset.h:557
MutableOverflowBitset(const MutableOverflowBitset &)=delete
void SetBitOverflow(int bit_num)
MutableOverflowBitset & operator=(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:187
void ClearBit(int bit_num)
Definition: overflow_bitset.h:218
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:224
Definition: overflow_bitset.h:338
const Combine * m_combine
Definition: overflow_bitset.h:340
bool operator==(const iterator &other) const
Definition: overflow_bitset.h:378
iterator(uint64_t state, const Combine *combine)
Definition: overflow_bitset.h:356
size_t operator*() const
Definition: overflow_bitset.h:386
iterator(const std::array< const uint64_t *, N > begin, const uint64_t *end, const Combine *combine)
Definition: overflow_bitset.h:362
bool operator!=(const iterator &other) const
Definition: overflow_bitset.h:382
std::array< const uint64_t *, N > m_next
Definition: overflow_bitset.h:350
const uint64_t *const m_end
Definition: overflow_bitset.h:351
int m_base
Definition: overflow_bitset.h:352
iterator & operator++()
Definition: overflow_bitset.h:387
uint64_t m_state
Definition: overflow_bitset.h:341
Definition: overflow_bitset.h:336
iterator end() const
Definition: overflow_bitset.h:427
static uint64_t ReadAndCombine(const std::array< const uint64_t *, N > &ptrs, const Combine *combine)
Definition: overflow_bitset.h:442
iterator begin() const
Definition: overflow_bitset.h:406
const std::array< OverflowBitset, N > m_bitsets
Definition: overflow_bitset.h:451
const Combine m_combine
Definition: overflow_bitset.h:452
OverflowBitsetBitsIn(std::array< OverflowBitset, N > bitsets, Combine combine)
Definition: overflow_bitset.h:403
Definition: overflow_bitset.h:77
friend bool IsSubset(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:502
bool IsContainedIn(const MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:115
static MutableOverflowBitset Or(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:270
friend int PopulationCountOverflow(OverflowBitset x)
Definition: overflow_bitset.cc:138
friend bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:472
OverflowBitset()
Definition: overflow_bitset.h:80
static MutableOverflowBitset OrOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:41
friend bool IsSubsetOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:126
friend int PopulationCount(OverflowBitset x)
Definition: overflow_bitset.h:561
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:258
size_t capacity() const
Definition: overflow_bitset.h:105
static constexpr int kInlineBits
Definition: overflow_bitset.h:139
bool empty()
Definition: overflow_bitset.h:103
OverflowBitset & operator=(const OverflowBitset &)=default
bool is_inline() const
Definition: overflow_bitset.h:102
static MutableOverflowBitset XorOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:67
friend bool OverlapsOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:114
static MutableOverflowBitset AndOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:54
uint64_t m_bits
Definition: overflow_bitset.h:136
OverflowBitset(const OverflowBitset &)=default
friend bool IsBitSetOverflow(int bit_num, OverflowBitset x)
friend bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:544
static MutableOverflowBitset And(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:284
OverflowBitset(uint32_t bits)
Definition: overflow_bitset.h:82
OverflowBitset(OverflowBitset &&)=default
Ext * m_ext
Definition: overflow_bitset.h:137
static MutableOverflowBitset Xor(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:298
void InitOverflow(MEM_ROOT *mem_root, size_t capacity)
Definition: overflow_bitset.cc:32
friend bool IsBitSet(int bit_num, OverflowBitset x)
Definition: overflow_bitset.h:512
void Clear()
Definition: overflow_bitset.h:90
OverflowBitset & operator=(OverflowBitset &&)=default
static MEM_ROOT mem_root
Definition: client_plugin.cc:110
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::atomic< Type > N
Definition: ut0counter.h:225
Definition: gcs_xcom_synode.h:64
int PopulationCountOverflow(OverflowBitset x)
Definition: overflow_bitset.cc:138
bool IsSubsetOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:126
bool IsSubset(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:502
bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:472
auto BitsSetInBoth(OverflowBitset bitset_a, OverflowBitset bitset_b)
Definition: overflow_bitset.h:465
int PopulationCount(OverflowBitset x)
Definition: overflow_bitset.h:561
bool OverlapsOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:114
auto BitsSetIn(OverflowBitset bitset)
Definition: overflow_bitset.h:458
bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:544
bool IsBitSet(int bit_num, OverflowBitset x)
Definition: overflow_bitset.h:512
Definition: overflow_bitset.h:462
uint64_t operator()(uint64_t x, uint64_t y) const
Definition: overflow_bitset.h:463
Definition: overflow_bitset.h:455
uint64_t operator()(uint64_t x) const
Definition: overflow_bitset.h:456
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
bool Contains(void *ptr) const
Returns whether this MEM_ROOT contains the given pointer, ie., whether it was given back from Alloc(n...
Definition: my_alloc.h:353
Definition: overflow_bitset.h:129
uint64_t m_bits[1]
Definition: overflow_bitset.h:131
size_t m_num_blocks
Definition: overflow_bitset.h:130