SeqAn3 3.4.0-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-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <bit>
13
20
21namespace seqan3
22{
23
49template <size_t bit_capacity = 58>
51{
52private:
54 template <size_t>
55 friend class dynamic_bitset;
56
58 struct bitfield
59 {
61 uint64_t size : 6u;
63 uint64_t bits : 58u;
64 };
65
67 bitfield data{0u, 0u}; // Specifying values prevents ICE on gcc < 9 when comparing to default constructed bitset
68
70 class reference_proxy_type
71 {
72 public:
76 constexpr reference_proxy_type() noexcept = default;
77 constexpr reference_proxy_type(reference_proxy_type const &) noexcept = default;
78 constexpr reference_proxy_type(reference_proxy_type &&) noexcept = default;
79
81 constexpr reference_proxy_type & operator=(reference_proxy_type const rhs) noexcept
82 {
83 rhs ? set() : reset();
84 return *this;
85 }
86
88 constexpr reference_proxy_type & operator=(bool const value) noexcept
89 {
90 value ? set() : reset();
91 return *this;
92 }
93
94 ~reference_proxy_type() noexcept = default;
95
97
99 constexpr reference_proxy_type(bitfield & internal_, size_t const pos) noexcept :
100 internal{internal_},
101 mask{1ULL << pos}
102 {}
103
105 constexpr operator bool() const noexcept
106 {
107 return static_cast<bool>(internal.bits & mask);
108 }
109
111 constexpr bool operator~() const noexcept
112 {
113 return !static_cast<bool>(internal.bits & mask);
114 }
115
117 constexpr reference_proxy_type & operator|=(bool const value)
118 {
119 if (value)
120 set();
121
122 return *this;
123 }
124
126 constexpr reference_proxy_type & operator&=(bool const value)
127 {
128 if (!value)
129 reset();
130
131 return *this;
132 }
133
135 constexpr reference_proxy_type & operator^=(bool const value)
136 {
137 operator bool() && value ? reset() : set();
138 return *this;
139 }
140
141 private:
143 bitfield & internal;
145 uint64_t mask;
146
148 constexpr void set() noexcept
149 {
150 internal.bits |= mask;
151 }
152
154 constexpr void reset() noexcept
155 {
156 internal.bits &= ~mask;
157 }
158 };
159
160public:
161 static_assert(bit_capacity <= 58, "The capacity of the dynamic_bitset exceeds the limit of 58.");
162
170 using value_type = bool;
171
176 using reference = reference_proxy_type;
177
182 using const_reference = bool;
183
188 using iterator = detail::random_access_iterator<dynamic_bitset>;
189
194 using const_iterator = detail::random_access_iterator<dynamic_bitset const>;
195
200 using difference_type = ptrdiff_t;
201
208
212 constexpr dynamic_bitset() noexcept = default;
213 constexpr dynamic_bitset(dynamic_bitset const &) noexcept = default;
214 constexpr dynamic_bitset(dynamic_bitset &&) noexcept = default;
215 constexpr dynamic_bitset & operator=(dynamic_bitset const &) noexcept = default;
216 constexpr dynamic_bitset & operator=(dynamic_bitset &&) noexcept = default;
217 ~dynamic_bitset() noexcept = default;
218
239 constexpr dynamic_bitset(uint64_t const value)
240 {
241 if (std::popcount(value >> 58u) != 0u)
242 throw std::invalid_argument{"The dynamic_bitset can be at most 58 long."};
243 data.bits |= value;
244 data.size |= std::bit_width(value);
245 }
246
266 template <std::forward_iterator begin_it_type, typename end_it_type>
267 requires std::sentinel_for<end_it_type, begin_it_type>
268 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
269 constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept : dynamic_bitset{}
270 {
271 assign(begin_it, end_it);
272 }
273
291 template <std::ranges::input_range other_range_t>
292 requires (!std::same_as<std::remove_cvref_t<other_range_t>, dynamic_bitset>)
293 explicit constexpr dynamic_bitset(other_range_t && range) noexcept :
294 dynamic_bitset{std::ranges::begin(range), std::ranges::end(range)}
295 {}
296
313 constexpr dynamic_bitset(size_type const n, value_type const value) noexcept : dynamic_bitset{}
314 {
315 assign(n, value);
316 }
317
334 {
335 assign(std::ranges::begin(ilist), std::ranges::end(ilist));
336 return *this;
337 }
338
362 template <size_t N>
363 constexpr dynamic_bitset(char const (&lit)[N]) : dynamic_bitset{}
364 {
365 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
366 assign(lit);
367 }
368
388 template <size_t N>
389 constexpr dynamic_bitset & operator=(char const (&lit)[N])
390 {
391 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
392 assign(lit);
393 return *this;
394 }
395
415 template <size_t N>
416 constexpr void assign(char const (&lit)[N])
417 {
418 static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
419 assert(lit[N - 1] == '\0');
420 uint64_t value{};
421
422 for (size_t i = 0; i != N - 1; ++i)
423 {
424 if (lit[i] == '0')
425 {
426 value <<= 1;
427 }
428 else if (lit[i] == '1')
429 {
430 value <<= 1;
431 value |= 1u;
432 }
433 else
434 {
435 throw std::invalid_argument{"The string to construct a dynamic_bitset from may only contain 0 and 1."};
436 }
437 }
438
439 *this = value;
440 resize(N - 1);
441 }
442
458 constexpr void assign(std::initializer_list<value_type> const ilist) noexcept
459 {
460 assign(std::ranges::begin(ilist), std::ranges::end(ilist));
461 }
462
479 constexpr void assign(size_type const count, value_type const value) noexcept
480 {
481 clear();
482 auto tmp = views::repeat_n(value, count);
483 assign(std::ranges::begin(tmp), std::ranges::end(tmp));
484 }
485
503 template <std::ranges::input_range other_range_t>
504 requires std::constructible_from<value_type, std::ranges::range_reference_t<other_range_t>>
505 constexpr void assign(other_range_t && range) noexcept
506 {
507 assign(std::ranges::begin(range), std::ranges::end(range));
508 }
509
529 template <std::forward_iterator begin_it_type, typename end_it_type>
530 requires std::sentinel_for<end_it_type, begin_it_type>
531 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
532 constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
533 {
534 clear();
535 insert(cbegin(), begin_it, end_it);
536 }
538
552 constexpr iterator begin() noexcept
553 {
554 return iterator{*this};
555 }
556
558 constexpr const_iterator begin() const noexcept
559 {
560 return const_iterator{*this};
561 }
562
564 constexpr const_iterator cbegin() const noexcept
565 {
566 return begin();
567 }
568
579 constexpr iterator end() noexcept
580 {
581 return iterator{*this, size()};
582 }
583
585 constexpr const_iterator end() const noexcept
586 {
587 return const_iterator{*this, size()};
588 }
589
591 constexpr const_iterator cend() const noexcept
592 {
593 return end();
594 }
596
623 constexpr dynamic_bitset & operator&=(dynamic_bitset const & rhs) noexcept
624 {
625 assert(size() == rhs.size());
626 data.bits &= rhs.data.bits;
627 return *this;
628 }
629
653 constexpr dynamic_bitset & operator|=(dynamic_bitset const & rhs) noexcept
654 {
655 assert(size() == rhs.size());
656 data.bits |= rhs.data.bits;
657 return *this;
658 }
659
683 constexpr dynamic_bitset & operator^=(dynamic_bitset const & rhs) noexcept
684 {
685 assert(size() == rhs.size());
686 data.bits ^= rhs.data.bits;
687 return *this;
688 }
689
713 constexpr dynamic_bitset operator~() const noexcept
714 {
715 dynamic_bitset tmp{*this};
716 tmp.flip();
717 return tmp;
718 }
719
740 constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
741 {
742 assert(count > 0);
743 assert(count < size());
744 data.bits <<= count;
745 data.bits &= (1ULL << size()) - 1ULL;
746 return *this;
747 }
748
769 constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
770 {
771 assert(count > 0);
772 assert(count < size());
773 data.bits >>= count;
774 return *this;
775 }
776
797 constexpr dynamic_bitset operator>>(size_t const count) const noexcept
798 {
799 assert(count > 0);
800 assert(count < size());
801 dynamic_bitset tmp{*this};
802 tmp >>= count;
803 return tmp;
804 }
805
826 constexpr dynamic_bitset operator<<(size_t const count) const noexcept
827 {
828 assert(count > 0);
829 assert(count < size());
830 dynamic_bitset tmp{*this};
831 tmp <<= count;
832 return tmp;
833 }
834
854 constexpr dynamic_bitset & set() noexcept
855 {
856 data.bits |= (1ULL << size()) - 1ULL;
857 return *this;
858 }
859
882 constexpr dynamic_bitset & set(size_t const i, bool const value = true)
883 {
884 at(i) = value;
885 return *this;
886 }
887
910 constexpr dynamic_bitset & reset() noexcept
911 {
912 data.bits = 0u;
913 return *this;
914 }
915
937 constexpr dynamic_bitset & reset(size_t const i)
938 {
939 set(i, false);
940 return *this;
941 }
942
962 constexpr dynamic_bitset & flip() noexcept
963 {
964 data.bits = ~data.bits;
965 data.bits &= (1ULL << size()) - 1ULL;
966 return *this;
967 }
968
990 constexpr dynamic_bitset & flip(size_t const i)
991 {
992 at(i) ? reset(i) : set(i);
993 return *this;
994 }
996
1005 constexpr bool all() const noexcept
1006 {
1007 return count() == size();
1008 }
1009
1015 constexpr bool any() const noexcept
1016 {
1017 return count() != 0;
1018 }
1019
1025 constexpr bool none() const noexcept
1026 {
1027 return count() == 0;
1028 }
1029
1034 constexpr size_type count() const noexcept
1035 {
1036 return std::popcount(data.bits);
1037 }
1038
1056 constexpr reference at(size_t const i)
1057 {
1058 if (i >= size()) // [[unlikely]]
1059 throw std::out_of_range{"Trying to access position " + std::to_string(i)
1060 + " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
1061 return (*this)[i];
1062 }
1063
1065 constexpr const_reference at(size_t const i) const
1066 {
1067 if (i >= size()) // [[unlikely]]
1068 throw std::out_of_range{"Trying to access position " + std::to_string(i)
1069 + " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
1070 return (*this)[i];
1071 }
1072
1074 constexpr const_reference test(size_t const i) const
1075 {
1076 return at(i);
1077 }
1078
1102 constexpr reference operator[](size_t const i) noexcept
1103 {
1104 assert(i < size());
1105 return {data, i};
1106 }
1107
1109 constexpr const_reference operator[](size_t const i) const noexcept
1110 {
1111 assert(i < size());
1112 return data.bits & 1ULL << i;
1113 }
1114
1133 constexpr reference front() noexcept
1134 {
1135 assert(size() > 0);
1136 return (*this)[0];
1137 }
1138
1140 constexpr const_reference front() const noexcept
1141 {
1142 assert(size() > 0);
1143 return (*this)[0];
1144 }
1145
1163 constexpr reference back() noexcept
1164 {
1165 assert(size() > 0);
1166 return (*this)[size() - 1];
1167 }
1168
1170 constexpr const_reference back() const noexcept
1171 {
1172 assert(size() > 0);
1173 return (*this)[size() - 1];
1174 }
1175
1180 constexpr bitfield * raw_data() noexcept
1181 {
1182 return &data;
1183 }
1184
1186 constexpr bitfield const * raw_data() const noexcept
1187 {
1188 return &data;
1189 }
1191
1210 constexpr bool empty() const noexcept
1211 {
1212 return size() == 0;
1213 }
1214
1230 constexpr size_type size() const noexcept
1231 {
1232 return data.size;
1233 }
1234
1255 constexpr size_type max_size() const noexcept
1256 {
1257 return capacity();
1258 }
1259
1275 constexpr size_type capacity() const noexcept
1276 {
1277 return bit_capacity;
1278 }
1279
1284 constexpr void reserve(size_t) const noexcept
1285 {
1286 // no-op
1287 }
1288
1293 constexpr void shrink_to_fit() const noexcept
1294 {
1295 // no-op
1296 }
1298
1319 constexpr void clear() noexcept
1320 {
1321 data.size &= 0ULL;
1322 data.bits &= 0ULL;
1323 }
1324
1344 constexpr iterator insert(const_iterator pos, value_type const value) noexcept
1345 {
1346 return insert(pos, 1, value);
1347 }
1348
1369 constexpr iterator insert(const_iterator pos, size_type const count, value_type const value) noexcept
1370 {
1371 auto tmp = views::repeat_n(value, count);
1372 return insert(pos, std::ranges::begin(tmp), std::ranges::end(tmp));
1373 }
1374
1399 template <std::forward_iterator begin_it_type, typename end_it_type>
1400 requires std::sentinel_for<end_it_type, begin_it_type>
1401 && std::constructible_from<value_type, std::iter_reference_t<begin_it_type>>
1402 constexpr iterator insert(const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept
1403 {
1404 auto const pos_as_num = std::ranges::distance(cbegin(), pos);
1405 auto const length = std::ranges::distance(begin_it, end_it);
1406
1407 if (length == 0)
1408 return begin(); // nothing to insert
1409
1410 size_type const tmp_size{size()};
1411 resize(tmp_size + length);
1412
1413 for (size_type i = tmp_size + length - 1; i > pos_as_num + length - 1; --i)
1414 (*this)[i] = (*this)[i - length];
1415
1416 // std::ranges::copy(begin_it, end_it, (*this)[pos_as_num]);
1417 for (auto i = pos_as_num; begin_it != end_it; ++i, ++begin_it)
1418 (*this)[i] = *begin_it;
1419
1420 return begin() + pos_as_num;
1421 }
1422
1443 {
1444 return insert(pos, ilist.begin(), ilist.end());
1445 }
1446
1470 constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
1471 {
1472 if (begin_it >= end_it) // [[unlikely]]
1473 return begin() + std::ranges::distance(cbegin(), end_it);
1474
1475 auto const length = std::ranges::distance(begin_it, end_it);
1476 auto out_it = begin() + std::ranges::distance(cbegin(), begin_it);
1477
1478 while (end_it != cend())
1479 *(out_it++) = *(end_it++);
1480
1481 resize(size() - length);
1482 return begin() + std::ranges::distance(cbegin(), begin_it);
1483 }
1484
1507 constexpr iterator erase(const_iterator pos) noexcept
1508 {
1509 return erase(pos, pos + 1);
1510 }
1511
1529 constexpr void push_back(value_type const value) noexcept
1530 {
1531 assert(size() < bit_capacity);
1532 resize(size() + 1);
1533 (*this)[size() - 1] = value;
1534 }
1535
1554 constexpr void pop_back() noexcept
1555 {
1556 assert(size() > 0);
1557 resize(size() - 1);
1558 }
1559
1586 constexpr void resize(size_type const count, value_type const value = false) noexcept
1587 {
1588 assert(count <= bit_capacity);
1589 // Enlarging.
1590 data.bits |= value && count > size() ? ((1ULL << (count - size())) - 1) << size() : 0ULL;
1591 // Set size bits.
1592 data.size = count;
1593 // Shrinking.
1594 data.bits &= (1ULL << size()) - 1ULL;
1595 }
1596
1612 constexpr void swap(dynamic_bitset & rhs) noexcept
1613 {
1614 bitfield tmp = std::move(data);
1615 data = std::move(rhs.data);
1616 rhs.data = std::move(tmp);
1617 }
1618
1620 constexpr void swap(dynamic_bitset && rhs) noexcept
1621 {
1622 data = std::move(rhs.data);
1623 }
1624
1626
1643 friend constexpr void swap(dynamic_bitset & lhs, dynamic_bitset & rhs) noexcept
1644 {
1645 lhs.swap(rhs);
1646 }
1647
1661 template <size_t cap>
1662 requires (cap <= bit_capacity)
1663 friend constexpr dynamic_bitset operator&(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1664 {
1665 assert(lhs.size() == rhs.size());
1666 dynamic_bitset tmp{lhs};
1667 tmp &= rhs;
1668 return tmp;
1669 }
1670
1681 template <size_t cap>
1682 requires (cap <= bit_capacity)
1683 friend constexpr dynamic_bitset operator^(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1684 {
1685 assert(lhs.size() == rhs.size());
1686 dynamic_bitset tmp{lhs};
1687 tmp ^= rhs;
1688 return tmp;
1689 }
1690
1701 template <size_t cap>
1702 requires (cap <= bit_capacity)
1703 friend constexpr dynamic_bitset operator|(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1704 {
1705 assert(lhs.size() == rhs.size());
1706 dynamic_bitset tmp{lhs};
1707 tmp |= rhs;
1708 return tmp;
1709 }
1711
1719 template <size_t cap>
1720 friend constexpr bool operator==(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1721 {
1722 return lhs.data.size == rhs.raw_data()->size && lhs.data.bits == rhs.raw_data()->bits;
1723 }
1724
1729 template <size_t cap>
1730 friend constexpr bool operator!=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1731 {
1732 return !(lhs == rhs);
1733 }
1734
1739 template <size_t cap>
1740 friend constexpr bool operator<(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1741 {
1742 return lhs.data.bits < rhs.raw_data()->bits;
1743 }
1744
1749 template <size_t cap>
1750 friend constexpr bool operator>(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1751 {
1752 return lhs.data.bits > rhs.raw_data()->bits;
1753 }
1754
1759 template <size_t cap>
1760 friend constexpr bool operator<=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1761 {
1762 return !(lhs > rhs);
1763 }
1764
1769 template <size_t cap>
1770 friend constexpr bool operator>=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1771 {
1772 return !(lhs < rhs);
1773 }
1775
1801 template <typename char_t = char>
1802 std::string to_string(char_t zero = char_t{'0'}, char_t one = char_t{'1'}) const
1803 {
1804 std::string str{};
1805 str.reserve(size());
1806 for (bool const bit : std::views::reverse(*this))
1807 bit ? str.push_back(one) : str.push_back(zero);
1808
1809 return str;
1810 }
1811
1828 inline constexpr unsigned long to_ulong() const
1829 {
1831 {
1833 throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long."};
1834 }
1835
1836 return static_cast<unsigned long>(data.bits);
1837 }
1838
1855 inline constexpr unsigned long long to_ullong() const
1856 {
1858 {
1860 throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long long."};
1861 }
1862
1863 return static_cast<unsigned long long>(data.bits);
1864 }
1866
1882 {
1883 os << arg.to_string();
1884 return os;
1885 }
1886
1901 {
1902 // Check if stream is ok and skip leading whitespaces.
1904 if (s)
1905 {
1906 arg.clear(); // clear the bitset
1907 std::streamsize num_char =
1908 (is.width() > 0) ? std::min<std::streamsize>(is.width(), arg.max_size()) : arg.max_size();
1909 assert(num_char > 0);
1910 std::vector<bool> tmp{};
1911 tmp.reserve(num_char);
1912 for (std::streamsize n = num_char; n > 0 && (is.peek() == is.widen('0') || is.peek() == is.widen('1')); --n)
1913 {
1914 char c = is.get();
1915 c == is.widen('0') ? tmp.push_back(false) : tmp.push_back(true);
1916 }
1917
1918 arg.assign(std::views::reverse(tmp));
1919
1920 if (arg.size() == 0) // nothing extracted so we set the fail bit.
1921 is.setstate(std::ios_base::failbit); // LCOV_EXCL_LINE
1922
1923 is.width(0); // cancel the effects of std::setw, if any.
1924 }
1925 return is;
1926 }
1927
1939 template <typename char_t>
1947
1949
1960 template <cereal_archive archive_t>
1961 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
1962 {
1963 uint64_t size = data.size;
1964 archive(size);
1965 data.size = size;
1966 uint64_t bits = data.bits;
1967 archive(bits);
1968 data.bits = bits;
1969 }
1971};
1972
1973} // namespace seqan3
1974
1975namespace std
1976{
1977
1984template <size_t cap>
1985struct hash<seqan3::dynamic_bitset<cap>>
1986{
1994 size_t operator()(seqan3::dynamic_bitset<cap> const arg) const noexcept
1995 {
1996 return static_cast<size_t>(arg.to_ullong());
1997 }
1998};
1999
2000} //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:75
A constexpr bitset implementation with dynamic size at compile time.
Definition dynamic_bitset.hpp:51
constexpr dynamic_bitset operator<<(size_t const count) const noexcept
Performs binary shift left.
Definition dynamic_bitset.hpp:826
friend class dynamic_bitset
Befriend other template instantiations of dynamic_bitset.
Definition dynamic_bitset.hpp:55
constexpr iterator insert(const_iterator pos, value_type const value) noexcept
Inserts value before pos in the container.
Definition dynamic_bitset.hpp:1344
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition dynamic_bitset.hpp:1230
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:1442
constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
Performs binary shift left on the current object.
Definition dynamic_bitset.hpp:740
constexpr bool any() const noexcept
Checks if any bit is set.
Definition dynamic_bitset.hpp:1015
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition dynamic_bitset.hpp:1586
friend constexpr bool operator<(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1740
constexpr const_reference test(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1074
constexpr reference back() noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1163
friend std::istream & operator>>(std::istream &is, dynamic_bitset &arg)
Formatted input for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1900
constexpr void clear() noexcept
Removes all elements from the container.
Definition dynamic_bitset.hpp:1319
constexpr size_type count() const noexcept
Returns the number of set bits.
Definition dynamic_bitset.hpp:1034
constexpr reference front() noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1133
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition dynamic_bitset.hpp:1210
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:1255
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1293
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:623
constexpr bool all() const noexcept
Checks if all bit are set.
Definition dynamic_bitset.hpp:1005
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition dynamic_bitset.hpp:962
friend constexpr bool operator==(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1720
reference_proxy_type reference
A proxy type that enables assignment.
Definition dynamic_bitset.hpp:176
constexpr void assign(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:416
constexpr const_iterator begin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:558
constexpr unsigned long to_ulong() const
Converts the dynamic_bitset to an unsigned long integer.
Definition dynamic_bitset.hpp:1828
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
Assign from pair of iterators.
Definition dynamic_bitset.hpp:532
constexpr void swap(dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1612
constexpr dynamic_bitset(other_range_t &&range) noexcept
Construct from a different range.
Definition dynamic_bitset.hpp:293
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:1620
constexpr dynamic_bitset(char const (&lit)[N])
Construction from literal.
Definition dynamic_bitset.hpp:363
constexpr reference at(size_t const i)
Returns the i-th element.
Definition dynamic_bitset.hpp:1056
constexpr dynamic_bitset & operator=(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:333
constexpr dynamic_bitset & reset(size_t const i)
Sets the i'th bit to false.
Definition dynamic_bitset.hpp:937
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1507
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:1275
constexpr bitfield const * raw_data() const noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1186
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition dynamic_bitset.hpp:1529
constexpr const_iterator cbegin() const noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:564
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:1402
constexpr dynamic_bitset operator>>(size_t const count) const noexcept
Performs binary shift right.
Definition dynamic_bitset.hpp:797
constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept
Construct from two iterators.
Definition dynamic_bitset.hpp:269
constexpr const_reference operator[](size_t const i) const noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1109
constexpr unsigned long long to_ullong() const
Converts the dynamic_bitset to an unsigned long long integer.
Definition dynamic_bitset.hpp:1855
constexpr const_reference back() const noexcept
Returns the last element.
Definition dynamic_bitset.hpp:1170
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition dynamic_bitset.hpp:854
constexpr bitfield * raw_data() noexcept
Direct access to the underlying bit field.
Definition dynamic_bitset.hpp:1180
friend std::ostream & operator<<(std::ostream &os, dynamic_bitset const &arg)
Formatted output for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1881
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:579
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition dynamic_bitset.hpp:1554
constexpr const_reference at(size_t const i) const
Returns the i-th element.
Definition dynamic_bitset.hpp:1065
friend constexpr bool operator>=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1770
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition dynamic_bitset.hpp:552
constexpr void assign(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition dynamic_bitset.hpp:458
constexpr dynamic_bitset & set(size_t const i, bool const value=true)
Sets the i'th bit to value.
Definition dynamic_bitset.hpp:882
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition dynamic_bitset.hpp:910
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:591
constexpr bool none() const noexcept
Checks if no bit is set.
Definition dynamic_bitset.hpp:1025
constexpr dynamic_bitset operator~() const noexcept
Returns a temporary copy of *this with all bits flipped (binary NOT).
Definition dynamic_bitset.hpp:713
bool const_reference
Equals the value_type.
Definition dynamic_bitset.hpp:182
constexpr const_iterator end() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition dynamic_bitset.hpp:585
constexpr dynamic_bitset & operator=(char const (&lit)[N])
Assign from literal.
Definition dynamic_bitset.hpp:389
friend constexpr void swap(dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition dynamic_bitset.hpp:1643
constexpr void assign(size_type const count, value_type const value) noexcept
Assign with count times value.
Definition dynamic_bitset.hpp:479
ptrdiff_t difference_type
A std::ptrdiff_t.
Definition dynamic_bitset.hpp:200
constexpr dynamic_bitset() noexcept=default
Defaulted.
constexpr const_reference front() const noexcept
Returns the first element.
Definition dynamic_bitset.hpp:1140
constexpr void assign(other_range_t &&range) noexcept
Assign from a different range.
Definition dynamic_bitset.hpp:505
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:1802
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:683
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition dynamic_bitset.hpp:1470
friend debug_stream_type< char_t > & operator<<(debug_stream_type< char_t > &s, dynamic_bitset arg)
Formatted debug output for the seqan3::dynamic_bitset.
Definition dynamic_bitset.hpp:1940
constexpr void reserve(size_t) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition dynamic_bitset.hpp:1284
constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
Performs binary shift right on the current object.
Definition dynamic_bitset.hpp:769
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:653
friend constexpr bool operator<=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1760
detail::random_access_iterator< dynamic_bitset > iterator
The iterator type of this container (a random access iterator).
Definition dynamic_bitset.hpp:188
constexpr dynamic_bitset(size_type const n, value_type const value) noexcept
Construct with n times value.
Definition dynamic_bitset.hpp:313
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:1369
bool value_type
Equals bool.
Definition dynamic_bitset.hpp:170
detail::random_access_iterator< dynamic_bitset const > const_iterator
The const_iterator type of this container (a random access iterator).
Definition dynamic_bitset.hpp:194
constexpr reference operator[](size_t const i) noexcept
Returns the i-th element.
Definition dynamic_bitset.hpp:1102
friend constexpr bool operator>(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1750
friend constexpr bool operator!=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition dynamic_bitset.hpp:1730
constexpr dynamic_bitset & flip(size_t const i)
Flips the i'th bit (binary NOT).
Definition dynamic_bitset.hpp:990
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:376
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 operator()(T... args)
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)
Provides seqan3::ranges::to.
T to_string(T... args)
T widen(T... args)
T width(T... args)
Hide me