SeqAn3 3.4.1-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
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#include <vector>
15
22
23namespace seqan3
24{
25
51template <size_t bit_capacity = 58>
53{
54private:
56 template <size_t>
57 friend class dynamic_bitset;
58
60 struct bitfield
61 {
63 uint64_t size : 6u;
65 uint64_t bits : 58u;
66 };
67
69 bitfield data{0u, 0u}; // Specifying values prevents ICE on gcc < 9 when comparing to default constructed bitset
70
73 {
74 public:
78 constexpr reference_proxy_type() noexcept = default;
79 constexpr reference_proxy_type(reference_proxy_type const &) noexcept = default;
80 constexpr reference_proxy_type(reference_proxy_type &&) noexcept = default;
81
83 constexpr reference_proxy_type & operator=(reference_proxy_type const rhs) noexcept
84 {
85 rhs ? set() : reset();
86 return *this;
87 }
88
90 constexpr reference_proxy_type & operator=(bool const value) noexcept
91 {
92 value ? set() : reset();
93 return *this;
94 }
95
96 ~reference_proxy_type() noexcept = default;
97
99
101 constexpr reference_proxy_type(bitfield & internal_, size_t const pos) noexcept :
102 internal{internal_},
103 mask{1ULL << pos}
104 {}
105
107 constexpr operator bool() const noexcept
108 {
109 return static_cast<bool>(internal.bits & mask);
110 }
111
113 constexpr bool operator~() const noexcept
114 {
115 return !static_cast<bool>(internal.bits & mask);
116 }
117
119 constexpr reference_proxy_type & operator|=(bool const value)
120 {
121 if (value)
122 set();
123
124 return *this;
125 }
126
128 constexpr reference_proxy_type & operator&=(bool const value)
129 {
130 if (!value)
131 reset();
132
133 return *this;
134 }
135
137 constexpr reference_proxy_type & operator^=(bool const value)
138 {
139 operator bool() && value ? reset() : set();
140 return *this;
141 }
142
143 private:
147 uint64_t mask;
148
150 constexpr void set() noexcept
151 {
152 internal.bits |= mask;
153 }
154
156 constexpr void reset() noexcept
157 {
159 }
160 };
161
162public:
163 static_assert(bit_capacity <= 58, "The capacity of the dynamic_bitset exceeds the limit of 58.");
164
172 using value_type = bool;
173
179
184 using const_reference = bool;
185
191
197
202 using difference_type = ptrdiff_t;
203
210
214 constexpr dynamic_bitset() noexcept = default;
215 constexpr dynamic_bitset(dynamic_bitset const &) noexcept = default;
216 constexpr dynamic_bitset(dynamic_bitset &&) noexcept = default;
217 constexpr dynamic_bitset & operator=(dynamic_bitset const &) noexcept = default;
218 constexpr dynamic_bitset & operator=(dynamic_bitset &&) noexcept = default;
219 ~dynamic_bitset() noexcept = default;
220
241 constexpr dynamic_bitset(uint64_t const value)
242 {
243 if (std::popcount(value >> 58u) != 0u)
244 throw std::invalid_argument{"The dynamic_bitset can be at most 58 long."};
245 data.bits |= value;
246 data.size |= std::bit_width(value);
247 }
248
268 template <std::forward_iterator begin_it_type, typename end_it_type>
269 requires std::sentinel_for<end_it_type, begin_it_type>
270 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
271 constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept : dynamic_bitset{}
272 {
273 assign(begin_it, end_it);
274 }
275
293 template <std::ranges::input_range other_range_t>
294 requires (!std::same_as<std::remove_cvref_t<other_range_t>, dynamic_bitset>)
295 explicit constexpr dynamic_bitset(other_range_t && range) noexcept :
296 dynamic_bitset{std::ranges::begin(range), std::ranges::end(range)}
297 {}
298
315 constexpr dynamic_bitset(size_type const n, value_type const value) noexcept : dynamic_bitset{}
316 {
317 assign(n, value);
318 }
319
336 {
337 assign(std::ranges::begin(ilist), std::ranges::end(ilist));
338 return *this;
339 }
340
364 template <size_t N>
365 constexpr dynamic_bitset(char const (&lit)[N]) : dynamic_bitset{}
366 {
367 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
368 assign(lit);
369 }
370
390 template <size_t N>
391 constexpr dynamic_bitset & operator=(char const (&lit)[N])
392 {
393 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
394 assign(lit);
395 return *this;
396 }
397
417 template <size_t N>
418 constexpr void assign(char const (&lit)[N])
419 {
420 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
421 assert(lit[N - 1] == '\0');
422 uint64_t value{};
423
424 for (size_t i = 0; i != N - 1; ++i)
425 {
426 if (lit[i] == '0')
427 {
428 value <<= 1;
429 }
430 else if (lit[i] == '1')
431 {
432 value <<= 1;
433 value |= 1u;
434 }
435 else
436 {
437 throw std::invalid_argument{"The string to construct a dynamic_bitset from may only contain 0 and 1."};
438 }
439 }
440
441 *this = value;
442 resize(N - 1);
443 }
444
460 constexpr void assign(std::initializer_list<value_type> const ilist) noexcept
461 {
462 assign(std::ranges::begin(ilist), std::ranges::end(ilist));
463 }
464
481 constexpr void assign(size_type const count, value_type const value) noexcept
482 {
483 clear();
484 auto tmp = views::repeat_n(value, count);
485 assign(std::ranges::begin(tmp), std::ranges::end(tmp));
486 }
487
505 template <std::ranges::input_range other_range_t>
506 requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
507 constexpr void assign(other_range_t && range) noexcept
508 {
509 assign(std::ranges::begin(range), std::ranges::end(range));
510 }
511
531 template <std::forward_iterator begin_it_type, typename end_it_type>
532 requires std::sentinel_for<end_it_type, begin_it_type>
533 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
534 constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
535 {
536 clear();
537 insert(cbegin(), begin_it, end_it);
538 }
540
554 constexpr iterator begin() noexcept
555 {
556 return iterator{*this};
557 }
558
560 constexpr const_iterator begin() const noexcept
561 {
562 return const_iterator{*this};
563 }
564
566 constexpr const_iterator cbegin() const noexcept
567 {
568 return begin();
569 }
570
581 constexpr iterator end() noexcept
582 {
583 return iterator{*this, size()};
584 }
585
587 constexpr const_iterator end() const noexcept
588 {
589 return const_iterator{*this, size()};
590 }
591
593 constexpr const_iterator cend() const noexcept
594 {
595 return end();
596 }
598
625 constexpr dynamic_bitset & operator&=(dynamic_bitset const & rhs) noexcept
626 {
627 assert(size() == rhs.size());
628 data.bits &= rhs.data.bits;
629 return *this;
630 }
631
655 constexpr dynamic_bitset & operator|=(dynamic_bitset const & rhs) noexcept
656 {
657 assert(size() == rhs.size());
658 data.bits |= rhs.data.bits;
659 return *this;
660 }
661
685 constexpr dynamic_bitset & operator^=(dynamic_bitset const & rhs) noexcept
686 {
687 assert(size() == rhs.size());
688 data.bits ^= rhs.data.bits;
689 return *this;
690 }
691
715 constexpr dynamic_bitset operator~() const noexcept
716 {
717 dynamic_bitset tmp{*this};
718 tmp.flip();
719 return tmp;
720 }
721
742 constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
743 {
744 assert(count > 0);
745 assert(count < size());
746 data.bits <<= count;
747 data.bits &= (1ULL << size()) - 1ULL;
748 return *this;
749 }
750
771 constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
772 {
773 assert(count > 0);
774 assert(count < size());
775 data.bits >>= count;
776 return *this;
777 }
778
799 constexpr dynamic_bitset operator>>(size_t const count) const noexcept
800 {
801 assert(count > 0);
802 assert(count < size());
803 dynamic_bitset tmp{*this};
804 tmp >>= count;
805 return tmp;
806 }
807
828 constexpr dynamic_bitset operator<<(size_t const count) const noexcept
829 {
830 assert(count > 0);
831 assert(count < size());
832 dynamic_bitset tmp{*this};
833 tmp <<= count;
834 return tmp;
835 }
836
856 constexpr dynamic_bitset & set() noexcept
857 {
858 data.bits |= (1ULL << size()) - 1ULL;
859 return *this;
860 }
861
884 constexpr dynamic_bitset & set(size_t const i, bool const value = true)
885 {
886 at(i) = value;
887 return *this;
888 }
889
912 constexpr dynamic_bitset & reset() noexcept
913 {
914 data.bits = 0u;
915 return *this;
916 }
917
939 constexpr dynamic_bitset & reset(size_t const i)
940 {
941 set(i, false);
942 return *this;
943 }
944
964 constexpr dynamic_bitset & flip() noexcept
965 {
966 data.bits = ~data.bits;
967 data.bits &= (1ULL << size()) - 1ULL;
968 return *this;
969 }
970
992 constexpr dynamic_bitset & flip(size_t const i)
993 {
994 at(i) ? reset(i) : set(i);
995 return *this;
996 }
998
1007 constexpr bool all() const noexcept
1008 {
1009 return count() == size();
1010 }
1011
1017 constexpr bool any() const noexcept
1018 {
1019 return count() != 0;
1020 }
1021
1027 constexpr bool none() const noexcept
1028 {
1029 return count() == 0;
1030 }
1031
1036 constexpr size_type count() const noexcept
1037 {
1038 return std::popcount(data.bits);
1039 }
1040
1058 constexpr reference at(size_t const i)
1059 {
1060 if (i >= size()) // [[unlikely]]
1061 throw std::out_of_range{"Trying to access position " + std::to_string(i)
1062 + " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
1063 return (*this)[i];
1064 }
1065
1067 constexpr const_reference at(size_t const i) const
1068 {
1069 if (i >= size()) // [[unlikely]]
1070 throw std::out_of_range{"Trying to access position " + std::to_string(i)
1071 + " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
1072 return (*this)[i];
1073 }
1074
1076 constexpr const_reference test(size_t const i) const
1077 {
1078 return at(i);
1079 }
1080
1104 constexpr reference operator[](size_t const i) noexcept
1105 {
1106 assert(i < size());
1107 return {data, i};
1108 }
1109
1111 constexpr const_reference operator[](size_t const i) const noexcept
1112 {
1113 assert(i < size());
1114 return data.bits & 1ULL << i;
1115 }
1116
1135 constexpr reference front() noexcept
1136 {
1137 assert(size() > 0);
1138 return (*this)[0];
1139 }
1140
1142 constexpr const_reference front() const noexcept
1143 {
1144 assert(size() > 0);
1145 return (*this)[0];
1146 }
1147
1165 constexpr reference back() noexcept
1166 {
1167 assert(size() > 0);
1168 return (*this)[size() - 1];
1169 }
1170
1172 constexpr const_reference back() const noexcept
1173 {
1174 assert(size() > 0);
1175 return (*this)[size() - 1];
1176 }
1177
1182 constexpr bitfield * raw_data() noexcept
1183 {
1184 return &data;
1185 }
1186
1188 constexpr bitfield const * raw_data() const noexcept
1189 {
1190 return &data;
1191 }
1193
1212 constexpr bool empty() const noexcept
1213 {
1214 return size() == 0;
1215 }
1216
1232 constexpr size_type size() const noexcept
1233 {
1234 return data.size;
1235 }
1236
1257 constexpr size_type max_size() const noexcept
1258 {
1259 return capacity();
1260 }
1261
1277 constexpr size_type capacity() const noexcept
1278 {
1279 return bit_capacity;
1280 }
1281
1286 constexpr void reserve(size_t) const noexcept
1287 {
1288 // no-op
1289 }
1290
1295 constexpr void shrink_to_fit() const noexcept
1296 {
1297 // no-op
1298 }
1300
1321 constexpr void clear() noexcept
1322 {
1323 data.size &= 0ULL;
1324 data.bits &= 0ULL;
1325 }
1326
1346 constexpr iterator insert(const_iterator pos, value_type const value) noexcept
1347 {
1348 return insert(pos, 1, value);
1349 }
1350
1371 constexpr iterator insert(const_iterator pos, size_type const count, value_type const value) noexcept
1372 {
1373 auto tmp = views::repeat_n(value, count);
1374 return insert(pos, std::ranges::begin(tmp), std::ranges::end(tmp));
1375 }
1376
1401 template <std::forward_iterator begin_it_type, typename end_it_type>
1402 requires std::sentinel_for<end_it_type, begin_it_type>
1403 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
1404 constexpr iterator insert(const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept
1405 {
1406 auto const pos_as_num = std::ranges::distance(cbegin(), pos);
1407 auto const length = std::ranges::distance(begin_it, end_it);
1408
1409 if (length == 0)
1410 return begin(); // nothing to insert
1411
1412 size_type const tmp_size{size()};
1413 resize(tmp_size + length);
1414
1415 for (size_type i = tmp_size + length - 1; i > pos_as_num + length - 1; --i)
1416 (*this)[i] = (*this)[i - length];
1417
1418 // std::ranges::copy(begin_it, end_it, (*this)[pos_as_num]);
1419 for (auto i = pos_as_num; begin_it != end_it; ++i, ++begin_it)
1420 (*this)[i] = *begin_it;
1421
1422 return begin() + pos_as_num;
1423 }
1424
1445 {
1446 return insert(pos, ilist.begin(), ilist.end());
1447 }
1448
1472 constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
1473 {
1474 if (begin_it >= end_it) // [[unlikely]]
1475 return begin() + std::ranges::distance(cbegin(), end_it);
1476
1477 auto const length = std::ranges::distance(begin_it, end_it);
1478 auto out_it = begin() + std::ranges::distance(cbegin(), begin_it);
1479
1480 while (end_it != cend())
1481 *(out_it++) = *(end_it++);
1482
1483 resize(size() - length);
1484 return begin() + std::ranges::distance(cbegin(), begin_it);
1485 }
1486
1509 constexpr iterator erase(const_iterator pos) noexcept
1510 {
1511 return erase(pos, pos + 1);
1512 }
1513
1531 constexpr void push_back(value_type const value) noexcept
1532 {
1533 assert(size() < bit_capacity);
1534 resize(size() + 1);
1535 (*this)[size() - 1] = value;
1536 }
1537
1556 constexpr void pop_back() noexcept
1557 {
1558 assert(size() > 0);
1559 resize(size() - 1);
1560 }
1561
1588 constexpr void resize(size_type const count, value_type const value = false) noexcept
1589 {
1590 assert(count <= bit_capacity);
1591 // Enlarging.
1592 data.bits |= value && count > size() ? ((1ULL << (count - size())) - 1) << size() : 0ULL;
1593 // Set size bits.
1594 data.size = count;
1595 // Shrinking.
1596 data.bits &= (1ULL << size()) - 1ULL;
1597 }
1598
1614 constexpr void swap(dynamic_bitset & rhs) noexcept
1615 {
1616 bitfield tmp = std::move(data);
1617 data = std::move(rhs.data);
1618 rhs.data = std::move(tmp);
1619 }
1620
1622 constexpr void swap(dynamic_bitset && rhs) noexcept
1623 {
1624 data = std::move(rhs.data);
1625 }
1626
1628
1645 friend constexpr void swap(dynamic_bitset & lhs, dynamic_bitset & rhs) noexcept
1646 {
1647 lhs.swap(rhs);
1648 }
1649
1663 template <size_t cap>
1664 requires (cap <= bit_capacity)
1665 friend constexpr dynamic_bitset operator&(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1666 {
1667 assert(lhs.size() == rhs.size());
1668 dynamic_bitset tmp{lhs};
1669 tmp &= rhs;
1670 return tmp;
1671 }
1672
1683 template <size_t cap>
1684 requires (cap <= bit_capacity)
1685 friend constexpr dynamic_bitset operator^(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1686 {
1687 assert(lhs.size() == rhs.size());
1688 dynamic_bitset tmp{lhs};
1689 tmp ^= rhs;
1690 return tmp;
1691 }
1692
1703 template <size_t cap>
1704 requires (cap <= bit_capacity)
1705 friend constexpr dynamic_bitset operator|(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1706 {
1707 assert(lhs.size() == rhs.size());
1708 dynamic_bitset tmp{lhs};
1709 tmp |= rhs;
1710 return tmp;
1711 }
1713
1721 template <size_t cap>
1722 friend constexpr bool operator==(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1723 {
1724 return lhs.data.size == rhs.raw_data()->size && lhs.data.bits == rhs.raw_data()->bits;
1725 }
1726
1731 template <size_t cap>
1732 friend constexpr bool operator!=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1733 {
1734 return !(lhs == rhs);
1735 }
1736
1741 template <size_t cap>
1742 friend constexpr bool operator<(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1743 {
1744 return lhs.data.bits < rhs.raw_data()->bits;
1745 }
1746
1751 template <size_t cap>
1752 friend constexpr bool operator>(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1753 {
1754 return lhs.data.bits > rhs.raw_data()->bits;
1755 }
1756
1761 template <size_t cap>
1762 friend constexpr bool operator<=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1763 {
1764 return !(lhs > rhs);
1765 }
1766
1771 template <size_t cap>
1772 friend constexpr bool operator>=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1773 {
1774 return !(lhs < rhs);
1775 }
1777
1803 template <typename char_t = char>
1804 std::string to_string(char_t zero = char_t{'0'}, char_t one = char_t{'1'}) const
1805 {
1806 std::string str{};
1807 str.reserve(size());
1808 for (bool const bit : std::views::reverse(*this))
1809 bit ? str.push_back(one) : str.push_back(zero);
1810
1811 return str;
1812 }
1813
1830 inline constexpr unsigned long to_ulong() const
1831 {
1833 {
1835 throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long."};
1836 }
1837
1838 return static_cast<unsigned long>(data.bits);
1839 }
1840
1857 inline constexpr unsigned long long to_ullong() const
1858 {
1860 {
1862 throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long long."};
1863 }
1864
1865 return static_cast<unsigned long long>(data.bits);
1866 }
1868
1884 {
1885 os << arg.to_string();
1886 return os;
1887 }
1888
1903 {
1904 // Check if stream is ok and skip leading whitespaces.
1906 if (s)
1907 {
1908 arg.clear(); // clear the bitset
1909 std::streamsize num_char =
1910 (is.width() > 0) ? std::min<std::streamsize>(is.width(), arg.max_size()) : arg.max_size();
1911 assert(num_char > 0);
1912 std::vector<bool> tmp{};
1913 tmp.reserve(num_char);
1914 for (std::streamsize n = num_char; n > 0 && (is.peek() == is.widen('0') || is.peek() == is.widen('1')); --n)
1915 {
1916 char c = is.get();
1917 c == is.widen('0') ? tmp.push_back(false) : tmp.push_back(true);
1918 }
1919
1920 arg.assign(std::views::reverse(tmp));
1921
1922 if (arg.size() == 0) // nothing extracted so we set the fail bit.
1923 is.setstate(std::ios_base::failbit); // LCOV_EXCL_LINE
1924
1925 is.width(0); // cancel the effects of std::setw, if any.
1926 }
1927 return is;
1928 }
1929
1931
1942 template <cereal_archive archive_t>
1943 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
1944 {
1945 uint64_t size = data.size;
1946 archive(size);
1947 data.size = size;
1948 uint64_t bits = data.bits;
1949 archive(bits);
1950 data.bits = bits;
1951 }
1953};
1954
1959template <size_t bit_capacity>
1961{
1968 template <typename stream_t, typename arg_t>
1969 constexpr void operator()(stream_t & stream, arg_t && arg) const
1970 {
1971 stream << (std::string_view{arg.to_string()} | views::interleave(4, std::string_view{"'"})
1973 }
1974};
1975
1976} // namespace seqan3
1977
1978namespace std
1979{
1980
1987template <size_t cap>
1988struct hash<seqan3::dynamic_bitset<cap>>
1989{
1997 size_t operator()(seqan3::dynamic_bitset<cap> const arg) const noexcept
1998 {
1999 return static_cast<size_t>(arg.to_ullong());
2000 }
2001};
2002
2003} //namespace std
T begin(T... args)
T bit_width(T... args)
Adaptions of concepts from the Cereal library.
A generic random access iterator that delegates most operations to the range.
Definition random_access_iterator.hpp:288
Proxy data type returned by seqan3::dynamic_bitset as reference to the bit.
Definition dynamic_bitset.hpp:73
uint64_t mask
Bitmask to access one specific bit.
Definition dynamic_bitset.hpp:147
~reference_proxy_type() noexcept=default
Defaulted.
constexpr bool operator~() const noexcept
Returns the inverted value of the referenced bit.
Definition dynamic_bitset.hpp:113
bitfield & internal
The proxy of the underlying data type.
Definition dynamic_bitset.hpp:145
constexpr reference_proxy_type & operator=(bool const value) noexcept
Sets the referenced bit to value.
Definition dynamic_bitset.hpp:90
constexpr reference_proxy_type & operator&=(bool const value)
Sets the referenced bit to the result of a binary AND with value.
Definition dynamic_bitset.hpp:128
constexpr void reset() noexcept
Sets the referenced bit to 0.
Definition dynamic_bitset.hpp:156
constexpr void set() noexcept
Sets the referenced bit to 1.
Definition dynamic_bitset.hpp:150
constexpr reference_proxy_type & operator|=(bool const value)
Sets the referenced bit to the result of a binary OR with value.
Definition dynamic_bitset.hpp:119
constexpr reference_proxy_type() noexcept=default
Defaulted.
constexpr reference_proxy_type & operator^=(bool const value)
Sets the referenced bit to the result of a binary XOR with value.
Definition dynamic_bitset.hpp:137
A constexpr bitset implementation with dynamic size at compile time.
Definition dynamic_bitset.hpp:53
constexpr dynamic_bitset operator<<(size_t const count) const noexcept
Performs binary shift left.
Definition dynamic_bitset.hpp:828
friend class dynamic_bitset
Befriend other template instantiations of dynamic_bitset.
Definition dynamic_bitset.hpp:57
constexpr iterator insert(const_iterator pos, value_type const value) noexcept
Inserts value before pos in the container.
Definition dynamic_bitset.hpp:1346
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition dynamic_bitset.hpp:1232
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:1444
constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
Performs binary shift left on the current object.
Definition dynamic_bitset.hpp:742
constexpr bool any() const noexcept
Checks if any bit is set.
Definition dynamic_bitset.hpp:1017
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition dynamic_bitset.hpp:1588
friend constexpr bool operator<(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1742
constexpr const_reference test(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1076
constexpr reference back() noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1165
friend std::istream & operator>>(std::istream &is, dynamic_bitset &arg)
Formatted input for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1902
constexpr void clear() noexcept
Removes all elements from the container.
Definition dynamic_bitset.hpp:1321
constexpr size_type count() const noexcept
Returns the number of set bits.
Definition dynamic_bitset.hpp:1036
constexpr reference front() noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1135
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition dynamic_bitset.hpp:1212
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:1257
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1295
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:625
constexpr bool all() const noexcept
Checks if all bit are set.
Definition dynamic_bitset.hpp:1007
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition dynamic_bitset.hpp:964
friend constexpr bool operator==(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1722
constexpr void assign(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:418
constexpr const_iterator begin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:560
constexpr unsigned long to_ulong() const
Converts the dynamic_bitset to an unsigned long integer.
Definition dynamic_bitset.hpp:1830
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
Assign from pair of iterators.
Definition dynamic_bitset.hpp:534
constexpr void swap(dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1614
constexpr dynamic_bitset(other_range_t &&range) noexcept
Construct from a different range.
Definition dynamic_bitset.hpp:295
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:1622
constexpr dynamic_bitset(char const (&lit)[N])
Construction from literal.
Definition dynamic_bitset.hpp:365
constexpr reference at(size_t const i)
Returns the i-th element.
Definition dynamic_bitset.hpp:1058
constexpr dynamic_bitset & operator=(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:335
bitfield data
Stores the actual data.
Definition dynamic_bitset.hpp:69
constexpr dynamic_bitset & reset(size_t const i)
Sets the i'th bit to false.
Definition dynamic_bitset.hpp:939
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1509
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:1277
constexpr bitfield const * raw_data() const noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1188
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition dynamic_bitset.hpp:1531
constexpr const_iterator cbegin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:566
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:1404
constexpr dynamic_bitset operator>>(size_t const count) const noexcept
Performs binary shift right.
Definition dynamic_bitset.hpp:799
constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept
Construct from two iterators.
Definition dynamic_bitset.hpp:271
constexpr const_reference operator[](size_t const i) const noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1111
constexpr unsigned long long to_ullong() const
Converts the dynamic_bitset to an unsigned long long integer.
Definition dynamic_bitset.hpp:1857
constexpr const_reference back() const noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1172
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition dynamic_bitset.hpp:856
constexpr bitfield * raw_data() noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1182
friend std::ostream & operator<<(std::ostream &os, dynamic_bitset const &arg)
Formatted output for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1883
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:581
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition dynamic_bitset.hpp:1556
constexpr const_reference at(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1067
friend constexpr bool operator>=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1772
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:554
constexpr void assign(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:460
constexpr dynamic_bitset & set(size_t const i, bool const value=true)
Sets the i'th bit to value.
Definition dynamic_bitset.hpp:884
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition dynamic_bitset.hpp:912
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:593
constexpr bool none() const noexcept
Checks if no bit is set.
Definition dynamic_bitset.hpp:1027
constexpr dynamic_bitset operator~() const noexcept
Returns a temporary copy of *this with all bits flipped (binary NOT).
Definition dynamic_bitset.hpp:715
bool const_reference
Equals the value_type.
Definition dynamic_bitset.hpp:184
constexpr const_iterator end() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:587
constexpr dynamic_bitset & operator=(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:391
friend constexpr void swap(dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1645
constexpr void assign(size_type const count, value_type const value) noexcept
Assign with count times value.
Definition dynamic_bitset.hpp:481
ptrdiff_t difference_type
A std::ptrdiff_t.
Definition dynamic_bitset.hpp:202
constexpr dynamic_bitset() noexcept=default
Defaulted.
constexpr const_reference front() const noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1142
constexpr void assign(other_range_t &&range) noexcept
Assign from a different range.
Definition dynamic_bitset.hpp:507
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:1804
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:685
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1472
constexpr void reserve(size_t) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1286
constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
Performs binary shift right on the current object.
Definition dynamic_bitset.hpp:771
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:655
friend constexpr bool operator<=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1762
constexpr dynamic_bitset(size_type const n, value_type const value) noexcept
Construct with n times value.
Definition dynamic_bitset.hpp:315
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:1371
bool value_type
Equals bool.
Definition dynamic_bitset.hpp:172
constexpr reference operator[](size_t const i) noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1104
friend constexpr bool operator>(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1752
friend constexpr bool operator!=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1732
constexpr dynamic_bitset & flip(size_t const i)
Flips the i'th bit (binary NOT).
Definition dynamic_bitset.hpp:992
Implementation of a masked alphabet to be used for tuple composites.
Definition mask.hpp:35
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 max(T... args)
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
SeqAn specific customisations in the standard namespace.
T peek(T... args)
#define CEREAL_SERIALIZE_FUNCTION_NAME
Macro for Cereal's serialize function.
Definition platform.hpp:154
T popcount(T... args)
Provides seqan3::views::repeat_n.
T reserve(T... args)
T reverse(T... args)
T setstate(T... args)
A bit field representing size and bit information stored in one uint64_t.
Definition dynamic_bitset.hpp:61
uint64_t bits
58 bits representing the bit information.
Definition dynamic_bitset.hpp:65
uint64_t size
6 bits representing the size information.
Definition dynamic_bitset.hpp:63
constexpr void operator()(stream_t &stream, arg_t &&arg) const
Prints the dynamic bitset.
Definition dynamic_bitset.hpp:1969
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:1997
Provides seqan3::ranges::to.
T to_string(T... args)
T widen(T... args)
T width(T... args)
Hide me