23namespace bio::ranges::detail
27struct dynamic_bitset_bitfield
36class dynamic_bitset_reference_proxy
42 constexpr dynamic_bitset_reference_proxy() =
delete;
43 constexpr dynamic_bitset_reference_proxy(dynamic_bitset_reference_proxy
const &)
noexcept =
default;
44 constexpr dynamic_bitset_reference_proxy(dynamic_bitset_reference_proxy &&) noexcept = default;
47 constexpr dynamic_bitset_reference_proxy const & operator=(dynamic_bitset_reference_proxy const rhs) const noexcept
49 rhs ? set() : reset();
54 constexpr dynamic_bitset_reference_proxy
const & operator=(
bool const value)
const noexcept
56 value ? set() : reset();
60 ~dynamic_bitset_reference_proxy() noexcept = default;
64 constexpr dynamic_bitset_reference_proxy(dynamic_bitset_bitfield & internal_,
size_t const pos) noexcept :
65 internal{internal_}, mask{1ULL << pos}
69 constexpr operator bool() const noexcept {
return static_cast<bool>(
internal.bits & mask); }
72 constexpr bool operator~() const noexcept {
return !
static_cast<bool>(
internal.bits & mask); }
75 constexpr dynamic_bitset_reference_proxy
const &
operator|=(
bool const value)
const noexcept
84 constexpr dynamic_bitset_reference_proxy
const &
operator&=(
bool const value)
const noexcept
93 constexpr dynamic_bitset_reference_proxy
const &
operator^=(
bool const value)
const noexcept
95 operator bool() && value ? reset() : set();
106 constexpr void set() const noexcept {
internal.bits |= mask; }
109 constexpr void reset() const noexcept {
internal.bits &= ~mask; }
140template <
size_t bit_capacity = 58>
149 detail::dynamic_bitset_bitfield data{
154 static_assert(bit_capacity <= 58,
"The capacity of the dynamic_bitset exceeds the limit of 58.");
162 using reference = detail::dynamic_bitset_reference_proxy;
166 using iterator = detail::random_access_iterator<dynamic_bitset>;
177 using allocator_type = void;
233 template <std::forward_iterator begin_it_type,
typename end_it_type>
234 requires(std::sentinel_for<end_it_type, begin_it_type> &&
235 std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
256 template <meta::different_from<dynamic_bitset> other_range_t>
257 requires std::ranges::input_range<other_range_t>
324 static_assert(N <= bit_capacity + 1,
"Length of string literal exceeds capacity of dynamic_bitset.");
348 static_assert(N <= bit_capacity + 1,
"Length of string literal exceeds capacity of dynamic_bitset.");
371 constexpr void assign(
char const (&lit)[N])
373 static_assert(N <= bit_capacity + 1,
"Length of string literal exceeds capacity of dynamic_bitset.");
374 assert(lit[N - 1] ==
'\0');
377 for (
size_t i = 0; i != N - 1; ++i)
383 else if (lit[i] ==
'1')
390 throw std::invalid_argument{
"The string to construct a dynamic_bitset from may only contain 0 and 1."};
452 template <std::ranges::input_range other_range_t>
453 requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
454 constexpr void assign(other_range_t && range)
noexcept
476 template <std::forward_iterator begin_it_type,
typename end_it_type>
477 requires(std::sentinel_for<end_it_type, begin_it_type> &&
478 std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
479 constexpr void assign(begin_it_type begin_it, end_it_type end_it)
noexcept
548 assert(
size() == rhs.size());
549 data.bits &= rhs.data.bits;
576 assert(
size() == rhs.size());
577 data.bits |= rhs.data.bits;
604 assert(
size() == rhs.size());
605 data.bits ^= rhs.data.bits;
660 data.bits &= (1ULL <<
size()) - 1ULL;
763 data.bits |= (1ULL <<
size()) - 1ULL;
863 data.bits = ~data.bits;
864 data.bits &= (1ULL <<
size()) - 1ULL;
905 constexpr bool any() const noexcept {
return count() != 0; }
910 constexpr bool none() const noexcept {
return count() == 0; }
981 return data.bits & 1ULL << i;
1031 return (*
this)[
size() - 1];
1038 return (*
this)[
size() - 1];
1042 constexpr detail::dynamic_bitset_bitfield *
raw_data() noexcept {
return &data; }
1045 constexpr detail::dynamic_bitset_bitfield
const *
raw_data() const noexcept {
return &data; }
1064 constexpr bool empty() const noexcept {
return size() == 0; }
1218 template <std::forward_iterator begin_it_type,
typename end_it_type>
1219 requires(std::sentinel_for<end_it_type, begin_it_type> &&
1220 std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>)
1223 auto const pos_as_num = std::ranges::distance(
cbegin(), pos);
1224 auto const length = std::ranges::distance(begin_it, end_it);
1230 resize(tmp_size + length);
1232 for (
size_type i = tmp_size + length - 1; i > pos_as_num + length - 1; --i)
1233 (*
this)[i] = (*this)[i - length];
1236 for (
auto i = pos_as_num; begin_it != end_it; ++i, ++begin_it)
1237 (*
this)[i] = *begin_it;
1239 return begin() + pos_as_num;
1261 return insert(pos, ilist.begin(), ilist.end());
1287 if (begin_it >= end_it)
1288 return begin() + std::ranges::distance(
cbegin(), end_it);
1290 auto const length = std::ranges::distance(begin_it, end_it);
1291 auto out_it =
begin() + std::ranges::distance(
cbegin(), begin_it);
1293 while (end_it !=
cend())
1294 *(out_it++) = *(end_it++);
1297 return begin() + std::ranges::distance(
cbegin(), begin_it);
1339 assert(
size() < bit_capacity);
1341 (*this)[
size() - 1] = value;
1392 assert(
count <= bit_capacity);
1398 data.bits &= (1ULL <<
size()) - 1ULL;
1417 detail::dynamic_bitset_bitfield tmp = data;
1454 template <
size_t cap>
1455 requires(cap <= bit_capacity)
1472 template <
size_t cap>
1473 requires(cap <= bit_capacity)
1490 template <
size_t cap>
1491 requires(cap <= bit_capacity)
1505 template <
size_t cap>
1508 return lhs.data.size == rhs.
raw_data()->size && lhs.data.bits == rhs.
raw_data()->bits;
1512 template <
size_t cap>
1515 return lhs.data.bits <=> rhs.
raw_data()->bits;
1541 throw std::overflow_error{
"bio::ranges::dynamic_bitset cannot be represented as unsigned long."};
1544 return static_cast<unsigned long>(data.bits);
1566 throw std::overflow_error{
"bio::ranges::dynamic_bitset cannot be represented as unsigned long long."};
1569 return static_cast<unsigned long long>(data.bits);
1583 template <
typename archive_t>
1584 void serialize(archive_t & archive)
1586 uint64_t
size = data.size;
1589 uint64_t bits = data.bits;
1605template <
size_t cap>
1615 return static_cast<size_t>(arg.to_ullong());
1621#if __has_include(<fmt/format.h>)
1623# include <fmt/ranges.h>
1626struct fmt::formatter<
bio::ranges::detail::dynamic_bitset_reference_proxy> : fmt::formatter<bool>
1628 constexpr auto format(bio::ranges::detail::dynamic_bitset_reference_proxy
const a,
auto & ctx)
const
1630 return fmt::formatter<bool>::format(
static_cast<bool>(a), ctx);
1634template <
size_t bit_capacity>
1635struct fmt::is_range<
bio::ranges::dynamic_bitset<bit_capacity>, char> :
std::false_type
1638template <
size_t bit_capacity>
1639struct fmt::formatter<
bio::ranges::dynamic_bitset<bit_capacity>> : fmt::formatter<std::string>
1645 auto v = s | std::views::transform([](
bool const bit) {
return bit ?
'1' :
'0'; }) |
1648 return fmt::formatter<std::string>::format(str, ctx);
T back_inserter(T... args)
A constexpr bitset implementation with dynamic size at compile time.
Definition: dynamic_bitset.hpp:142
ptrdiff_t difference_type
A std::ptrdiff_t.
Definition: dynamic_bitset.hpp:170
constexpr void assign(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition: dynamic_bitset.hpp:411
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: dynamic_bitset.hpp:1079
constexpr bool any() const noexcept
Checks if any bit is set.
Definition: dynamic_bitset.hpp:905
constexpr reference front() noexcept
Returns the first element.
Definition: dynamic_bitset.hpp:1000
constexpr dynamic_bitset(char const (&lit)[N])
Construction from literal.
Definition: dynamic_bitset.hpp:322
constexpr void assign(other_range_t &&range) noexcept
Assign from a different range.
Definition: dynamic_bitset.hpp:454
constexpr reference at(size_t const i)
Returns the i-th element.
Definition: dynamic_bitset.hpp:930
constexpr dynamic_bitset(size_type const n, value_type const value) noexcept
Construct with n times value.
Definition: dynamic_bitset.hpp:276
constexpr size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold and resolves to bit_capacity.
Definition: dynamic_bitset.hpp:1099
constexpr reference operator[](size_t const i) noexcept
Returns the i-th element.
Definition: dynamic_bitset.hpp:971
detail::dynamic_bitset_reference_proxy reference
A proxy type that enables assignment.
Definition: dynamic_bitset.hpp:162
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition: dynamic_bitset.hpp:1390
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition: dynamic_bitset.hpp:513
constexpr size_type capacity() const noexcept
Returns the number of elements that the container is able to hold and resolves to bit_capacity.
Definition: dynamic_bitset.hpp:1114
constexpr void swap(dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition: dynamic_bitset.hpp:1414
friend constexpr bool operator==(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1506
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition: dynamic_bitset.hpp:519
constexpr dynamic_bitset & operator&=(dynamic_bitset const &rhs) noexcept
Sets the bits to the result of binary AND on corresponding pairs of bits of *this and rhs.
Definition: dynamic_bitset.hpp:546
constexpr const_iterator end() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition: dynamic_bitset.hpp:516
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition: dynamic_bitset.hpp:861
constexpr dynamic_bitset(other_range_t &&range) noexcept
Construct from a different range.
Definition: dynamic_bitset.hpp:258
constexpr dynamic_bitset & set(size_t const i, bool const value=true)
Sets the i'th bit to value.
Definition: dynamic_bitset.hpp:787
constexpr dynamic_bitset & operator=(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition: dynamic_bitset.hpp:294
constexpr dynamic_bitset & operator|=(dynamic_bitset const &rhs) noexcept
Sets the bits to the result of binary OR on corresponding pairs of bits of *this and rhs.
Definition: dynamic_bitset.hpp:574
constexpr dynamic_bitset operator~() const noexcept
Returns a temporary copy of *this with all bits flipped (binary NOT).
Definition: dynamic_bitset.hpp:630
constexpr void reserve(size_t) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: dynamic_bitset.hpp:1117
constexpr dynamic_bitset & flip(size_t const i)
Flips the i'th bit (binary NOT).
Definition: dynamic_bitset.hpp:887
constexpr iterator insert(const_iterator pos, size_type const count, value_type const value) noexcept
Inserts count copies of value before position in the container.
Definition: dynamic_bitset.hpp:1190
constexpr unsigned long to_ulong() const
Converts the dynamic_bitset to an unsigned long integer.
Definition: dynamic_bitset.hpp:1536
constexpr dynamic_bitset & reset(size_t const i)
Sets the i'th bit to false.
Definition: dynamic_bitset.hpp:838
constexpr const_reference back() const noexcept
Returns the last element.
Definition: dynamic_bitset.hpp:1035
constexpr dynamic_bitset operator>>(size_t const count) const noexcept
Performs binary shift right.
Definition: dynamic_bitset.hpp:708
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition: dynamic_bitset.hpp:1337
constexpr const_reference front() const noexcept
Returns the first element.
Definition: dynamic_bitset.hpp:1007
constexpr dynamic_bitset & operator=(char const (&lit)[N])
Assign from literal.
Definition: dynamic_bitset.hpp:346
constexpr bool all() const noexcept
Checks if all bit are set.
Definition: dynamic_bitset.hpp:900
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition: dynamic_bitset.hpp:1360
constexpr void assign(size_type const count, value_type const value) noexcept
Assign with count times value.
Definition: dynamic_bitset.hpp:430
constexpr void clear() noexcept
Removes all elements from the container.
Definition: dynamic_bitset.hpp:1147
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition: dynamic_bitset.hpp:1285
constexpr const_reference at(size_t const i) const
Returns the i-th element.
Definition: dynamic_bitset.hpp:939
constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept
Construct from two iterators.
Definition: dynamic_bitset.hpp:236
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition: dynamic_bitset.hpp:761
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: dynamic_bitset.hpp:1123
constexpr reference back() noexcept
Returns the last element.
Definition: dynamic_bitset.hpp:1028
constexpr iterator insert(const_iterator pos, std::initializer_list< value_type > const &ilist) noexcept
Inserts elements from initializer list before pos in the container.
Definition: dynamic_bitset.hpp:1259
constexpr void assign(char const (&lit)[N])
Assign from literal.
Definition: dynamic_bitset.hpp:371
constexpr iterator insert(const_iterator pos, value_type const value) noexcept
Inserts value before pos in the container.
Definition: dynamic_bitset.hpp:1170
constexpr void swap(dynamic_bitset &&rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: dynamic_bitset.hpp:1423
constexpr detail::dynamic_bitset_bitfield * raw_data() noexcept
Direct access to the underlying bit field.
Definition: dynamic_bitset.hpp:1042
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
Assign from pair of iterators.
Definition: dynamic_bitset.hpp:479
constexpr dynamic_bitset() noexcept=default
Defaulted.
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition: dynamic_bitset.hpp:813
constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
Performs binary shift left on the current object.
Definition: dynamic_bitset.hpp:655
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition: dynamic_bitset.hpp:1320
constexpr unsigned long long to_ullong() const
Converts the dynamic_bitset to an unsigned long long integer.
Definition: dynamic_bitset.hpp:1561
constexpr const_reference test(size_t const i) const
Returns the i-th element.
Definition: dynamic_bitset.hpp:948
constexpr const_reference operator[](size_t const i) const noexcept
Returns the i-th element.
Definition: dynamic_bitset.hpp:978
constexpr dynamic_bitset operator<<(size_t const count) const noexcept
Performs binary shift left.
Definition: dynamic_bitset.hpp:735
constexpr bool none() const noexcept
Checks if no bit is set.
Definition: dynamic_bitset.hpp:910
friend constexpr auto operator<=>(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1513
constexpr const_iterator begin() const noexcept
Returns the begin to the dynamic_bitset.
Definition: dynamic_bitset.hpp:500
friend constexpr void swap(dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition: dynamic_bitset.hpp:1441
bool value_type
Equals bool.
Definition: dynamic_bitset.hpp:160
constexpr iterator insert(const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept
Inserts elements from range [begin_it, end_it) before pos in the container.
Definition: dynamic_bitset.hpp:1221
detail::random_access_iterator< dynamic_bitset > iterator
The iterator type of this container (a random access iterator).
Definition: dynamic_bitset.hpp:166
constexpr const_iterator cbegin() const noexcept
Returns the begin to the dynamic_bitset.
Definition: dynamic_bitset.hpp:503
bool const_reference
Equals the value_type.
Definition: dynamic_bitset.hpp:164
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: dynamic_bitset.hpp:1064
detail::random_access_iterator< dynamic_bitset const > const_iterator
The const_iterator type of this container (a random access iterator).
Definition: dynamic_bitset.hpp:168
constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
Performs binary shift right on the current object.
Definition: dynamic_bitset.hpp:682
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition: dynamic_bitset.hpp:497
constexpr size_type count() const noexcept
Returns the number of set bits.
Definition: dynamic_bitset.hpp:913
constexpr dynamic_bitset & operator^=(dynamic_bitset const &rhs) noexcept
Sets the bits to the result of binary XOR on corresponding pairs of bits of *this and rhs.
Definition: dynamic_bitset.hpp:602
constexpr detail::dynamic_bitset_bitfield const * raw_data() const noexcept
Direct access to the underlying bit field.
Definition: dynamic_bitset.hpp:1045
constexpr auto size
A type trait that holds the size of a (semi-)alphabet.
Definition: concept.hpp:517
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:98
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition: interleave.hpp:164
Provides metaprogramming utilities for integer types.
Provides bio::views::interleave.
constexpr translation_frames & operator^=(translation_frames &lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:141
constexpr translation_frames & operator&=(translation_frames &lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:129
constexpr translation_frames operator~(translation_frames lhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:123
constexpr translation_frames & operator|=(translation_frames &lhs, translation_frames rhs) noexcept
Binary operators for bio::alphabet::translation_frames.
Definition: translation.hpp:135
The ranges module's namespace.
The main BioC++ namespace.
Definition: aa10li.hpp:23
Provides bio::views::repeat_n.
size_t operator()(bio::ranges::dynamic_bitset< cap > const arg) const noexcept
Compute the hash for a bio::ranges::dynamic_bitset.
Definition: dynamic_bitset.hpp:1613
An implementation of C++23's std::ranges::to.