19#include <seastar/util/modules.hh>
26static constexpr int ulong_bits = std::numeric_limits<unsigned long>::digits;
38size_t count_leading_zeros(T value)
noexcept;
49size_t count_trailing_zeros(T value)
noexcept;
52inline size_t count_leading_zeros<unsigned long>(
unsigned long value)
noexcept
54 return __builtin_clzl(value);
58inline size_t count_leading_zeros<long>(
long value)
noexcept
60 return __builtin_clzl((
unsigned long)value) - 1;
64inline size_t count_leading_zeros<unsigned long long>(
unsigned long long value)
noexcept
66 return __builtin_clzll(value);
70inline size_t count_leading_zeros<long long>(
long long value)
noexcept
72 return __builtin_clzll((
unsigned long long)value) - 1;
77size_t count_trailing_zeros<unsigned long>(
unsigned long value)
noexcept
79 return __builtin_ctzl(value);
84size_t count_trailing_zeros<long>(
long value)
noexcept
86 return __builtin_ctzl((
unsigned long)value);
91size_t count_trailing_zeros<unsigned long long>(
unsigned long long value)
noexcept
93 return __builtin_ctzll(value);
98size_t count_trailing_zeros<long long>(
long long value)
noexcept
100 return __builtin_ctzll((
unsigned long long)value);
108inline size_t get_first_set(
const std::bitset<N>& bitset)
noexcept
110 static_assert(N <= ulong_bits,
"bitset too large");
111 return count_trailing_zeros(bitset.to_ulong());
119inline size_t get_last_set(
const std::bitset<N>& bitset)
noexcept
121 static_assert(N <= ulong_bits,
"bitset too large");
122 return ulong_bits - 1 - count_leading_zeros(bitset.to_ulong());
125SEASTAR_MODULE_EXPORT_BEGIN
131 void advance()
noexcept
133 if (_bitset.none()) {
136 auto shift = get_first_set(_bitset) + 1;
142 using iterator_category = std::input_iterator_tag;
143 using value_type = int;
144 using difference_type = std::ptrdiff_t;
145 using pointer =
int*;
146 using reference =
int&;
148 set_iterator(std::bitset<N> bitset,
int offset = 0) noexcept
152 static_assert(N <= ulong_bits,
"This implementation is inefficient for large bitsets");
170 int operator*()
const noexcept
175 bool operator==(
const set_iterator& other)
const noexcept
177 return _index == other._index;
180 bool operator!=(
const set_iterator& other)
const noexcept
182 return !(*
this == other);
185 std::bitset<N> _bitset;
194 using value_type = int;
196 constexpr set_range(std::bitset<N> bitset,
int offset = 0) noexcept
205 std::bitset<N> _bitset;
210inline set_range<N> for_each_set(std::bitset<N> bitset,
int offset = 0) noexcept
215SEASTAR_MODULE_EXPORT_END
Definition: bitset-iter.hh:129
Definition: bitset-iter.hh:191
Seastar API namespace.
Definition: abort_on_ebadf.hh:26