SeqAn3 3.4.0-rc.4
The Modern C++ library for sequence analysis.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
dynamic_bitset.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <bit>
13#include <istream>
14
21
22namespace seqan3
23{
24
50template <size_t bit_capacity = 58>
52{
53private:
55 template <size_t>
56 friend class dynamic_bitset;
57
59 struct bitfield
60 {
62 uint64_t size : 6u;
64 uint64_t bits : 58u;
65 };
66
68 bitfield data{0u, 0u}; // Specifying values prevents ICE on gcc < 9 when comparing to default constructed bitset
69
71 class reference_proxy_type
72 {
73 public:
77 constexpr reference_proxy_type() noexcept = default;
78 constexpr reference_proxy_type(reference_proxy_type const &) noexcept = default;
79 constexpr reference_proxy_type(reference_proxy_type &&) noexcept = default;
80
82 constexpr reference_proxy_type & operator=(reference_proxy_type const rhs) noexcept
83 {
84 rhs ? set() : reset();
85 return *this;
86 }
87
89 constexpr reference_proxy_type & operator=(bool const value) noexcept
90 {
91 value ? set() : reset();
92 return *this;
93 }
94
95 ~reference_proxy_type() noexcept = default;
96
98
100 constexpr reference_proxy_type(bitfield & internal_, size_t const pos) noexcept :
101 internal{internal_},
102 mask{1ULL << pos}
103 {}
104
106 constexpr operator bool() const noexcept
107 {
108 return static_cast<bool>(internal.bits & mask);
109 }
110
112 constexpr bool operator~() const noexcept
113 {
114 return !static_cast<bool>(internal.bits & mask);
115 }
116
118 constexpr reference_proxy_type & operator|=(bool const value)
119 {
120 if (value)
121 set();
122
123 return *this;
124 }
125
127 constexpr reference_proxy_type & operator&=(bool const value)
128 {
129 if (!value)
130 reset();
131
132 return *this;
133 }
134
136 constexpr reference_proxy_type & operator^=(bool const value)
137 {
138 operator bool() && value ? reset() : set();
139 return *this;
140 }
141
142 private:
144 bitfield & internal;
146 uint64_t mask;
147
149 constexpr void set() noexcept
150 {
151 internal.bits |= mask;
152 }
153
155 constexpr void reset() noexcept
156 {
157 internal.bits &= ~mask;
158 }
159 };
160
161public:
162 static_assert(bit_capacity <= 58, "The capacity of the dynamic_bitset exceeds the limit of 58.");
163
172
177 using reference = reference_proxy_type;
178
184
189 using iterator = detail::random_access_iterator<dynamic_bitset>;
190
195 using const_iterator = detail::random_access_iterator<dynamic_bitset const>;
196
201 using difference_type = ptrdiff_t;
202
209
219
241 {
242 if (std::popcount(value >> 58u) != 0u)
243 throw std::invalid_argument{"The dynamic_bitset can be at most 58 long."};
244 data.bits |= value;
245 data.size |= std::bit_width(value);
246 }
247
267 template <std::forward_iterator begin_it_type, typename end_it_type>
268 requires std::sentinel_for<end_it_type, begin_it_type>
269 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
271 {
272 assign(begin_it, end_it);
273 }
274
292 template <std::ranges::input_range other_range_t>
293 requires (!std::same_as<std::remove_cvref_t<other_range_t>, dynamic_bitset>)
295 dynamic_bitset{std::ranges::begin(range), std::ranges::end(range)}
296 {}
297
314 constexpr dynamic_bitset(size_type const n, value_type const value) noexcept : dynamic_bitset{}
315 {
316 assign(n, value);
317 }
318
335 {
336 assign(std::ranges::begin(ilist), std::ranges::end(ilist));
337 return *this;
338 }
339
363 template <size_t N>
364 constexpr dynamic_bitset(char const (&lit)[N]) : dynamic_bitset{}
365 {
366 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
367 assign(lit);
368 }
369
389 template <size_t N>
390 constexpr dynamic_bitset & operator=(char const (&lit)[N])
391 {
392 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
393 assign(lit);
394 return *this;
395 }
396
416 template <size_t N>
417 constexpr void assign(char const (&lit)[N])
418 {
419 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
420 assert(lit[N - 1] == '\0');
421 uint64_t value{};
422
423 for (size_t i = 0; i != N - 1; ++i)
424 {
425 if (lit[i] == '0')
426 {
427 value <<= 1;
428 }
429 else if (lit[i] == '1')
430 {
431 value <<= 1;
432 value |= 1u;
433 }
434 else
435 {
436 throw std::invalid_argument{"The string to construct a dynamic_bitset from may only contain 0 and 1."};
437 }
438 }
439
440 *this = value;
441 resize(N - 1);
442 }
443
459 constexpr void assign(std::initializer_list<value_type> const ilist) noexcept
460 {
461 assign(std::ranges::begin(ilist), std::ranges::end(ilist));
462 }
463
480 constexpr void assign(size_type const count, value_type const value) noexcept
481 {
482 clear();
483 auto tmp = views::repeat_n(value, count);
484 assign(std::ranges::begin(tmp), std::ranges::end(tmp));
485 }
486
504 template <std::ranges::input_range other_range_t>
505 requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
506 constexpr void assign(other_range_t && range) noexcept
507 {
508 assign(std::ranges::begin(range), std::ranges::end(range));
509 }
510
530 template <std::forward_iterator begin_it_type, typename end_it_type>
531 requires std::sentinel_for<end_it_type, begin_it_type>
532 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
533 constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
534 {
535 clear();
536 insert(cbegin(), begin_it, end_it);
537 }
539
554 {
555 return iterator{*this};
556 }
557
560 {
561 return const_iterator{*this};
562 }
563
566 {
567 return begin();
568 }
569
581 {
582 return iterator{*this, size()};
583 }
584
587 {
588 return const_iterator{*this, size()};
589 }
590
593 {
594 return end();
595 }
597
624 constexpr dynamic_bitset & operator&=(dynamic_bitset const & rhs) noexcept
625 {
626 assert(size() == rhs.size());
627 data.bits &= rhs.data.bits;
628 return *this;
629 }
630
654 constexpr dynamic_bitset & operator|=(dynamic_bitset const & rhs) noexcept
655 {
656 assert(size() == rhs.size());
657 data.bits |= rhs.data.bits;
658 return *this;
659 }
660
684 constexpr dynamic_bitset & operator^=(dynamic_bitset const & rhs) noexcept
685 {
686 assert(size() == rhs.size());
687 data.bits ^= rhs.data.bits;
688 return *this;
689 }
690
715 {
716 dynamic_bitset tmp{*this};
717 tmp.flip();
718 return tmp;
719 }
720
741 constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
742 {
743 assert(count > 0);
744 assert(count < size());
745 data.bits <<= count;
746 data.bits &= (1ULL << size()) - 1ULL;
747 return *this;
748 }
749
770 constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
771 {
772 assert(count > 0);
773 assert(count < size());
774 data.bits >>= count;
775 return *this;
776 }
777
798 constexpr dynamic_bitset operator>>(size_t const count) const noexcept
799 {
800 assert(count > 0);
801 assert(count < size());
802 dynamic_bitset tmp{*this};
803 tmp >>= count;
804 return tmp;
805 }
806
827 constexpr dynamic_bitset operator<<(size_t const count) const noexcept
828 {
829 assert(count > 0);
830 assert(count < size());
831 dynamic_bitset tmp{*this};
832 tmp <<= count;
833 return tmp;
834 }
835
856 {
857 data.bits |= (1ULL << size()) - 1ULL;
858 return *this;
859 }
860
883 constexpr dynamic_bitset & set(size_t const i, bool const value = true)
884 {
885 at(i) = value;
886 return *this;
887 }
888
912 {
913 data.bits = 0u;
914 return *this;
915 }
916
938 constexpr dynamic_bitset & reset(size_t const i)
939 {
940 set(i, false);
941 return *this;
942 }
943
964 {
965 data.bits = ~data.bits;
966 data.bits &= (1ULL << size()) - 1ULL;
967 return *this;
968 }
969
991 constexpr dynamic_bitset & flip(size_t const i)
992 {
993 at(i) ? reset(i) : set(i);
994 return *this;
995 }
997
1006 constexpr bool all() const noexcept
1007 {
1008 return count() == size();
1009 }
1010
1016 constexpr bool any() const noexcept
1017 {
1018 return count() != 0;
1019 }
1020
1026 constexpr bool none() const noexcept
1027 {
1028 return count() == 0;
1029 }
1030
1036 {
1037 return std::popcount(data.bits);
1038 }
1039
1057 constexpr reference at(size_t const i)
1058 {
1059 if (i >= size()) // [[unlikely]]
1060 throw std::out_of_range{"Trying to access position " + std::to_string(i)
1061 + " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
1062 return (*this)[i];
1063 }
1064
1066 constexpr const_reference at(size_t const i) const
1067 {
1068 if (i >= size()) // [[unlikely]]
1069 throw std::out_of_range{"Trying to access position " + std::to_string(i)
1070 + " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
1071 return (*this)[i];
1072 }
1073
1075 constexpr const_reference test(size_t const i) const
1076 {
1077 return at(i);
1078 }
1079
1103 constexpr reference operator[](size_t const i) noexcept
1104 {
1105 assert(i < size());
1106 return {data, i};
1107 }
1108
1110 constexpr const_reference operator[](size_t const i) const noexcept
1111 {
1112 assert(i < size());
1113 return data.bits & 1ULL << i;
1114 }
1115
1135 {
1136 assert(size() > 0);
1137 return (*this)[0];
1138 }
1139
1142 {
1143 assert(size() > 0);
1144 return (*this)[0];
1145 }
1146
1165 {
1166 assert(size() > 0);
1167 return (*this)[size() - 1];
1168 }
1169
1172 {
1173 assert(size() > 0);
1174 return (*this)[size() - 1];
1175 }
1176
1181 constexpr bitfield * raw_data() noexcept
1182 {
1183 return &data;
1184 }
1185
1187 constexpr bitfield const * raw_data() const noexcept
1188 {
1189 return &data;
1190 }
1192
1211 constexpr bool empty() const noexcept
1212 {
1213 return size() == 0;
1214 }
1215
1232 {
1233 return data.size;
1234 }
1235
1257 {
1258 return capacity();
1259 }
1260
1277 {
1278 return bit_capacity;
1279 }
1280
1285 constexpr void reserve(size_t) const noexcept
1286 {
1287 // no-op
1288 }
1289
1295 {
1296 // no-op
1297 }
1299
1320 constexpr void clear() noexcept
1321 {
1322 data.size &= 0ULL;
1323 data.bits &= 0ULL;
1324 }
1325
1345 constexpr iterator insert(const_iterator pos, value_type const value) noexcept
1346 {
1347 return insert(pos, 1, value);
1348 }
1349
1370 constexpr iterator insert(const_iterator pos, size_type const count, value_type const value) noexcept
1371 {
1372 auto tmp = views::repeat_n(value, count);
1373 return insert(pos, std::ranges::begin(tmp), std::ranges::end(tmp));
1374 }
1375
1400 template <std::forward_iterator begin_it_type, typename end_it_type>
1401 requires std::sentinel_for<end_it_type, begin_it_type>
1402 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
1403 constexpr iterator insert(const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept
1404 {
1405 auto const pos_as_num = std::ranges::distance(cbegin(), pos);
1406 auto const length = std::ranges::distance(begin_it, end_it);
1407
1408 if (length == 0)
1409 return begin(); // nothing to insert
1410
1411 size_type const tmp_size{size()};
1412 resize(tmp_size + length);
1413
1414 for (size_type i = tmp_size + length - 1; i > pos_as_num + length - 1; --i)
1415 (*this)[i] = (*this)[i - length];
1416
1417 // std::ranges::copy(begin_it, end_it, (*this)[pos_as_num]);
1418 for (auto i = pos_as_num; begin_it != end_it; ++i, ++begin_it)
1419 (*this)[i] = *begin_it;
1420
1421 return begin() + pos_as_num;
1422 }
1423
1444 {
1445 return insert(pos, ilist.begin(), ilist.end());
1446 }
1447
1471 constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
1472 {
1473 if (begin_it >= end_it) // [[unlikely]]
1474 return begin() + std::ranges::distance(cbegin(), end_it);
1475
1476 auto const length = std::ranges::distance(begin_it, end_it);
1477 auto out_it = begin() + std::ranges::distance(cbegin(), begin_it);
1478
1479 while (end_it != cend())
1480 *(out_it++) = *(end_it++);
1481
1482 resize(size() - length);
1483 return begin() + std::ranges::distance(cbegin(), begin_it);
1484 }
1485
1508 constexpr iterator erase(const_iterator pos) noexcept
1509 {
1510 return erase(pos, pos + 1);
1511 }
1512
1530 constexpr void push_back(value_type const value) noexcept
1531 {
1533 resize(size() + 1);
1534 (*this)[size() - 1] = value;
1535 }
1536
1555 constexpr void pop_back() noexcept
1556 {
1557 assert(size() > 0);
1558 resize(size() - 1);
1559 }
1560
1587 constexpr void resize(size_type const count, value_type const value = false) noexcept
1588 {
1590 // Enlarging.
1591 data.bits |= value && count > size() ? ((1ULL << (count - size())) - 1) << size() : 0ULL;
1592 // Set size bits.
1593 data.size = count;
1594 // Shrinking.
1595 data.bits &= (1ULL << size()) - 1ULL;
1596 }
1597
1613 constexpr void swap(dynamic_bitset & rhs) noexcept
1614 {
1615 bitfield tmp = std::move(data);
1616 data = std::move(rhs.data);
1617 rhs.data = std::move(tmp);
1618 }
1619
1621 constexpr void swap(dynamic_bitset && rhs) noexcept
1622 {
1623 data = std::move(rhs.data);
1624 }
1625
1627
1644 friend constexpr void swap(dynamic_bitset & lhs, dynamic_bitset & rhs) noexcept
1645 {
1646 lhs.swap(rhs);
1647 }
1648
1662 template <size_t cap>
1663 requires (cap <= bit_capacity)
1664 friend constexpr dynamic_bitset operator&(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1665 {
1666 assert(lhs.size() == rhs.size());
1668 tmp &= rhs;
1669 return tmp;
1670 }
1671
1682 template <size_t cap>
1683 requires (cap <= bit_capacity)
1684 friend constexpr dynamic_bitset operator^(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1685 {
1686 assert(lhs.size() == rhs.size());
1688 tmp ^= rhs;
1689 return tmp;
1690 }
1691
1702 template <size_t cap>
1703 requires (cap <= bit_capacity)
1704 friend constexpr dynamic_bitset operator|(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1705 {
1706 assert(lhs.size() == rhs.size());
1708 tmp |= rhs;
1709 return tmp;
1710 }
1712
1720 template <size_t cap>
1721 friend constexpr bool operator==(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1722 {
1723 return lhs.data.size == rhs.raw_data()->size && lhs.data.bits == rhs.raw_data()->bits;
1724 }
1725
1730 template <size_t cap>
1731 friend constexpr bool operator!=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1732 {
1733 return !(lhs == rhs);
1734 }
1735
1740 template <size_t cap>
1741 friend constexpr bool operator<(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1742 {
1743 return lhs.data.bits < rhs.raw_data()->bits;
1744 }
1745
1750 template <size_t cap>
1751 friend constexpr bool operator>(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1752 {
1753 return lhs.data.bits > rhs.raw_data()->bits;
1754 }
1755
1760 template <size_t cap>
1761 friend constexpr bool operator<=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1762 {
1763 return !(lhs > rhs);
1764 }
1765
1770 template <size_t cap>
1771 friend constexpr bool operator>=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1772 {
1773 return !(lhs < rhs);
1774 }
1776
1802 template <typename char_t = char>
1804 {
1805 std::string str{};
1806 str.reserve(size());
1807 for (bool const bit : std::views::reverse(*this))
1808 bit ? str.push_back(one) : str.push_back(zero);
1809
1810 return str;
1811 }
1812
1829 inline constexpr unsigned long to_ulong() const
1830 {
1832 {
1834 throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long."};
1835 }
1836
1837 return static_cast<unsigned long>(data.bits);
1838 }
1839
1856 inline constexpr unsigned long long to_ullong() const
1857 {
1859 {
1861 throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long long."};
1862 }
1863
1864 return static_cast<unsigned long long>(data.bits);
1865 }
1867
1883 {
1884 os << arg.to_string();
1885 return os;
1886 }
1887
1902 {
1903 // Check if stream is ok and skip leading whitespaces.
1905 if (s)
1906 {
1907 arg.clear(); // clear the bitset
1909 (is.width() > 0) ? std::min<std::streamsize>(is.width(), arg.max_size()) : arg.max_size();
1910 assert(num_char > 0);
1912 tmp.reserve(num_char);
1913 for (std::streamsize n = num_char; n > 0 && (is.peek() == is.widen('0') || is.peek() == is.widen('1')); --n)
1914 {
1915 char c = is.get();
1916 c == is.widen('0') ? tmp.push_back(false) : tmp.push_back(true);
1917 }
1918
1919 arg.assign(std::views::reverse(tmp));
1920
1921 if (arg.size() == 0) // nothing extracted so we set the fail bit.
1922 is.setstate(std::ios_base::failbit); // LCOV_EXCL_LINE
1923
1924 is.width(0); // cancel the effects of std::setw, if any.
1925 }
1926 return is;
1927 }
1928
1930
1941 template <cereal_archive archive_t>
1943 {
1944 uint64_t size = data.size;
1945 archive(size);
1946 data.size = size;
1947 uint64_t bits = data.bits;
1948 archive(bits);
1949 data.bits = bits;
1950 }
1952};
1953
1958template <size_t bit_capacity>
1960{
1967 template <typename stream_t, typename arg_t>
1968 constexpr void operator()(stream_t & stream, arg_t && arg) const
1969 {
1970 stream << (std::string_view{arg.to_string()} | views::interleave(4, std::string_view{"'"})
1972 }
1973};
1974
1975} // namespace seqan3
1976
1977namespace std
1978{
1979
1986template <size_t cap>
1987struct hash<seqan3::dynamic_bitset<cap>>
1988{
1996 size_t operator()(seqan3::dynamic_bitset<cap> const arg) const noexcept
1997 {
1998 return static_cast<size_t>(arg.to_ullong());
1999 }
2000};
2001
2002} //namespace std
T begin(T... args)
T bit_width(T... args)
Adaptions of concepts from the Cereal library.
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
A constexpr bitset implementation with dynamic size at compile time.
Definition dynamic_bitset.hpp:52
constexpr dynamic_bitset operator<<(size_t const count) const noexcept
Performs binary shift left.
Definition dynamic_bitset.hpp:827
friend class dynamic_bitset
Befriend other template instantiations of dynamic_bitset.
Definition dynamic_bitset.hpp:56
constexpr iterator insert(const_iterator pos, value_type const value) noexcept
Inserts value before pos in the container.
Definition dynamic_bitset.hpp:1345
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition dynamic_bitset.hpp:1231
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:1443
constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
Performs binary shift left on the current object.
Definition dynamic_bitset.hpp:741
constexpr bool any() const noexcept
Checks if any bit is set.
Definition dynamic_bitset.hpp:1016
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition dynamic_bitset.hpp:1587
friend constexpr bool operator<(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1741
constexpr const_reference test(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1075
constexpr reference back() noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1164
friend std::istream & operator>>(std::istream &is, dynamic_bitset &arg)
Formatted input for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1901
constexpr void clear() noexcept
Removes all elements from the container.
Definition dynamic_bitset.hpp:1320
constexpr size_type count() const noexcept
Returns the number of set bits.
Definition dynamic_bitset.hpp:1035
constexpr reference front() noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1134
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition dynamic_bitset.hpp:1211
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:1256
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1294
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:624
constexpr bool all() const noexcept
Checks if all bit are set.
Definition dynamic_bitset.hpp:1006
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition dynamic_bitset.hpp:963
friend constexpr bool operator==(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1721
reference_proxy_type reference
A proxy type that enables assignment.
Definition dynamic_bitset.hpp:177
constexpr void assign(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:417
constexpr const_iterator begin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:559
constexpr unsigned long to_ulong() const
Converts the dynamic_bitset to an unsigned long integer.
Definition dynamic_bitset.hpp:1829
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
Assign from pair of iterators.
Definition dynamic_bitset.hpp:533
constexpr void swap(dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1613
constexpr dynamic_bitset(other_range_t &&range) noexcept
Construct from a different range.
Definition dynamic_bitset.hpp:294
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:1621
constexpr dynamic_bitset(char const (&lit)[N])
Construction from literal.
Definition dynamic_bitset.hpp:364
constexpr reference at(size_t const i)
Returns the i-th element.
Definition dynamic_bitset.hpp:1057
constexpr dynamic_bitset & operator=(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:334
constexpr dynamic_bitset & reset(size_t const i)
Sets the i'th bit to false.
Definition dynamic_bitset.hpp:938
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1508
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:1276
constexpr bitfield const * raw_data() const noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1187
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition dynamic_bitset.hpp:1530
constexpr const_iterator cbegin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:565
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:1403
constexpr dynamic_bitset operator>>(size_t const count) const noexcept
Performs binary shift right.
Definition dynamic_bitset.hpp:798
constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept
Construct from two iterators.
Definition dynamic_bitset.hpp:270
constexpr const_reference operator[](size_t const i) const noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1110
constexpr unsigned long long to_ullong() const
Converts the dynamic_bitset to an unsigned long long integer.
Definition dynamic_bitset.hpp:1856
constexpr const_reference back() const noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1171
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition dynamic_bitset.hpp:855
constexpr bitfield * raw_data() noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1181
friend std::ostream & operator<<(std::ostream &os, dynamic_bitset const &arg)
Formatted output for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1882
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:580
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition dynamic_bitset.hpp:1555
constexpr const_reference at(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1066
friend constexpr bool operator>=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1771
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:553
constexpr void assign(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:459
constexpr dynamic_bitset & set(size_t const i, bool const value=true)
Sets the i'th bit to value.
Definition dynamic_bitset.hpp:883
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition dynamic_bitset.hpp:911
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:592
constexpr bool none() const noexcept
Checks if no bit is set.
Definition dynamic_bitset.hpp:1026
constexpr dynamic_bitset operator~() const noexcept
Returns a temporary copy of *this with all bits flipped (binary NOT).
Definition dynamic_bitset.hpp:714
constexpr const_iterator end() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:586
constexpr dynamic_bitset & operator=(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:390
friend constexpr void swap(dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1644
constexpr void assign(size_type const count, value_type const value) noexcept
Assign with count times value.
Definition dynamic_bitset.hpp:480
ptrdiff_t difference_type
A std::ptrdiff_t.
Definition dynamic_bitset.hpp:201
constexpr dynamic_bitset() noexcept=default
Defaulted.
constexpr const_reference front() const noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1141
constexpr void assign(other_range_t &&range) noexcept
Assign from a different range.
Definition dynamic_bitset.hpp:506
std::string to_string(char_t zero=char_t{ '0'}, char_t one=char_t{ '1'}) const
Converts the dynamic_bitset to a std::string.
Definition dynamic_bitset.hpp:1803
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:684
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1471
constexpr void reserve(size_t) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1285
constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
Performs binary shift right on the current object.
Definition dynamic_bitset.hpp:770
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:654
friend constexpr bool operator<=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1761
detail::random_access_iterator< dynamic_bitset > iterator
The iterator type of this container (a random access iterator).
Definition dynamic_bitset.hpp:189
constexpr dynamic_bitset(size_type const n, value_type const value) noexcept
Construct with n times value.
Definition dynamic_bitset.hpp:314
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:1370
detail::random_access_iterator< dynamic_bitset const > const_iterator
The const_iterator type of this container (a random access iterator).
Definition dynamic_bitset.hpp:195
constexpr reference operator[](size_t const i) noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1103
friend constexpr bool operator>(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1751
friend constexpr bool operator!=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1731
constexpr dynamic_bitset & flip(size_t const i)
Flips the i'th bit (binary NOT).
Definition dynamic_bitset.hpp:991
Provides seqan3::debug_stream and related types.
T get(T... args)
seqan::stl::ranges::to to
Converts a range to a container. <dl class="no-api">This entity is not part of the SeqAn API....
Definition to.hpp:23
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition interleave.hpp:374
Provides metaprogramming utilities for integer types.
Provides seqan3::views::interleave.
T internal(T... args)
T max(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
T peek(T... args)
T popcount(T... args)
Provides seqan3::views::repeat_n.
T reserve(T... args)
T reverse(T... args)
T setstate(T... args)
constexpr void operator()(stream_t &stream, arg_t &&arg) const
Prints the dynamic bitset.
Definition dynamic_bitset.hpp:1968
Definition default_printer.hpp:34
size_t operator()(seqan3::dynamic_bitset< cap > const arg) const noexcept
Compute the hash for a seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1996
Provides seqan3::ranges::to.
T to_string(T... args)
T widen(T... args)
T width(T... args)
Hide me