24#ifndef SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
25#define SQL_JOIN_OPTIMIZER_OVERFLOW_BITSET_H
88 assert((
m_bits >> 1) == bits);
136 static_assert(
alignof(
Ext) % 2 == 0,
"The lowest bit must be zero.");
161 template <
size_t N,
class Combine>
170 "OverflowBitset is intended to be as compact as a regular 64-bit set.");
171static_assert(std::is_trivially_copyable_v<OverflowBitset>,
172 "OverflowBitset is intended to be trivally copyable.");
202 assert(bit_num >= 0);
203 assert(
static_cast<size_t>(bit_num) <
capacity());
204 const unsigned bn = bit_num;
206 assert(bit_num < 63);
207 m_bits |= uint64_t{1} << (bn + 1);
209 m_ext->
m_bits[bn / 64] |= uint64_t{1} << (bn % 64);
214 assert(begin_bit_num >= 0);
215 assert(end_bit_num >= 0);
216 assert(begin_bit_num <= end_bit_num);
217 assert(
static_cast<size_t>(begin_bit_num) <=
capacity());
218 assert(
static_cast<size_t>(end_bit_num) <=
capacity());
220 m_bits &= ~BitsBetween(begin_bit_num + 1, end_bit_num + 1);
343template <
size_t N,
class Combine>
380 const Combine *combine)
411 for (
size_t i = 0; i <
N; ++i) {
421 std::array<uint64_t, N> bits;
422 for (
size_t i = 0; i <
N; ++i) {
434 std::array<uint64_t, N> bits;
435 for (
size_t i = 0; i <
N; ++i) {
439 uint64_t state = std::apply(
m_combine, bits);
442 std::array<const uint64_t *, N> ptrs;
443 for (
size_t i = 0; i <
N; ++i) {
448 const uint64_t *
end =
457 std::array<const uint64_t *, N> ptrs;
458 for (
size_t i = 0; i <
N; ++i) {
527 assert(bit_num >= 0);
528 assert(
static_cast<size_t>(bit_num) < x.
capacity());
529 const unsigned bn = bit_num;
581 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:176
void ClearBits(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.h:213
MutableOverflowBitset(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:191
friend int PopulationCount(const MutableOverflowBitset &x)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:588
friend bool IsBitSet(int bit_num, const MutableOverflowBitset &x)
Definition: overflow_bitset.h:537
void ClearBitsOverflow(int begin_bit_num, int end_bit_num)
Definition: overflow_bitset.cc:81
void SetBit(int bit_num)
Definition: overflow_bitset.h:201
friend bool IsSubset(OverflowBitset a, const MutableOverflowBitset &b)
Is 'a' a subset of 'b'?
Definition: overflow_bitset.h:542
MutableOverflowBitset & operator=(const MutableOverflowBitset &)=delete
friend bool Overlaps(OverflowBitset a, const MutableOverflowBitset &b)
Definition: overflow_bitset.h:501
MutableOverflowBitset(MEM_ROOT *mem_root, size_t capacity)
Definition: overflow_bitset.h:180
friend class OverflowBitset
Definition: overflow_bitset.h:251
friend bool IsEmpty(const MutableOverflowBitset &x)
Definition: overflow_bitset.h:574
MutableOverflowBitset(const MutableOverflowBitset &)=delete
void SetBitOverflow(int bit_num)
MutableOverflowBitset & operator=(MutableOverflowBitset &&other)
Definition: overflow_bitset.h:195
void ClearBit(int bit_num)
Definition: overflow_bitset.h:226
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:232
Definition: overflow_bitset.h:346
const Combine * m_combine
Definition: overflow_bitset.h:348
bool operator==(const iterator &other) const
Definition: overflow_bitset.h:389
value_type * pointer
Definition: overflow_bitset.h:369
iterator(uint64_t state, const Combine *combine)
Definition: overflow_bitset.h:373
value_type & reference
Definition: overflow_bitset.h:370
size_t operator*() const
Definition: overflow_bitset.h:393
uint64_t ReadAndCombine() const
Definition: overflow_bitset.h:420
size_t difference_type
Definition: overflow_bitset.h:367
iterator(const std::array< const uint64_t *, N > begin, const uint64_t *end, const Combine *combine)
Definition: overflow_bitset.h:379
size_t value_type
Definition: overflow_bitset.h:368
std::array< const uint64_t *, N > m_next
Definition: overflow_bitset.h:358
const uint64_t *const m_end
Definition: overflow_bitset.h:359
void SkipEmptyWords()
Definition: overflow_bitset.h:408
std::forward_iterator_tag iterator_category
Definition: overflow_bitset.h:366
int m_base
Definition: overflow_bitset.h:363
iterator & operator++()
Definition: overflow_bitset.h:394
uint64_t m_state
Definition: overflow_bitset.h:349
Definition: overflow_bitset.h:344
iterator end() const
Definition: overflow_bitset.h:453
iterator begin() const
Definition: overflow_bitset.h:432
const std::array< OverflowBitset, N > m_bitsets
Definition: overflow_bitset.h:468
const Combine m_combine
Definition: overflow_bitset.h:469
OverflowBitsetBitsIn(std::array< OverflowBitset, N > bitsets, Combine combine)
Definition: overflow_bitset.h:429
Definition: overflow_bitset.h:81
friend bool IsSubset(OverflowBitset a, OverflowBitset b)
Is 'a' a subset of 'b'?
Definition: overflow_bitset.h:516
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:278
friend int PopulationCountOverflow(OverflowBitset x)
Definition: overflow_bitset.cc:139
friend bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:485
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:579
MutableOverflowBitset Clone(MEM_ROOT *mem_root) const
Definition: overflow_bitset.h:266
size_t capacity() const
Definition: overflow_bitset.h:108
static constexpr int kInlineBits
Definition: overflow_bitset.h:142
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 MutableOverflowBitset AndOverflow(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.cc:55
uint64_t m_bits
Definition: overflow_bitset.h:139
OverflowBitset(const OverflowBitset &)=default
friend bool IsBitSetOverflow(int bit_num, OverflowBitset x)
friend bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:561
static MutableOverflowBitset And(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:292
OverflowBitset(uint32_t bits)
Definition: overflow_bitset.h:86
OverflowBitset(OverflowBitset &&)=default
Ext * m_ext
Definition: overflow_bitset.h:140
static MutableOverflowBitset Xor(MEM_ROOT *mem_root, OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:306
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:526
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:516
bool Overlaps(OverflowBitset a, OverflowBitset b)
Definition: overflow_bitset.h:485
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:479
int PopulationCount(OverflowBitset x)
Find the nuber of bits set in 'x'.
Definition: overflow_bitset.h:579
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:474
bool IsEmpty(OverflowBitset x)
Definition: overflow_bitset.h:561
bool IsBitSet(int bit_num, OverflowBitset x)
Definition: overflow_bitset.h:526
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:132
uint64_t m_bits[1]
Definition: overflow_bitset.h:134
size_t m_num_blocks
Definition: overflow_bitset.h:133