24#ifndef SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
25#define SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
88 assert((
m_bits >> 1) == bits);
139 static_assert(
alignof(
Ext) % 2 == 0,
"The lowest bit must be zero.");
164 template <
size_t N,
class Combine>
173 "OverflowBitset is intended to be as compact as a regular 64-bit set.");
174static_assert(std::is_trivially_copyable_v<OverflowBitset>,
175 "OverflowBitset is intended to be trivally copyable.");
205 assert(bit_num >= 0);
206 assert(
static_cast<size_t>(bit_num) <
capacity());
207 const unsigned bn = bit_num;
209 assert(bit_num < 63);
210 m_bits |= uint64_t{1} << (bn + 1);
212 m_ext->
m_bits[bn / 64] |= uint64_t{1} << (bn % 64);
217 assert(begin_bit_num >= 0);
218 assert(end_bit_num >= 0);
219 assert(begin_bit_num <= end_bit_num);
220 assert(
static_cast<size_t>(begin_bit_num) <=
capacity());
221 assert(
static_cast<size_t>(end_bit_num) <=
capacity());
223 m_bits &= ~BitsBetween(begin_bit_num + 1, end_bit_num + 1);
351template <
size_t N,
class Combine>
388 const Combine *combine)
419 for (
size_t i = 0; i <
N; ++i) {
429 std::array<uint64_t, N> bits;
430 for (
size_t i = 0; i <
N; ++i) {
442 std::array<uint64_t, N> bits;
443 for (
size_t i = 0; i <
N; ++i) {
447 uint64_t state = std::apply(
m_combine, bits);
450 std::array<const uint64_t *, N> ptrs;
451 for (
size_t i = 0; i <
N; ++i) {
456 const uint64_t *
end =
465 std::array<const uint64_t *, N> ptrs;
466 for (
size_t i = 0; i <
N; ++i) {
535 assert(bit_num >= 0);
536 assert(
static_cast<size_t>(bit_num) < x.
capacity());
537 const unsigned bn = bit_num;
589 return std::popcount(x.
m_bits) - 1;
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
size_t FindLowestBitSet(uint64_t x)
Definition: bit_utils.h:66
Definition: overflow_bitset.h:179
void ClearBits(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.h:216
MutableOverflowBitset(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:194
friend int PopulationCount(const MutableOverflowBitset &x)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:596
friend bool IsBitSet(int bit_num, const MutableOverflowBitset &x)
Definition: overflow_bitset.h:545
void ClearBitsOverflow(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.cc:81
void SetBit(int bit_num)
Definition: overflow_bitset.h:204
friend bool IsSubset(OverflowBitset a, const MutableOverflowBitset &b)
Is 'a' a subset of 'b'?
Definition: overflow_bitset.h:550
MutableOverflowBitset & operator=(const MutableOverflowBitset &)=delete
friend bool Overlaps(OverflowBitset a, const MutableOverflowBitset &b)
Definition: overflow_bitset.h:509
MutableOverflowBitset(MEM_ROOT *mem_root, size_t capacity)
Definition: overflow_bitset.h:183
friend class OverflowBitset
Definition: overflow_bitset.h:254
friend bool IsEmpty(const MutableOverflowBitset &x)
Definition: overflow_bitset.h:582
MutableOverflowBitset(const MutableOverflowBitset &)=delete
void SetBitOverflow(int bit_num)
MutableOverflowBitset & operator=(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:198
void ClearBit(int bit_num)
Definition: overflow_bitset.h:229
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:235
Definition: overflow_bitset.h:354
const Combine * m_combine
Definition: overflow_bitset.h:356
bool operator==(const iterator &other) const
Definition: overflow_bitset.h:397
value_type * pointer
Definition: overflow_bitset.h:377
iterator(uint64_t state, const Combine *combine)
Definition: overflow_bitset.h:381
value_type & reference
Definition: overflow_bitset.h:378
size_t operator*() const
Definition: overflow_bitset.h:401
uint64_t ReadAndCombine() const
Definition: overflow_bitset.h:428
size_t difference_type
Definition: overflow_bitset.h:375
iterator(const std::array< const uint64_t *, N > begin, const uint64_t *end, const Combine *combine)
Definition: overflow_bitset.h:387
size_t value_type
Definition: overflow_bitset.h:376
std::array< const uint64_t *, N > m_next
Definition: overflow_bitset.h:366
const uint64_t *const m_end
Definition: overflow_bitset.h:367
void SkipEmptyWords()
Definition: overflow_bitset.h:416
std::forward_iterator_tag iterator_category
Definition: overflow_bitset.h:374
int m_base
Definition: overflow_bitset.h:371
iterator & operator++()
Definition: overflow_bitset.h:402
uint64_t m_state
Definition: overflow_bitset.h:357
Definition: overflow_bitset.h:352
iterator end() const
Definition: overflow_bitset.h:461
iterator begin() const
Definition: overflow_bitset.h:440
const std::array< OverflowBitset, N > m_bitsets
Definition: overflow_bitset.h:476
const Combine m_combine
Definition: overflow_bitset.h:477
OverflowBitsetBitsIn(std::array< OverflowBitset, N > bitsets, Combine combine)
Definition: overflow_bitset.h:437
Definition: overflow_bitset.h:81
friend bool IsSubset(OverflowBitset a, OverflowBitset b)
Is 'a' a subset of 'b'?
Definition: overflow_bitset.h:524
bool IsContainedIn(const MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:118
static MutableOverflowBitset Or(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:281
friend int PopulationCountOverflow(OverflowBitset x)
Definition: overflow_bitset.cc:139
friend bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:493
OverflowBitset()
Definition: overflow_bitset.h:84
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)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:587
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:269
size_t capacity() const
Definition: overflow_bitset.h:108
static constexpr int kInlineBits
Definition: overflow_bitset.h:145
OverflowBitset & operator=(const OverflowBitset &)=default
bool is_inline() const
Definition: overflow_bitset.h:106
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 OverflowBitset EmptySet(MEM_ROOT *mem_root, size_t capacity)
Make a bitset that has no bits set, with the given capacity.
Definition: overflow_bitset.h:323
static MutableOverflowBitset AndOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:55
uint64_t m_bits
Definition: overflow_bitset.h:142
OverflowBitset(const OverflowBitset &)=default
friend bool IsBitSetOverflow(int bit_num, OverflowBitset x)
friend bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:569
static MutableOverflowBitset And(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:295
OverflowBitset(uint32_t bits)
Definition: overflow_bitset.h:86
OverflowBitset(OverflowBitset &&)=default
Ext * m_ext
Definition: overflow_bitset.h:143
static MutableOverflowBitset Xor(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:309
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:534
void Clear()
Definition: overflow_bitset.h:94
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)
Is 'a' a subset of 'b'?
Definition: overflow_bitset.h:524
bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:493
auto BitsSetInBoth(OverflowBitset bitset_a, OverflowBitset bitset_b)
Get a container-like interface for the bits set in both of the two bitsets.
Definition: overflow_bitset.h:487
int PopulationCount(OverflowBitset x)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:587
bool OverlapsOverflow(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:115
auto BitsSetIn(OverflowBitset bitset)
Get a container-like interface of an OverflowBitset, to allow passing it to algorithms that work on i...
Definition: overflow_bitset.h:482
bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:569
bool IsBitSet(int bit_num, OverflowBitset x)
Definition: overflow_bitset.h:534
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:135
uint64_t m_bits[1]
Definition: overflow_bitset.h:137
size_t m_num_blocks
Definition: overflow_bitset.h:136