2#include "gaia/config/config.h"
13 template <
typename TBitset,
bool IsFwd,
bool IsInverse>
22 const TBitset* m_bitset =
nullptr;
32 GAIA_NODISCARD
bool check_bit(
uint32_t pos)
const noexcept {
34 return !m_bitset->test(
pos);
36 return m_bitset->test(
pos);
39 GAIA_NODISCARD uint32_t find_next_set_bit(uint32_t pos)
const noexcept {
40 value_type wordIndex = pos / TBitset::BitsPerItem;
41 const auto item_count = m_bitset->items();
42 GAIA_ASSERT(wordIndex < item_count);
45 const size_type posInWord = pos % TBitset::BitsPerItem + 1;
46 if GAIA_LIKELY (posInWord < TBitset::BitsPerItem) {
48 word = item(wordIndex) & (~mask);
51 GAIA_MSVC_WARNING_PUSH()
52 GAIA_MSVC_WARNING_DISABLE(4244)
55 if constexpr (TBitset::BitsPerItem == 32)
56 return wordIndex * TBitset::BitsPerItem + GAIA_FFS(word) - 1;
58 return wordIndex * TBitset::BitsPerItem + GAIA_FFS64(word) - 1;
62 if (++wordIndex >= item_count)
65 word = item(wordIndex);
67 GAIA_MSVC_WARNING_POP()
70 GAIA_NODISCARD uint32_t find_prev_set_bit(uint32_t pos)
const noexcept {
71 value_type wordIndex = pos / TBitset::BitsPerItem;
72 GAIA_ASSERT(wordIndex < m_bitset->items());
74 const size_type posInWord = pos % TBitset::BitsPerItem;
78 GAIA_MSVC_WARNING_PUSH()
79 GAIA_MSVC_WARNING_DISABLE(4244)
82 if constexpr (TBitset::BitsPerItem == 32)
83 return TBitset::BitsPerItem * (wordIndex + 1) - GAIA_CTZ(word) - 1;
85 return TBitset::BitsPerItem * (wordIndex + 1) - GAIA_CTZ64(word) - 1;
92 word = item(--wordIndex);
94 GAIA_MSVC_WARNING_POP()
98 bitset_const_iterator() =
default;
105 if constexpr (!
IsFwd) {
107 if (
pos != 0 || !check_bit(0)) {
108 pos = find_next_set_bit(m_pos);
118 if (
pos != 0 || !check_bit(0)) {
119 pos = find_next_set_bit(m_pos);
134 if constexpr (!
IsFwd) {
137 const auto newPos = find_prev_set_bit(
pos);
144 const auto newPos = find_prev_set_bit(
pos);
178 if constexpr (!
IsFwd) {
182 auto newPos = find_prev_set_bit(m_pos);
188 auto newPos = find_next_set_bit(m_pos);
210 return m_pos == other.m_pos;
217 return m_pos != other.m_pos;
223 template <
typename TBitset>
224 using const_iterator = bitset_const_iterator<TBitset, true, false>;
227 template <
typename TBitset>
228 using const_iterator_inverse = bitset_const_iterator<TBitset, true, true>;
231 template <
typename TBitset>
232 using const_reverse_iterator = bitset_const_iterator<TBitset, false, false>;
235 template <
typename TBitset>
236 using const_reverse_inverse_iterator = bitset_const_iterator<TBitset, false, true>;
Bitset iterator.
Definition bitset_iterator.h:14
GAIA_NODISCARD bool operator!=(const bitset_const_iterator &other) const
Compares iterator positions.
Definition bitset_iterator.h:216
typename TBitset::size_type size_type
Backing-word type used by the parent bit set.
Definition bitset_iterator.h:19
GAIA_NODISCARD value_type operator->() const
Returns the current bit index for arrow-style access.
Definition bitset_iterator.h:165
GAIA_NODISCARD value_type index() const
Returns the current bit index.
Definition bitset_iterator.h:171
GAIA_NODISCARD bool operator==(const bitset_const_iterator &other) const
Compares iterator positions.
Definition bitset_iterator.h:209
uint32_t value_type
Bit-index value type.
Definition bitset_iterator.h:17
GAIA_NODISCARD value_type operator*() const
Returns the current bit index.
Definition bitset_iterator.h:159
GAIA_NODISCARD bitset_const_iterator operator++(int)
Advances to the next matching bit in the iterator's direction.
Definition bitset_iterator.h:200
bitset_const_iterator(const TBitset &bitset, value_type pos, bool fwd)
Definition bitset_iterator.h:103
bitset_const_iterator & operator++()
Advances to the next matching bit in the iterator's direction.
Definition bitset_iterator.h:177
Fixed-size bit set.
Definition bitset.h:14
GAIA_NODISCARD constexpr uint32_t size() const
Returns the number of bits the bitset can hold.
Definition bitset.h:314
Array with variable size of elements of type.
Definition darray_impl.h:27
GAIA_NODISCARD pointer data() noexcept
Returns a pointer to the element storage.
Definition darray_impl.h:193