/root/bitcoin/src/util/bitset.h
Line | Count | Source |
1 | | // Copyright (c) The Bitcoin Core developers |
2 | | // Distributed under the MIT software license, see the accompanying |
3 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | | |
5 | | #ifndef BITCOIN_UTIL_BITSET_H |
6 | | #define BITCOIN_UTIL_BITSET_H |
7 | | |
8 | | #include <util/check.h> |
9 | | #include <util/overflow.h> |
10 | | |
11 | | #include <array> |
12 | | #include <bit> |
13 | | #include <cstdint> |
14 | | #include <limits> |
15 | | #include <type_traits> |
16 | | |
17 | | /* This file provides data types similar to std::bitset, but adds the following functionality: |
18 | | * |
19 | | * - Efficient iteration over all set bits (compatible with range-based for loops). |
20 | | * - Efficient search for the first and last set bit (First() and Last()). |
21 | | * - Efficient set subtraction: (a - b) implements "a and not b". |
22 | | * - Efficient non-strict subset/superset testing: IsSubsetOf() and IsSupersetOf(). |
23 | | * - Efficient set overlap testing: a.Overlaps(b) |
24 | | * - Efficient construction of set containing 0..N-1 (S::Fill). |
25 | | * - Efficient construction of a single set (S::Singleton). |
26 | | * - Construction from initializer lists. |
27 | | * |
28 | | * Other differences: |
29 | | * - BitSet<N> is a bitset that supports at least N elements, but may support more (Size() reports |
30 | | * the actual number). Because the actual number is unpredictable, there are no operations that |
31 | | * affect all positions (like std::bitset's operator~, flip(), or all()). |
32 | | * - Various other unimplemented features. |
33 | | */ |
34 | | |
35 | | namespace bitset_detail { |
36 | | |
37 | | /** Count the number of bits set in an unsigned integer type. */ |
38 | | template<typename I> |
39 | | unsigned inline constexpr PopCount(I v) |
40 | 0 | { |
41 | 0 | static_assert(std::is_integral_v<I> && std::is_unsigned_v<I> && std::numeric_limits<I>::radix == 2); |
42 | 0 | constexpr auto BITS = std::numeric_limits<I>::digits; |
43 | | // Algorithms from https://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation. |
44 | | // These seem to be faster than std::popcount when compiling for non-SSE4 on x86_64. |
45 | 0 | if constexpr (BITS <= 32) { |
46 | 0 | v -= (v >> 1) & 0x55555555; |
47 | 0 | v = (v & 0x33333333) + ((v >> 2) & 0x33333333); |
48 | 0 | v = (v + (v >> 4)) & 0x0f0f0f0f; |
49 | 0 | if constexpr (BITS > 8) v += v >> 8; |
50 | 0 | if constexpr (BITS > 16) v += v >> 16; |
51 | 0 | return v & 0x3f; |
52 | 0 | } else { |
53 | 0 | static_assert(BITS <= 64); |
54 | 0 | v -= (v >> 1) & 0x5555555555555555; |
55 | 0 | v = (v & 0x3333333333333333) + ((v >> 2) & 0x3333333333333333); |
56 | 0 | v = (v + (v >> 4)) & 0x0f0f0f0f0f0f0f0f; |
57 | 0 | return (v * uint64_t{0x0101010101010101}) >> 56; |
58 | 0 | } |
59 | 0 | } Unexecuted instantiation: unsigned int bitset_detail::PopCount<unsigned short>(unsigned short) Unexecuted instantiation: unsigned int bitset_detail::PopCount<unsigned int>(unsigned int) Unexecuted instantiation: unsigned int bitset_detail::PopCount<unsigned long>(unsigned long) |
60 | | |
61 | | /** A bitset implementation backed by a single integer of type I. */ |
62 | | template<typename I> |
63 | | class IntBitSet |
64 | | { |
65 | | // Only binary, unsigned, integer, types allowed. |
66 | | static_assert(std::is_integral_v<I> && std::is_unsigned_v<I> && std::numeric_limits<I>::radix == 2); |
67 | | /** The maximum number of bits this bitset supports. */ |
68 | | static constexpr unsigned MAX_SIZE = std::numeric_limits<I>::digits; |
69 | | /** Integer whose bits represent this bitset. */ |
70 | | I m_val; |
71 | | /** Internal constructor with a given integer as contents. */ |
72 | 0 | IntBitSet(I val) noexcept : m_val{val} {}Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::IntBitSet(unsigned short) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::IntBitSet(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::IntBitSet(unsigned long) |
73 | | /** Dummy type to return using end(). Only used for comparing with Iterator. */ |
74 | | class IteratorEnd |
75 | | { |
76 | | friend class IntBitSet; |
77 | | constexpr IteratorEnd() = default; |
78 | | public: |
79 | | constexpr IteratorEnd(const IteratorEnd&) = default; |
80 | | }; |
81 | | /** Iterator type returned by begin(), which efficiently iterates all 1 positions. */ |
82 | | class Iterator |
83 | | { |
84 | | friend class IntBitSet; |
85 | | I m_val; /**< The original integer's remaining bits. */ |
86 | | unsigned m_pos; /** Last reported 1 position (if m_pos != 0). */ |
87 | 0 | constexpr Iterator(I val) noexcept : m_val(val), m_pos(0) |
88 | 0 | { |
89 | 0 | if (m_val != 0) m_pos = std::countr_zero(m_val); |
90 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Iterator::Iterator(unsigned short) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Iterator::Iterator(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Iterator::Iterator(unsigned long) |
91 | | public: |
92 | | /** Do not allow external code to construct an Iterator. */ |
93 | | Iterator() = delete; |
94 | | // Copying is allowed. |
95 | | constexpr Iterator(const Iterator&) noexcept = default; |
96 | | constexpr Iterator& operator=(const Iterator&) noexcept = default; |
97 | | /** Test whether we are done (can only compare with IteratorEnd). */ |
98 | | constexpr friend bool operator==(const Iterator& a, const IteratorEnd&) noexcept |
99 | 0 | { |
100 | 0 | return a.m_val == 0; |
101 | 0 | } Unexecuted instantiation: bitset_detail::operator==(bitset_detail::IntBitSet<unsigned short>::Iterator const&, bitset_detail::IntBitSet<unsigned short>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::IntBitSet<unsigned int>::Iterator const&, bitset_detail::IntBitSet<unsigned int>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::IntBitSet<unsigned long>::Iterator const&, bitset_detail::IntBitSet<unsigned long>::IteratorEnd const&) |
102 | | /** Progress to the next 1 bit (only if != IteratorEnd). */ |
103 | | constexpr Iterator& operator++() noexcept |
104 | 0 | { |
105 | 0 | Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
106 | 0 | m_val &= m_val - I{1U}; |
107 | 0 | if (m_val != 0) m_pos = std::countr_zero(m_val); |
108 | 0 | return *this; |
109 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Iterator::operator++() Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Iterator::operator++() Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Iterator::operator++() |
110 | | /** Get the current bit position (only if != IteratorEnd). */ |
111 | | constexpr unsigned operator*() const noexcept |
112 | 0 | { |
113 | 0 | Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
114 | 0 | return m_pos; |
115 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Iterator::operator*() const |
116 | | }; |
117 | | |
118 | | public: |
119 | | /** Construct an all-zero bitset. */ |
120 | 0 | constexpr IntBitSet() noexcept : m_val{0} {}Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::IntBitSet() Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::IntBitSet() Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::IntBitSet() |
121 | | /** Copy construct a bitset. */ |
122 | | constexpr IntBitSet(const IntBitSet&) noexcept = default; |
123 | | /** Construct from a list of values. */ |
124 | 0 | constexpr IntBitSet(std::initializer_list<unsigned> ilist) noexcept : m_val(0) |
125 | 0 | { |
126 | 0 | for (auto pos : ilist) Set(pos); |
127 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::IntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::IntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::IntBitSet(std::initializer_list<unsigned int>) |
128 | | /** Copy assign a bitset. */ |
129 | | constexpr IntBitSet& operator=(const IntBitSet&) noexcept = default; |
130 | | /** Assign from a list of positions (which will be made true, all others false). */ |
131 | | constexpr IntBitSet& operator=(std::initializer_list<unsigned> ilist) noexcept |
132 | 0 | { |
133 | 0 | m_val = 0; |
134 | 0 | for (auto pos : ilist) Set(pos); |
135 | 0 | return *this; |
136 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::operator=(std::initializer_list<unsigned int>) |
137 | | /** Construct a bitset with the singleton i. */ |
138 | | static constexpr IntBitSet Singleton(unsigned i) noexcept |
139 | 0 | { |
140 | 0 | Assume(i < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(i < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(i < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
141 | 0 | return IntBitSet(I(1U) << i); |
142 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Singleton(unsigned int) |
143 | | /** Construct a bitset with bits 0..count-1 (inclusive) set to 1. */ |
144 | | static constexpr IntBitSet Fill(unsigned count) noexcept |
145 | 0 | { |
146 | 0 | IntBitSet ret; |
147 | 0 | Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
148 | 0 | if (count) ret.m_val = I(~I{0}) >> (MAX_SIZE - count); |
149 | 0 | return ret; |
150 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Fill(unsigned int) |
151 | | /** Set a bit to 1. */ |
152 | | constexpr void Set(unsigned pos) noexcept |
153 | 0 | { |
154 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
155 | 0 | m_val |= I{1U} << pos; |
156 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Set(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Set(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Set(unsigned int) |
157 | | /** Set a bit to the specified value. */ |
158 | | constexpr void Set(unsigned pos, bool val) noexcept |
159 | 0 | { |
160 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
161 | 0 | m_val = (m_val & ~I(I{1U} << pos)) | (I(val) << pos); |
162 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Set(unsigned int, bool) |
163 | | /** Set a bit to 0. */ |
164 | | constexpr void Reset(unsigned pos) noexcept |
165 | 0 | { |
166 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
167 | 0 | m_val &= ~I(I{1U} << pos); |
168 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Reset(unsigned int) |
169 | | /** Retrieve a bit at the given position. */ |
170 | | constexpr bool operator[](unsigned pos) const noexcept |
171 | 0 | { |
172 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
173 | 0 | return (m_val >> pos) & 1U; |
174 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::operator[](unsigned int) const |
175 | | /** Compute the number of 1 bits in the bitset. */ |
176 | 0 | constexpr unsigned Count() const noexcept { return PopCount(m_val); }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Count() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Count() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Count() const |
177 | | /** Return the number of bits that this object holds. */ |
178 | 0 | static constexpr unsigned Size() noexcept { return MAX_SIZE; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Size() Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Size() Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Size() |
179 | | /** Check if all bits are 0. */ |
180 | 0 | constexpr bool None() const noexcept { return m_val == 0; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::None() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::None() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::None() const |
181 | | /** Check if any bits are 1. */ |
182 | 0 | constexpr bool Any() const noexcept { return !None(); }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Any() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Any() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Any() const |
183 | | /** Return an object that iterates over all 1 bits (++ and * only allowed when != end()). */ |
184 | 0 | constexpr Iterator begin() const noexcept { return Iterator(m_val); }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::begin() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::begin() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::begin() const |
185 | | /** Return a dummy object to compare Iterators with. */ |
186 | 0 | constexpr IteratorEnd end() const noexcept { return IteratorEnd(); }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::end() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::end() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::end() const |
187 | | /** Find the first element (requires Any()). */ |
188 | | constexpr unsigned First() const noexcept |
189 | 0 | { |
190 | 0 | Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
191 | 0 | return std::countr_zero(m_val); |
192 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::First() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::First() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::First() const |
193 | | /** Find the last element (requires Any()). */ |
194 | | constexpr unsigned Last() const noexcept |
195 | 0 | { |
196 | 0 | Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_val != 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
197 | 0 | return std::bit_width(m_val) - 1; |
198 | 0 | } Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Last() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Last() const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Last() const |
199 | | /** Set this object's bits to be the binary AND between respective bits from this and a. */ |
200 | 0 | constexpr IntBitSet& operator|=(const IntBitSet& a) noexcept { m_val |= a.m_val; return *this; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::operator|=(bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::operator|=(bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::operator|=(bitset_detail::IntBitSet<unsigned long> const&) |
201 | | /** Set this object's bits to be the binary OR between respective bits from this and a. */ |
202 | 0 | constexpr IntBitSet& operator&=(const IntBitSet& a) noexcept { m_val &= a.m_val; return *this; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::operator&=(bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::operator&=(bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::operator&=(bitset_detail::IntBitSet<unsigned long> const&) |
203 | | /** Set this object's bits to be the binary AND NOT between respective bits from this and a. */ |
204 | 0 | constexpr IntBitSet& operator-=(const IntBitSet& a) noexcept { m_val &= ~a.m_val; return *this; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::operator-=(bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::operator-=(bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::operator-=(bitset_detail::IntBitSet<unsigned long> const&) |
205 | | /** Set this object's bits to be the binary XOR between respective bits from this as a. */ |
206 | 0 | constexpr IntBitSet& operator^=(const IntBitSet& a) noexcept { m_val ^= a.m_val; return *this; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::operator^=(bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::operator^=(bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::operator^=(bitset_detail::IntBitSet<unsigned long> const&) |
207 | | /** Check if the intersection between two sets is non-empty. */ |
208 | 0 | constexpr bool Overlaps(const IntBitSet& a) const noexcept { return m_val & a.m_val; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::Overlaps(bitset_detail::IntBitSet<unsigned short> const&) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::Overlaps(bitset_detail::IntBitSet<unsigned int> const&) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::Overlaps(bitset_detail::IntBitSet<unsigned long> const&) const |
209 | | /** Return an object with the binary AND between respective bits from a and b. */ |
210 | 0 | friend constexpr IntBitSet operator&(const IntBitSet& a, const IntBitSet& b) noexcept { return I(a.m_val & b.m_val); }Unexecuted instantiation: bitset_detail::operator&(bitset_detail::IntBitSet<unsigned short> const&, bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::IntBitSet<unsigned int> const&, bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::IntBitSet<unsigned long> const&, bitset_detail::IntBitSet<unsigned long> const&) |
211 | | /** Return an object with the binary OR between respective bits from a and b. */ |
212 | 0 | friend constexpr IntBitSet operator|(const IntBitSet& a, const IntBitSet& b) noexcept { return I(a.m_val | b.m_val); }Unexecuted instantiation: bitset_detail::operator|(bitset_detail::IntBitSet<unsigned short> const&, bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::IntBitSet<unsigned int> const&, bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::IntBitSet<unsigned long> const&, bitset_detail::IntBitSet<unsigned long> const&) |
213 | | /** Return an object with the binary AND NOT between respective bits from a and b. */ |
214 | 0 | friend constexpr IntBitSet operator-(const IntBitSet& a, const IntBitSet& b) noexcept { return I(a.m_val & ~b.m_val); }Unexecuted instantiation: bitset_detail::operator-(bitset_detail::IntBitSet<unsigned short> const&, bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::IntBitSet<unsigned int> const&, bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::IntBitSet<unsigned long> const&, bitset_detail::IntBitSet<unsigned long> const&) |
215 | | /** Return an object with the binary XOR between respective bits from a and b. */ |
216 | 0 | friend constexpr IntBitSet operator^(const IntBitSet& a, const IntBitSet& b) noexcept { return I(a.m_val ^ b.m_val); }Unexecuted instantiation: bitset_detail::operator^(bitset_detail::IntBitSet<unsigned short> const&, bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::IntBitSet<unsigned int> const&, bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::IntBitSet<unsigned long> const&, bitset_detail::IntBitSet<unsigned long> const&) |
217 | | /** Check if bitset a and bitset b are identical. */ |
218 | 0 | friend constexpr bool operator==(const IntBitSet& a, const IntBitSet& b) noexcept = default; Unexecuted instantiation: bitset_detail::operator==(bitset_detail::IntBitSet<unsigned short> const&, bitset_detail::IntBitSet<unsigned short> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::IntBitSet<unsigned int> const&, bitset_detail::IntBitSet<unsigned int> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::IntBitSet<unsigned long> const&, bitset_detail::IntBitSet<unsigned long> const&) |
219 | | /** Check if bitset a is a superset of bitset b (= every 1 bit in b is also in a). */ |
220 | 0 | constexpr bool IsSupersetOf(const IntBitSet& a) const noexcept { return (a.m_val & ~m_val) == 0; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::IsSupersetOf(bitset_detail::IntBitSet<unsigned short> const&) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::IsSupersetOf(bitset_detail::IntBitSet<unsigned int> const&) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::IsSupersetOf(bitset_detail::IntBitSet<unsigned long> const&) const |
221 | | /** Check if bitset a is a subset of bitset b (= every 1 bit in a is also in b). */ |
222 | 0 | constexpr bool IsSubsetOf(const IntBitSet& a) const noexcept { return (m_val & ~a.m_val) == 0; }Unexecuted instantiation: bitset_detail::IntBitSet<unsigned short>::IsSubsetOf(bitset_detail::IntBitSet<unsigned short> const&) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned int>::IsSubsetOf(bitset_detail::IntBitSet<unsigned int> const&) const Unexecuted instantiation: bitset_detail::IntBitSet<unsigned long>::IsSubsetOf(bitset_detail::IntBitSet<unsigned long> const&) const |
223 | | /** Swap two bitsets. */ |
224 | 0 | friend constexpr void swap(IntBitSet& a, IntBitSet& b) noexcept { std::swap(a.m_val, b.m_val); }Unexecuted instantiation: bitset_detail::swap(bitset_detail::IntBitSet<unsigned short>&, bitset_detail::IntBitSet<unsigned short>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::IntBitSet<unsigned int>&, bitset_detail::IntBitSet<unsigned int>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::IntBitSet<unsigned long>&, bitset_detail::IntBitSet<unsigned long>&) |
225 | | }; |
226 | | |
227 | | /** A bitset implementation backed by N integers of type I. */ |
228 | | template<typename I, unsigned N> |
229 | | class MultiIntBitSet |
230 | | { |
231 | | // Only binary, unsigned, integer, types allowed. |
232 | | static_assert(std::is_integral_v<I> && std::is_unsigned_v<I> && std::numeric_limits<I>::radix == 2); |
233 | | // Cannot be empty. |
234 | | static_assert(N > 0); |
235 | | /** The number of bits per integer. */ |
236 | | static constexpr unsigned LIMB_BITS = std::numeric_limits<I>::digits; |
237 | | /** Number of elements this set type supports. */ |
238 | | static constexpr unsigned MAX_SIZE = LIMB_BITS * N; |
239 | | // No overflow allowed here. |
240 | | static_assert(MAX_SIZE / LIMB_BITS == N); |
241 | | /** Array whose member integers store the bits of the set. */ |
242 | | std::array<I, N> m_val; |
243 | | /** Dummy type to return using end(). Only used for comparing with Iterator. */ |
244 | | class IteratorEnd |
245 | | { |
246 | | friend class MultiIntBitSet; |
247 | | constexpr IteratorEnd() = default; |
248 | | public: |
249 | | constexpr IteratorEnd(const IteratorEnd&) = default; |
250 | | }; |
251 | | /** Iterator type returned by begin(), which efficiently iterates all 1 positions. */ |
252 | | class Iterator |
253 | | { |
254 | | friend class MultiIntBitSet; |
255 | | const std::array<I, N>* m_ptr; /**< Pointer to array to fetch bits from. */ |
256 | | I m_val; /**< The remaining bits of (*m_ptr)[m_idx]. */ |
257 | | unsigned m_pos; /**< The last reported position. */ |
258 | | unsigned m_idx; /**< The index in *m_ptr currently being iterated over. */ |
259 | 0 | constexpr Iterator(const std::array<I, N>& ref) noexcept : m_ptr(&ref), m_idx(0) |
260 | 0 | { |
261 | 0 | do { |
262 | 0 | m_val = (*m_ptr)[m_idx]; |
263 | 0 | if (m_val) { |
264 | 0 | m_pos = std::countr_zero(m_val) + m_idx * LIMB_BITS; |
265 | 0 | break; |
266 | 0 | } |
267 | 0 | ++m_idx; |
268 | 0 | } while(m_idx < N); |
269 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Iterator::Iterator(std::array<unsigned short, 1ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Iterator::Iterator(std::array<unsigned short, 2ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Iterator::Iterator(std::array<unsigned short, 3ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Iterator::Iterator(std::array<unsigned long, 1ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Iterator::Iterator(std::array<unsigned int, 2ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Iterator::Iterator(std::array<unsigned short, 4ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Iterator::Iterator(std::array<unsigned int, 3ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Iterator::Iterator(std::array<unsigned long, 2ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Iterator::Iterator(std::array<unsigned int, 4ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Iterator::Iterator(std::array<unsigned long, 3ul> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Iterator::Iterator(std::array<unsigned long, 4ul> const&) |
270 | | |
271 | | public: |
272 | | /** Do not allow external code to construct an Iterator. */ |
273 | | Iterator() = delete; |
274 | | // Copying is allowed. |
275 | | constexpr Iterator(const Iterator&) noexcept = default; |
276 | | constexpr Iterator& operator=(const Iterator&) noexcept = default; |
277 | | /** Test whether we are done (can only compare with IteratorEnd). */ |
278 | | friend constexpr bool operator==(const Iterator& a, const IteratorEnd&) noexcept |
279 | 0 | { |
280 | 0 | return a.m_idx == N; |
281 | 0 | } Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 1u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned short, 1u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 2u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned short, 2u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 3u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned short, 3u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 1u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned long, 1u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned int, 2u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned int, 2u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 4u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned short, 4u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned int, 3u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned int, 3u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 2u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned long, 2u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned int, 4u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned int, 4u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 3u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned long, 3u>::IteratorEnd const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 4u>::Iterator const&, bitset_detail::MultiIntBitSet<unsigned long, 4u>::IteratorEnd const&) |
282 | | /** Progress to the next 1 bit (only if != IteratorEnd). */ |
283 | | constexpr Iterator& operator++() noexcept |
284 | 0 | { |
285 | 0 | Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
286 | 0 | m_val &= m_val - I{1U}; |
287 | 0 | if (m_val == 0) { |
288 | 0 | while (true) { |
289 | 0 | ++m_idx; |
290 | 0 | if (m_idx == N) break; |
291 | 0 | m_val = (*m_ptr)[m_idx]; |
292 | 0 | if (m_val) { |
293 | 0 | m_pos = std::countr_zero(m_val) + m_idx * LIMB_BITS; |
294 | 0 | break; |
295 | 0 | } |
296 | 0 | } |
297 | 0 | } else { |
298 | 0 | m_pos = std::countr_zero(m_val) + m_idx * LIMB_BITS; |
299 | 0 | } |
300 | 0 | return *this; |
301 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Iterator::operator++() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Iterator::operator++() |
302 | | /** Get the current bit position (only if != IteratorEnd). */ |
303 | | constexpr unsigned operator*() const noexcept |
304 | 0 | { |
305 | 0 | Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(m_idx < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
306 | 0 | return m_pos; |
307 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Iterator::operator*() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Iterator::operator*() const |
308 | | }; |
309 | | |
310 | | public: |
311 | | /** Construct an all-zero bitset. */ |
312 | 0 | constexpr MultiIntBitSet() noexcept : m_val{} {}Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::MultiIntBitSet() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::MultiIntBitSet() |
313 | | /** Copy construct a bitset. */ |
314 | | constexpr MultiIntBitSet(const MultiIntBitSet&) noexcept = default; |
315 | | /** Copy assign a bitset. */ |
316 | | constexpr MultiIntBitSet& operator=(const MultiIntBitSet&) noexcept = default; |
317 | | /** Set a bit to 1. */ |
318 | | void constexpr Set(unsigned pos) noexcept |
319 | 0 | { |
320 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
321 | 0 | m_val[pos / LIMB_BITS] |= I{1U} << (pos % LIMB_BITS); |
322 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Set(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Set(unsigned int) |
323 | | /** Set a bit to the specified value. */ |
324 | | void constexpr Set(unsigned pos, bool val) noexcept |
325 | 0 | { |
326 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
327 | 0 | m_val[pos / LIMB_BITS] = (m_val[pos / LIMB_BITS] & ~I(I{1U} << (pos % LIMB_BITS))) | |
328 | 0 | (I{val} << (pos % LIMB_BITS)); |
329 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Set(unsigned int, bool) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Set(unsigned int, bool) |
330 | | /** Construct a bitset from a list of values. */ |
331 | 0 | constexpr MultiIntBitSet(std::initializer_list<unsigned> ilist) noexcept : m_val{} |
332 | 0 | { |
333 | 0 | for (auto pos : ilist) Set(pos); |
334 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::MultiIntBitSet(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::MultiIntBitSet(std::initializer_list<unsigned int>) |
335 | | /** Set a bitset to a list of values. */ |
336 | | constexpr MultiIntBitSet& operator=(std::initializer_list<unsigned> ilist) noexcept |
337 | 0 | { |
338 | 0 | m_val.fill(0); |
339 | 0 | for (auto pos : ilist) Set(pos); |
340 | 0 | return *this; |
341 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::operator=(std::initializer_list<unsigned int>) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::operator=(std::initializer_list<unsigned int>) |
342 | | /** Set a bit to 0. */ |
343 | | void constexpr Reset(unsigned pos) noexcept |
344 | 0 | { |
345 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
346 | 0 | m_val[pos / LIMB_BITS] &= ~I(I{1U} << (pos % LIMB_BITS)); |
347 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Reset(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Reset(unsigned int) |
348 | | /** Retrieve a bit at the given position. */ |
349 | | bool constexpr operator[](unsigned pos) const noexcept |
350 | 0 | { |
351 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
352 | 0 | return (m_val[pos / LIMB_BITS] >> (pos % LIMB_BITS)) & 1U; |
353 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::operator[](unsigned int) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::operator[](unsigned int) const |
354 | | /** Construct a bitset with the singleton pos. */ |
355 | | static constexpr MultiIntBitSet Singleton(unsigned pos) noexcept |
356 | 0 | { |
357 | 0 | Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(pos < MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
358 | 0 | MultiIntBitSet ret; |
359 | 0 | ret.m_val[pos / LIMB_BITS] = I{1U} << (pos % LIMB_BITS); |
360 | 0 | return ret; |
361 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Singleton(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Singleton(unsigned int) |
362 | | /** Construct a bitset with bits 0..count-1 (inclusive) set to 1. */ |
363 | | static constexpr MultiIntBitSet Fill(unsigned count) noexcept |
364 | 0 | { |
365 | 0 | Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(count <= MAX_SIZE); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
366 | 0 | MultiIntBitSet ret; |
367 | 0 | if (count) { |
368 | 0 | unsigned i = 0; |
369 | 0 | while (count > LIMB_BITS) { |
370 | 0 | ret.m_val[i++] = I(~I{0}); |
371 | 0 | count -= LIMB_BITS; |
372 | 0 | } |
373 | 0 | ret.m_val[i] = I(~I{0}) >> (LIMB_BITS - count); |
374 | 0 | } |
375 | 0 | return ret; |
376 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Fill(unsigned int) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Fill(unsigned int) |
377 | | /** Return the number of bits that this object holds. */ |
378 | 0 | static constexpr unsigned Size() noexcept { return MAX_SIZE; }Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Size() Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Size() |
379 | | /** Compute the number of 1 bits in the bitset. */ |
380 | | unsigned constexpr Count() const noexcept |
381 | 0 | { |
382 | 0 | unsigned ret{0}; |
383 | 0 | for (I v : m_val) ret += PopCount(v); |
384 | 0 | return ret; |
385 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Count() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Count() const |
386 | | /** Check if all bits are 0. */ |
387 | | bool constexpr None() const noexcept |
388 | 0 | { |
389 | 0 | for (auto v : m_val) { |
390 | 0 | if (v != 0) return false; |
391 | 0 | } |
392 | 0 | return true; |
393 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::None() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::None() const |
394 | | /** Check if any bits are 1. */ |
395 | 0 | bool constexpr Any() const noexcept { return !None(); }Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Any() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Any() const |
396 | | /** Return an object that iterates over all 1 bits (++ and * only allowed when != end()). */ |
397 | 0 | Iterator constexpr begin() const noexcept { return Iterator(m_val); }Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::begin() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::begin() const |
398 | | /** Return a dummy object to compare Iterators with. */ |
399 | 0 | IteratorEnd constexpr end() const noexcept { return IteratorEnd(); }Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::end() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::end() const |
400 | | /** Find the first element (requires Any()). */ |
401 | | unsigned constexpr First() const noexcept |
402 | 0 | { |
403 | 0 | unsigned p = 0; |
404 | 0 | while (m_val[p] == 0) { |
405 | 0 | ++p; |
406 | 0 | Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p < N); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
407 | 0 | } |
408 | 0 | return std::countr_zero(m_val[p]) + p * LIMB_BITS; |
409 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::First() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::First() const |
410 | | /** Find the last element (requires Any()). */ |
411 | | unsigned constexpr Last() const noexcept |
412 | 0 | { |
413 | 0 | unsigned p = N - 1; |
414 | 0 | while (m_val[p] == 0) { |
415 | 0 | Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
| Assume(p > 0); Line | Count | Source | 125 | 0 | #define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val) |
|
416 | 0 | --p; |
417 | 0 | } |
418 | 0 | return std::bit_width(m_val[p]) - 1 + p * LIMB_BITS; |
419 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Last() const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Last() const |
420 | | /** Set this object's bits to be the binary OR between respective bits from this and a. */ |
421 | | constexpr MultiIntBitSet& operator|=(const MultiIntBitSet& a) noexcept |
422 | 0 | { |
423 | 0 | for (unsigned i = 0; i < N; ++i) { |
424 | 0 | m_val[i] |= a.m_val[i]; |
425 | 0 | } |
426 | 0 | return *this; |
427 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::operator|=(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::operator|=(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::operator|=(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::operator|=(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::operator|=(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::operator|=(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::operator|=(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::operator|=(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::operator|=(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::operator|=(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::operator|=(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
428 | | /** Set this object's bits to be the binary AND between respective bits from this and a. */ |
429 | | constexpr MultiIntBitSet& operator&=(const MultiIntBitSet& a) noexcept |
430 | 0 | { |
431 | 0 | for (unsigned i = 0; i < N; ++i) { |
432 | 0 | m_val[i] &= a.m_val[i]; |
433 | 0 | } |
434 | 0 | return *this; |
435 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::operator&=(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::operator&=(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::operator&=(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::operator&=(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::operator&=(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::operator&=(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::operator&=(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::operator&=(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::operator&=(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::operator&=(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::operator&=(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
436 | | /** Set this object's bits to be the binary AND NOT between respective bits from this and a. */ |
437 | | constexpr MultiIntBitSet& operator-=(const MultiIntBitSet& a) noexcept |
438 | 0 | { |
439 | 0 | for (unsigned i = 0; i < N; ++i) { |
440 | 0 | m_val[i] &= ~a.m_val[i]; |
441 | 0 | } |
442 | 0 | return *this; |
443 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::operator-=(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::operator-=(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::operator-=(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::operator-=(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::operator-=(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::operator-=(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::operator-=(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::operator-=(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::operator-=(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::operator-=(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::operator-=(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
444 | | /** Set this object's bits to be the binary XOR between respective bits from this and a. */ |
445 | | constexpr MultiIntBitSet& operator^=(const MultiIntBitSet& a) noexcept |
446 | 0 | { |
447 | 0 | for (unsigned i = 0; i < N; ++i) { |
448 | 0 | m_val[i] ^= a.m_val[i]; |
449 | 0 | } |
450 | 0 | return *this; |
451 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::operator^=(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::operator^=(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::operator^=(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::operator^=(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::operator^=(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::operator^=(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::operator^=(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::operator^=(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::operator^=(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::operator^=(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::operator^=(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
452 | | /** Check whether the intersection between two sets is non-empty. */ |
453 | | constexpr bool Overlaps(const MultiIntBitSet& a) const noexcept |
454 | 0 | { |
455 | 0 | for (unsigned i = 0; i < N; ++i) { |
456 | 0 | if (m_val[i] & a.m_val[i]) return true; |
457 | 0 | } |
458 | 0 | return false; |
459 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::Overlaps(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) const |
460 | | /** Return an object with the binary AND between respective bits from a and b. */ |
461 | | friend constexpr MultiIntBitSet operator&(const MultiIntBitSet& a, const MultiIntBitSet& b) noexcept |
462 | 0 | { |
463 | 0 | MultiIntBitSet r; |
464 | 0 | for (unsigned i = 0; i < N; ++i) { |
465 | 0 | r.m_val[i] = a.m_val[i] & b.m_val[i]; |
466 | 0 | } |
467 | 0 | return r; |
468 | 0 | } Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&, bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&, bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&, bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&, bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&, bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&, bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&, bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&, bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&, bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&, bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::operator&(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&, bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
469 | | /** Return an object with the binary OR between respective bits from a and b. */ |
470 | | friend constexpr MultiIntBitSet operator|(const MultiIntBitSet& a, const MultiIntBitSet& b) noexcept |
471 | 0 | { |
472 | 0 | MultiIntBitSet r; |
473 | 0 | for (unsigned i = 0; i < N; ++i) { |
474 | 0 | r.m_val[i] = a.m_val[i] | b.m_val[i]; |
475 | 0 | } |
476 | 0 | return r; |
477 | 0 | } Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&, bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&, bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&, bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&, bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&, bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&, bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&, bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&, bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&, bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&, bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::operator|(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&, bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
478 | | /** Return an object with the binary AND NOT between respective bits from a and b. */ |
479 | | friend constexpr MultiIntBitSet operator-(const MultiIntBitSet& a, const MultiIntBitSet& b) noexcept |
480 | 0 | { |
481 | 0 | MultiIntBitSet r; |
482 | 0 | for (unsigned i = 0; i < N; ++i) { |
483 | 0 | r.m_val[i] = a.m_val[i] & ~b.m_val[i]; |
484 | 0 | } |
485 | 0 | return r; |
486 | 0 | } Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&, bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&, bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&, bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&, bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&, bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&, bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&, bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&, bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&, bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&, bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::operator-(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&, bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
487 | | /** Return an object with the binary XOR between respective bits from a and b. */ |
488 | | friend constexpr MultiIntBitSet operator^(const MultiIntBitSet& a, const MultiIntBitSet& b) noexcept |
489 | 0 | { |
490 | 0 | MultiIntBitSet r; |
491 | 0 | for (unsigned i = 0; i < N; ++i) { |
492 | 0 | r.m_val[i] = a.m_val[i] ^ b.m_val[i]; |
493 | 0 | } |
494 | 0 | return r; |
495 | 0 | } Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&, bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&, bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&, bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&, bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&, bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&, bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&, bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&, bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&, bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&, bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::operator^(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&, bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
496 | | /** Check if bitset a is a superset of bitset b (= every 1 bit in b is also in a). */ |
497 | | constexpr bool IsSupersetOf(const MultiIntBitSet& a) const noexcept |
498 | 0 | { |
499 | 0 | for (unsigned i = 0; i < N; ++i) { |
500 | 0 | if (a.m_val[i] & ~m_val[i]) return false; |
501 | 0 | } |
502 | 0 | return true; |
503 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::IsSupersetOf(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) const |
504 | | /** Check if bitset a is a subset of bitset b (= every 1 bit in a is also in b). */ |
505 | | constexpr bool IsSubsetOf(const MultiIntBitSet& a) const noexcept |
506 | 0 | { |
507 | 0 | for (unsigned i = 0; i < N; ++i) { |
508 | 0 | if (m_val[i] & ~a.m_val[i]) return false; |
509 | 0 | } |
510 | 0 | return true; |
511 | 0 | } Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 1u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 2u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 3u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 1u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 2u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned short, 4u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 3u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 2u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned int, 4u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 3u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) const Unexecuted instantiation: bitset_detail::MultiIntBitSet<unsigned long, 4u>::IsSubsetOf(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) const |
512 | | /** Check if bitset a and bitset b are identical. */ |
513 | 0 | friend constexpr bool operator==(const MultiIntBitSet& a, const MultiIntBitSet& b) noexcept = default; Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 1u> const&, bitset_detail::MultiIntBitSet<unsigned short, 1u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 2u> const&, bitset_detail::MultiIntBitSet<unsigned short, 2u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 3u> const&, bitset_detail::MultiIntBitSet<unsigned short, 3u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 1u> const&, bitset_detail::MultiIntBitSet<unsigned long, 1u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned int, 2u> const&, bitset_detail::MultiIntBitSet<unsigned int, 2u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned short, 4u> const&, bitset_detail::MultiIntBitSet<unsigned short, 4u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned int, 3u> const&, bitset_detail::MultiIntBitSet<unsigned int, 3u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 2u> const&, bitset_detail::MultiIntBitSet<unsigned long, 2u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned int, 4u> const&, bitset_detail::MultiIntBitSet<unsigned int, 4u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 3u> const&, bitset_detail::MultiIntBitSet<unsigned long, 3u> const&) Unexecuted instantiation: bitset_detail::operator==(bitset_detail::MultiIntBitSet<unsigned long, 4u> const&, bitset_detail::MultiIntBitSet<unsigned long, 4u> const&) |
514 | | /** Swap two bitsets. */ |
515 | 0 | friend constexpr void swap(MultiIntBitSet& a, MultiIntBitSet& b) noexcept { std::swap(a.m_val, b.m_val); }Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned short, 1u>&, bitset_detail::MultiIntBitSet<unsigned short, 1u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned short, 2u>&, bitset_detail::MultiIntBitSet<unsigned short, 2u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned short, 3u>&, bitset_detail::MultiIntBitSet<unsigned short, 3u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned long, 1u>&, bitset_detail::MultiIntBitSet<unsigned long, 1u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned int, 2u>&, bitset_detail::MultiIntBitSet<unsigned int, 2u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned short, 4u>&, bitset_detail::MultiIntBitSet<unsigned short, 4u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned int, 3u>&, bitset_detail::MultiIntBitSet<unsigned int, 3u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned long, 2u>&, bitset_detail::MultiIntBitSet<unsigned long, 2u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned int, 4u>&, bitset_detail::MultiIntBitSet<unsigned int, 4u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned long, 3u>&, bitset_detail::MultiIntBitSet<unsigned long, 3u>&) Unexecuted instantiation: bitset_detail::swap(bitset_detail::MultiIntBitSet<unsigned long, 4u>&, bitset_detail::MultiIntBitSet<unsigned long, 4u>&) |
516 | | }; |
517 | | |
518 | | } // namespace bitset_detail |
519 | | |
520 | | // BitSet dispatches to IntBitSet or MultiIntBitSet as appropriate for the requested minimum number |
521 | | // of bits. Use IntBitSet up to 32-bit, or up to 64-bit on 64-bit platforms; above that, use a |
522 | | // MultiIntBitSet of size_t. |
523 | | template<unsigned BITS> |
524 | | using BitSet = std::conditional_t<(BITS <= 32), bitset_detail::IntBitSet<uint32_t>, |
525 | | std::conditional_t<(BITS <= std::numeric_limits<size_t>::digits), bitset_detail::IntBitSet<size_t>, |
526 | | bitset_detail::MultiIntBitSet<size_t, CeilDiv(BITS, size_t{std::numeric_limits<size_t>::digits})>>>; |
527 | | |
528 | | #endif // BITCOIN_UTIL_BITSET_H |