24#ifndef SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
25#define SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
85 assert((
m_bits >> 1) == bits);
134 static_assert(
alignof(
Ext) % 2 == 0,
"The lowest bit must be zero.");
159 template <
size_t N,
class Combine>
165 "OverflowBitset is intended to be as compact as a regular 64-bit set.");
195 assert(bit_num >= 0);
196 assert(
static_cast<size_t>(bit_num) <
capacity());
197 const unsigned bn = bit_num;
199 assert(bit_num < 63);
200 m_bits |= uint64_t{1} << (bn + 1);
202 m_ext->
m_bits[bn / 64] |= uint64_t{1} << (bn % 64);
207 assert(begin_bit_num >= 0);
208 assert(end_bit_num >= 0);
209 assert(begin_bit_num <= end_bit_num);
210 assert(
static_cast<size_t>(begin_bit_num) <=
capacity());
211 assert(
static_cast<size_t>(end_bit_num) <=
capacity());
213 m_bits &= ~BitsBetween(begin_bit_num + 1, end_bit_num + 1);
336template <
size_t N,
class Combine>
370 const Combine *combine)
378 for (
size_t i = 0; i <
N; ++i) {
401 for (
size_t i = 0; i <
N; ++i) {
415 std::array<uint64_t, N> bits;
416 for (
size_t i = 0; i <
N; ++i) {
420 uint64_t state = std::apply(
m_combine, bits);
423 std::array<const uint64_t *, N> ptrs;
424 for (
size_t i = 0; i <
N; ++i) {
429 const uint64_t *
end =
438 std::array<const uint64_t *, N> ptrs;
439 for (
size_t i = 0; i <
N; ++i) {
450 const std::array<const uint64_t *, N> &ptrs,
const Combine *combine) {
451 std::array<uint64_t, N> bits;
452 for (
size_t i = 0; i <
N; ++i) {
455 return std::apply(*combine, bits);
470 uint64_t
operator()(uint64_t x, uint64_t y)
const {
return x & y; }
520 assert(bit_num >= 0);
521 assert(
static_cast<size_t>(bit_num) < x.
capacity());
522 const unsigned bn = bit_num;
570 return std::popcount(x.
m_bits) - 1;
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
size_t FindLowestBitSet(uint64_t x)
Definition: bit_utils.h:66
Definition: overflow_bitset.h:169
void ClearBits(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.h:206
MutableOverflowBitset(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:184
friend int PopulationCount(const MutableOverflowBitset &x)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:577
friend bool IsBitSet(int bit_num, const MutableOverflowBitset &x)
Definition: overflow_bitset.h:530
void ClearBitsOverflow(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.cc:81
void SetBit(int bit_num)
Definition: overflow_bitset.h:194
friend bool IsSubset(OverflowBitset a, const MutableOverflowBitset &b)
Definition: overflow_bitset.h:534
MutableOverflowBitset & operator=(const MutableOverflowBitset &)=delete
friend bool Overlaps(OverflowBitset a, const MutableOverflowBitset &b)
Definition: overflow_bitset.h:495
MutableOverflowBitset(MEM_ROOT *mem_root, size_t capacity)
Definition: overflow_bitset.h:173
friend class OverflowBitset
Definition: overflow_bitset.h:244
friend bool IsEmpty(const MutableOverflowBitset &x)
Definition: overflow_bitset.h:564
MutableOverflowBitset(const MutableOverflowBitset &)=delete
void SetBitOverflow(int bit_num)
MutableOverflowBitset & operator=(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:188
void ClearBit(int bit_num)
Definition: overflow_bitset.h:219
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:225
Definition: overflow_bitset.h:339
const Combine * m_combine
Definition: overflow_bitset.h:341
bool operator==(const iterator &other) const
Definition: overflow_bitset.h:385
value_type * pointer
Definition: overflow_bitset.h:359
iterator(uint64_t state, const Combine *combine)
Definition: overflow_bitset.h:363
value_type & reference
Definition: overflow_bitset.h:360
size_t operator*() const
Definition: overflow_bitset.h:393
size_t difference_type
Definition: overflow_bitset.h:357
iterator(const std::array< const uint64_t *, N > begin, const uint64_t *end, const Combine *combine)
Definition: overflow_bitset.h:369
size_t value_type
Definition: overflow_bitset.h:358
bool operator!=(const iterator &other) const
Definition: overflow_bitset.h:389
std::array< const uint64_t *, N > m_next
Definition: overflow_bitset.h:351
const uint64_t *const m_end
Definition: overflow_bitset.h:352
std::forward_iterator_tag iterator_category
Definition: overflow_bitset.h:356
int m_base
Definition: overflow_bitset.h:353
iterator & operator++()
Definition: overflow_bitset.h:394
uint64_t m_state
Definition: overflow_bitset.h:342
Definition: overflow_bitset.h:337
iterator end() const
Definition: overflow_bitset.h:434
static uint64_t ReadAndCombine(const std::array< const uint64_t *, N > &ptrs, const Combine *combine)
Definition: overflow_bitset.h:449
iterator begin() const
Definition: overflow_bitset.h:413
const std::array< OverflowBitset, N > m_bitsets
Definition: overflow_bitset.h:458
const Combine m_combine
Definition: overflow_bitset.h:459
OverflowBitsetBitsIn(std::array< OverflowBitset, N > bitsets, Combine combine)
Definition: overflow_bitset.h:410
Definition: overflow_bitset.h:78
friend bool IsSubset(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:509
bool IsContainedIn(const MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:116
static MutableOverflowBitset Or(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:271
friend int PopulationCountOverflow(OverflowBitset x)
Definition: overflow_bitset.cc:139
friend bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:479
OverflowBitset()
Definition: overflow_bitset.h:81
static MutableOverflowBitset OrOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:42
friend bool IsSubsetOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:127
friend int PopulationCount(OverflowBitset x)
Definition: overflow_bitset.h:568
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:259
size_t capacity() const
Definition: overflow_bitset.h:106
static constexpr int kInlineBits
Definition: overflow_bitset.h:140
bool empty()
Definition: overflow_bitset.h:104
OverflowBitset & operator=(const OverflowBitset &)=default
bool is_inline() const
Definition: overflow_bitset.h:103
static MutableOverflowBitset XorOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:68
friend bool OverlapsOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:115
static MutableOverflowBitset AndOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:55
uint64_t m_bits
Definition: overflow_bitset.h:137
OverflowBitset(const OverflowBitset &)=default
friend bool IsBitSetOverflow(int bit_num, OverflowBitset x)
friend bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:551
static MutableOverflowBitset And(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:285
OverflowBitset(uint32_t bits)
Definition: overflow_bitset.h:83
OverflowBitset(OverflowBitset &&)=default
Ext * m_ext
Definition: overflow_bitset.h:138
static MutableOverflowBitset Xor(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:299
void InitOverflow(MEM_ROOT *mem_root, size_t capacity)
Definition: overflow_bitset.cc:33
friend bool IsBitSet(int bit_num, OverflowBitset x)
Definition: overflow_bitset.h:519
void Clear()
Definition: overflow_bitset.h:91
OverflowBitset & operator=(OverflowBitset &&)=default
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
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:139
bool IsSubsetOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:127
bool IsSubset(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:509
bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:479
auto BitsSetInBoth(OverflowBitset bitset_a, OverflowBitset bitset_b)
Definition: overflow_bitset.h:472
int PopulationCount(OverflowBitset x)
Definition: overflow_bitset.h:568
bool OverlapsOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:115
auto BitsSetIn(OverflowBitset bitset)
Definition: overflow_bitset.h:465
bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:551
bool IsBitSet(int bit_num, OverflowBitset x)
Definition: overflow_bitset.h:519
Definition: overflow_bitset.h:469
uint64_t operator()(uint64_t x, uint64_t y) const
Definition: overflow_bitset.h:470
Definition: overflow_bitset.h:462
uint64_t operator()(uint64_t x) const
Definition: overflow_bitset.h:463
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:130
uint64_t m_bits[1]
Definition: overflow_bitset.h:132
size_t m_num_blocks
Definition: overflow_bitset.h:131