SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
dynamic_bitset.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
21 
22 namespace seqan3
23 {
24 
48 template <size_t bit_capacity = 58>
50 {
51 private:
53  template <size_t>
54  friend class dynamic_bitset;
55 
57  struct bitfield
58  {
60  uint64_t size : 6u;
62  uint64_t bits : 58u;
63  };
64 
66  bitfield data{0u, 0u}; // Specifying values prevents ICE on gcc < 9 when comparing to default constructed bitset
67 
69  class reference_proxy_type
70  {
71  public:
75  constexpr reference_proxy_type() noexcept = default;
76  constexpr reference_proxy_type(reference_proxy_type const &) noexcept = default;
77  constexpr reference_proxy_type(reference_proxy_type &&) noexcept = default;
78 
80  constexpr reference_proxy_type & operator=(reference_proxy_type const rhs) noexcept
81  {
82  rhs ? set() : reset();
83  return *this;
84  }
85 
87  constexpr reference_proxy_type & operator=(bool const value) noexcept
88  {
89  value ? set() : reset();
90  return *this;
91  }
92 
93  ~reference_proxy_type() noexcept = default;
94 
97  constexpr reference_proxy_type(bitfield & internal_, size_t const pos) noexcept :
98  internal{internal_}, mask{1ULL<<pos}
99  {}
100 
102  constexpr operator bool() const noexcept
103  {
104  return static_cast<bool>(internal.bits & mask);
105  }
106 
108  constexpr bool operator~() const noexcept
109  {
110  return !static_cast<bool>(internal.bits & mask);
111  }
112 
114  constexpr reference_proxy_type & operator|=(bool const value)
115  {
116  if (value)
117  set();
118 
119  return *this;
120  }
121 
123  constexpr reference_proxy_type & operator&=(bool const value)
124  {
125  if (!value)
126  reset();
127 
128  return *this;
129  }
130 
132  constexpr reference_proxy_type & operator^=(bool const value)
133  {
134  operator bool() && value ? reset() : set();
135  return *this;
136  }
137 
138  private:
140  bitfield & internal;
142  uint64_t mask;
143 
145  constexpr void set() noexcept
146  {
147  internal.bits |= mask;
148  }
149 
151  constexpr void reset() noexcept
152  {
153  internal.bits &= ~mask;
154  }
155  };
156 
157 public:
158  static_assert(bit_capacity <= 58, "The capacity of the dynamic_bitset exceeds the limit of 58.");
159 
163  using value_type = bool;
166  using reference = reference_proxy_type;
168  using const_reference = bool;
170  using iterator = detail::random_access_iterator<dynamic_bitset>;
172  using const_iterator = detail::random_access_iterator<dynamic_bitset const>;
174  using difference_type = ptrdiff_t;
178 
180  // this signals to range-v3 that something is a container :|
181  using allocator_type = void;
183 
187  constexpr dynamic_bitset() noexcept = default;
188  constexpr dynamic_bitset(dynamic_bitset const &) noexcept = default;
189  constexpr dynamic_bitset(dynamic_bitset &&) noexcept = default;
190  constexpr dynamic_bitset & operator=(dynamic_bitset const &) noexcept = default;
191  constexpr dynamic_bitset & operator=(dynamic_bitset &&) noexcept = default;
192  ~dynamic_bitset() noexcept = default;
193 
212  constexpr dynamic_bitset(uint64_t const value)
213  {
214  if (detail::popcount(value >> 58) != 0)
215  throw std::invalid_argument{"The dynamic_bitset can be at most 58 long."};
216  data.bits |= value;
217  data.size |= value ? detail::most_significant_bit_set(value) + 1 : 0u;
218  }
219 
237  template <std::forward_iterator begin_it_type, typename end_it_type>
239  requires std::sentinel_for<end_it_type, begin_it_type> &&
242  constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept:
244  {
245  assign(begin_it, end_it);
246  }
247 
263  template <std::ranges::input_range other_range_t>
267  explicit constexpr dynamic_bitset(other_range_t && range) noexcept :
268  dynamic_bitset{std::ranges::begin(range), std::ranges::end(range)}
269  {}
270 
285  constexpr dynamic_bitset(size_type const n, value_type const value) noexcept :
287  {
288  assign(n, value);
289  }
290 
305  {
306  assign(std::ranges::begin(ilist), std::ranges::end(ilist));
307  return *this;
308  }
309 
331  template <size_t N>
332  constexpr dynamic_bitset(char const (&lit)[N]) : dynamic_bitset{}
333  {
334  static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
335  assign(lit);
336  }
337 
355  template <size_t N>
356  constexpr dynamic_bitset & operator=(char const (&lit)[N])
357  {
358  static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
359  assign(lit);
360  return *this;
361  }
362 
380  template <size_t N>
381  constexpr void assign(char const (&lit)[N])
382  {
383  static_assert(N <= bit_capacity + 1, "Length of string literal exceeds capacity of dynamic_bitset.");
384  assert(lit[N - 1] == '\0');
385  uint64_t value{};
386 
387  for (size_t i = 0; i != N - 1; ++i)
388  {
389  if (lit[i] == '0')
390  {
391  value <<= 1;
392  }
393  else if (lit[i] == '1')
394  {
395  value <<= 1;
396  value |= 1u;
397  }
398  else
399  {
400  throw std::invalid_argument{"The string to construct a dynamic_bitset from may only contain 0 and 1."};
401  }
402  }
403 
404  *this = value;
405  resize(N - 1);
406  }
407 
421  constexpr void assign(std::initializer_list<value_type> const ilist) noexcept
422  {
423  assign(std::ranges::begin(ilist), std::ranges::end(ilist));
424  }
425 
440  constexpr void assign(size_type const count, value_type const value) noexcept
441  {
442  clear();
443  auto tmp = views::repeat_n(value, count);
444  assign(std::ranges::begin(tmp), std::ranges::end(tmp));
445  }
446 
462  template <std::ranges::input_range other_range_t>
466  constexpr void assign(other_range_t && range) noexcept
467  {
468  assign(std::ranges::begin(range), std::ranges::end(range));
469  }
470 
488  template <std::forward_iterator begin_it_type, typename end_it_type>
490  requires std::sentinel_for<end_it_type, begin_it_type> &&
493  constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
494  {
495  clear();
496  insert(cbegin(), begin_it, end_it);
497  }
499 
511  constexpr iterator begin() noexcept
512  {
513  return iterator{*this};
514  }
515 
517  constexpr const_iterator begin() const noexcept
518  {
519  return const_iterator{*this};
520  }
521 
523  constexpr const_iterator cbegin() const noexcept
524  {
525  return begin();
526  }
527 
536  constexpr iterator end() noexcept
537  {
538  return iterator{*this, size()};
539  }
540 
542  constexpr const_iterator end() const noexcept
543  {
544  return const_iterator{*this, size()};
545  }
546 
548  constexpr const_iterator cend() const noexcept
549  {
550  return end();
551  }
553 
578  constexpr dynamic_bitset & operator&=(dynamic_bitset const & rhs) noexcept
579  {
580  assert(size() == rhs.size());
581  data.bits &= rhs.data.bits;
582  return *this;
583  }
584 
606  constexpr dynamic_bitset & operator|=(dynamic_bitset const & rhs) noexcept
607  {
608  assert(size() == rhs.size());
609  data.bits |= rhs.data.bits;
610  return *this;
611  }
612 
634  constexpr dynamic_bitset & operator^=(dynamic_bitset const & rhs) noexcept
635  {
636  assert(size() == rhs.size());
637  data.bits ^= rhs.data.bits;
638  return *this;
639  }
640 
662  constexpr dynamic_bitset operator~() const noexcept
663  {
664  dynamic_bitset tmp{*this};
665  tmp.flip();
666  return tmp;
667  }
668 
687  constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
688  {
689  assert(count > 0);
690  assert(count < size());
691  data.bits <<= count;
692  data.bits &= (1ULL << size()) - 1ULL;
693  return *this;
694  }
695 
714  constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
715  {
716  assert(count > 0);
717  assert(count < size());
718  data.bits >>= count;
719  return *this;
720  }
721 
740  constexpr dynamic_bitset operator>>(size_t const count) const noexcept
741  {
742  assert(count > 0);
743  assert(count < size());
744  dynamic_bitset tmp{*this};
745  tmp >>= count;
746  return tmp;
747  }
748 
767  constexpr dynamic_bitset operator<<(size_t const count) const noexcept
768  {
769  assert(count > 0);
770  assert(count < size());
771  dynamic_bitset tmp{*this};
772  tmp <<= count;
773  return tmp;
774  }
775 
793  constexpr dynamic_bitset & set() noexcept
794  {
795  data.bits |= (1ULL << size()) - 1ULL;
796  return *this;
797  }
798 
819  constexpr dynamic_bitset & set(size_t const i, bool const value = true)
820  {
821  at(i) = value;
822  return *this;
823  }
824 
845  constexpr dynamic_bitset & reset() noexcept
846  {
847  data.bits = 0u;
848  return *this;
849  }
850 
870  constexpr dynamic_bitset & reset(size_t const i)
871  {
872  set(i, false);
873  return *this;
874  }
875 
893  constexpr dynamic_bitset & flip() noexcept
894  {
895  data.bits = ~data.bits;
896  data.bits &= (1ULL << size()) - 1ULL;
897  return *this;
898  }
899 
919  constexpr dynamic_bitset & flip(size_t const i)
920  {
921  at(i) ? reset(i) : set(i);
922  return *this;
923  }
925 
932  constexpr bool all() const noexcept
933  {
934  return count() == size();
935  }
936 
940  constexpr bool any() const noexcept
941  {
942  return count() != 0;
943  }
944 
948  constexpr bool none() const noexcept
949  {
950  return count() == 0;
951  }
952 
954  constexpr size_type count() const noexcept
955  {
956  return detail::popcount(data.bits);
957  }
958 
974  constexpr reference at(size_t const i)
975  {
976  if (i >= size()) // [[unlikely]]
977  throw std::out_of_range{"Trying to access position " + std::to_string(i) +
978  " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
979  return (*this)[i];
980  }
981 
983  constexpr const_reference at(size_t const i) const
984  {
985  if (i >= size()) // [[unlikely]]
986  throw std::out_of_range{"Trying to access position " + std::to_string(i) +
987  " in a seqan3::dynamic_bitset of size " + std::to_string(size()) + "."};
988  return (*this)[i];
989  }
990 
992  constexpr const_reference test(size_t const i) const
993  {
994  return at(i);
995  }
996 
1018  constexpr reference operator[](size_t const i) noexcept
1019  {
1020  assert(i < size());
1021  return {data, i};
1022  }
1023 
1025  constexpr const_reference operator[](size_t const i) const noexcept
1026  {
1027  assert(i < size());
1028  return data.bits & 1ULL << i;
1029  }
1030 
1047  constexpr reference front() noexcept
1048  {
1049  assert(size() > 0);
1050  return (*this)[0];
1051  }
1052 
1054  constexpr const_reference front() const noexcept
1055  {
1056  assert(size() > 0);
1057  return (*this)[0];
1058  }
1059 
1075  constexpr reference back() noexcept
1076  {
1077  assert(size() > 0);
1078  return (*this)[size() - 1];
1079  }
1080 
1082  constexpr const_reference back() const noexcept
1083  {
1084  assert(size() > 0);
1085  return (*this)[size() - 1];
1086  }
1087 
1089  constexpr bitfield * raw_data() noexcept
1090  {
1091  return &data;
1092  }
1093 
1095  constexpr bitfield const * raw_data() const noexcept
1096  {
1097  return &data;
1098  }
1100 
1117  constexpr bool empty() const noexcept
1118  {
1119  return size() == 0;
1120  }
1121 
1135  constexpr size_type size() const noexcept
1136  {
1137  return data.size;
1138  }
1139 
1158  constexpr size_type max_size() const noexcept
1159  {
1160  return capacity();
1161  }
1162 
1176  constexpr size_type capacity() const noexcept
1177  {
1178  return bit_capacity;
1179  }
1180 
1182  constexpr void reserve(size_t) const noexcept
1183  {
1184  // no-op
1185  }
1186 
1188  constexpr void shrink_to_fit() const noexcept
1189  {
1190  // no-op
1191  }
1193 
1212  constexpr void clear() noexcept
1213  {
1214  data.size &= 0ULL;
1215  data.bits &= 0ULL;
1216  }
1217 
1235  constexpr iterator insert(const_iterator pos, value_type const value) noexcept
1236  {
1237  return insert(pos, 1, value);
1238  }
1239 
1258  constexpr iterator insert(const_iterator pos, size_type const count, value_type const value) noexcept
1259  {
1260  auto tmp = views::repeat_n(value, count);
1261  return insert(pos, std::ranges::begin(tmp), std::ranges::end(tmp));
1262  }
1263 
1286  template <std::forward_iterator begin_it_type, typename end_it_type>
1288  requires std::sentinel_for<end_it_type, begin_it_type> &&
1289  std::constructible_from<value_type, /*ranges::iter_reference_t*/reference_t<begin_it_type>>
1291  constexpr iterator insert(const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept
1292  {
1293  auto const pos_as_num = std::ranges::distance(cbegin(), pos);
1294  auto const length = std::ranges::distance(begin_it, end_it);
1295 
1296  if (length == 0)
1297  return begin(); // nothing to insert
1298 
1299  size_type const tmp_size{size()};
1300  resize(tmp_size + length);
1301 
1302  for (size_type i = tmp_size + length - 1; i > pos_as_num + length - 1; --i)
1303  (*this)[i] = (*this)[i - length];
1304 
1305  // std::ranges::copy(begin_it, end_it, (*this)[pos_as_num]);
1306  for (auto i = pos_as_num; begin_it != end_it; ++i, ++begin_it)
1307  (*this)[i] = *begin_it;
1308 
1309  return begin() + pos_as_num;
1310  }
1311 
1329  constexpr iterator insert(const_iterator pos, std::initializer_list<value_type> const & ilist) noexcept
1330  {
1331  return insert(pos, ilist.begin(), ilist.end());
1332  }
1333 
1355  constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
1356  {
1357  if (begin_it >= end_it) // [[unlikely]]
1358  return begin() + std::ranges::distance(cbegin(), end_it);
1359 
1360  auto const length = std::ranges::distance(begin_it, end_it);
1361  auto out_it = begin() + std::ranges::distance(cbegin(), begin_it);
1362 
1363  while (end_it != cend())
1364  *(out_it++) = *(end_it++);
1365 
1366  resize(size() - length);
1367  return begin() + std::ranges::distance(cbegin(), begin_it);
1368  }
1369 
1390  constexpr iterator erase(const_iterator pos) noexcept
1391  {
1392  return erase(pos, pos + 1);
1393  }
1394 
1410  constexpr void push_back(value_type const value) noexcept
1411  {
1412  assert(size() < bit_capacity);
1413  resize(size() + 1);
1414  (*this)[size() - 1] = value;
1415  }
1416 
1433  constexpr void pop_back() noexcept
1434  {
1435  assert(size() > 0);
1436  resize(size() - 1);
1437  }
1438 
1463  constexpr void resize(size_type const count, value_type const value = false) noexcept
1464  {
1465  assert(count <= bit_capacity);
1466  // Enlarging.
1467  data.bits |= value && count > size() ? ((1ULL << (count - size())) - 1) << size() : 0ULL;
1468  // Set size bits.
1469  data.size = count;
1470  // Shrinking.
1471  data.bits &= (1ULL << size()) - 1ULL;
1472  }
1473 
1487  constexpr void swap(dynamic_bitset & rhs) noexcept
1488  {
1489  bitfield tmp = std::move(data);
1490  data = std::move(rhs.data);
1491  rhs.data = std::move(tmp);
1492  }
1493 
1495  constexpr void swap(dynamic_bitset && rhs) noexcept
1496  {
1497  data = std::move(rhs.data);
1498  }
1499 
1501 
1516  friend constexpr void swap(dynamic_bitset & lhs, dynamic_bitset & rhs) noexcept
1517  {
1518  lhs.swap(rhs);
1519  }
1520 
1532  template <size_t cap>
1534  requires cap <= bit_capacity
1536  friend constexpr dynamic_bitset operator&(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1537  {
1538  assert(lhs.size() == rhs.size());
1539  dynamic_bitset tmp{lhs};
1540  tmp &= rhs;
1541  return tmp;
1542  }
1543 
1552  template <size_t cap>
1554  requires cap <= bit_capacity
1556  friend constexpr dynamic_bitset operator^(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1557  {
1558  assert(lhs.size() == rhs.size());
1559  dynamic_bitset tmp{lhs};
1560  tmp ^= rhs;
1561  return tmp;
1562  }
1563 
1572  template <size_t cap>
1574  requires cap <= bit_capacity
1576  friend constexpr dynamic_bitset operator|(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1577  {
1578  assert(lhs.size() == rhs.size());
1579  dynamic_bitset tmp{lhs};
1580  tmp |= rhs;
1581  return tmp;
1582  }
1584 
1588  template <size_t cap>
1590  friend constexpr bool operator==(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1591  {
1592  return lhs.data.size == rhs.raw_data()->size && lhs.data.bits == rhs.raw_data()->bits;
1593  }
1594 
1596  template <size_t cap>
1597  friend constexpr bool operator!=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1598  {
1599  return !(lhs == rhs);
1600  }
1601 
1603  template <size_t cap>
1604  friend constexpr bool operator<(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1605  {
1606  return lhs.data.bits < rhs.raw_data()->bits;
1607  }
1608 
1610  template <size_t cap>
1611  friend constexpr bool operator>(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1612  {
1613  return lhs.data.bits > rhs.raw_data()->bits;
1614  }
1615 
1617  template <size_t cap>
1618  friend constexpr bool operator<=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1619  {
1620  return !(lhs > rhs);
1621  }
1622 
1624  template <size_t cap>
1625  friend constexpr bool operator>=(dynamic_bitset const & lhs, dynamic_bitset<cap> const & rhs) noexcept
1626  {
1627  return !(lhs < rhs);
1628  }
1630 
1654  template <typename char_t = char>
1655  std::string to_string(char_t zero = char_t{'0'}, char_t one = char_t{'1'}) const
1656  {
1657  std::string str{};
1658  str.reserve(size());
1659  for (bool const bit : std::views::reverse(*this))
1660  bit ? str.push_back(one) : str.push_back(zero);
1661 
1662  return str;
1663  }
1664 
1679  inline constexpr unsigned long to_ulong() const
1680  {
1682  {
1683  if (data.bits > std::numeric_limits<unsigned long>::max())
1684  throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long."};
1685  }
1686 
1687  return static_cast<unsigned long>(data.bits);
1688  }
1689 
1704  inline constexpr unsigned long long to_ullong() const
1705  {
1707  {
1709  throw std::overflow_error{"seqan3::dynamic_bitset cannot be represented as unsigned long long."};
1710  }
1711 
1712  return static_cast<unsigned long long>(data.bits);
1713  }
1715 
1729  {
1730  os << arg.to_string();
1731  return os;
1732  }
1733 
1746  {
1747  // Check if stream is ok and skip leading whitespaces.
1748  std::istream::sentry s(is);
1749  if (s)
1750  {
1751  arg.clear(); // clear the bitset
1752  std::streamsize num_char = (is.width() > 0)
1753  ? std::min<std::streamsize>(is.width(), arg.max_size())
1754  : arg.max_size();
1755  assert(num_char > 0);
1756  std::vector<bool> tmp{};
1757  tmp.reserve(num_char);
1758  for (std::streamsize n = num_char; n > 0 && (is.peek() == is.widen('0') || is.peek() == is.widen('1')); --n)
1759  {
1760  char c = is.get();
1761  c == is.widen('0') ? tmp.push_back(false) : tmp.push_back(true);
1762  }
1763 
1764  arg.assign(std::views::reverse(tmp));
1765 
1766  if (arg.size() == 0) // nothing extracted so we set the fail bit.
1767  is.setstate(std::ios_base::failbit); // LCOV_EXCL_LINE
1768 
1769  is.width(0); // cancel the effects of std::setw, if any.
1770  }
1771  return is;
1772  }
1773 
1783  template <typename char_t>
1785  {
1786  s << (std::string_view{arg.to_string()} | views::interleave(4, std::string_view{"'"}) | views::to<std::string>);
1787  return s;
1788  }
1790 
1792 
1801  template <cereal_archive archive_t>
1802  void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
1803  {
1804  uint64_t size = data.size;
1805  archive(size);
1806  data.size = size;
1807  uint64_t bits = data.bits;
1808  archive(bits);
1809  data.bits = bits;
1810  }
1812 };
1813 
1814 } // namespace seqan3
1815 
1816 namespace std
1817 {
1818 
1823 template <size_t cap>
1824 struct hash<seqan3::dynamic_bitset<cap>>
1825 {
1831  size_t operator()(seqan3::dynamic_bitset<cap> const arg) const noexcept
1832  {
1833  return static_cast<size_t>(arg.to_ullong());
1834  }
1835 };
1836 
1837 } //namespace std
seqan3::dynamic_bitset::clear
constexpr void clear() noexcept
Removes all elements from the container.
Definition: dynamic_bitset.hpp:1212
std::istream::width
T width(T... args)
seqan3::dynamic_bitset::assign
constexpr void assign(char const (&lit)[N])
Assign from literal.
Definition: dynamic_bitset.hpp:381
seqan3::dynamic_bitset::any
constexpr bool any() const noexcept
Checks if any bit is set.
Definition: dynamic_bitset.hpp:940
seqan3::dynamic_bitset::to_ullong
constexpr unsigned long long to_ullong() const
Converts the dynamic_bitset to an unsigned long long integer.
Definition: dynamic_bitset.hpp:1704
std::istream::setstate
T setstate(T... args)
seqan3::dynamic_bitset::operator>>=
constexpr dynamic_bitset & operator>>=(size_t const count) noexcept
Performs binary shift right on the current object.
Definition: dynamic_bitset.hpp:714
seqan3::dynamic_bitset::to_ulong
constexpr unsigned long to_ulong() const
Converts the dynamic_bitset to an unsigned long integer.
Definition: dynamic_bitset.hpp:1679
bit_manipulation.hpp
Provides utility functions for bit twiddling.
std::string
seqan3::dynamic_bitset::assign
constexpr void assign(other_range_t &&range) noexcept
Assign from a different range.
Definition: dynamic_bitset.hpp:466
seqan3::dynamic_bitset::operator<<
friend std::ostream & operator<<(std::ostream &os, dynamic_bitset const &arg)
Formatted output for the seqan3::dynamic_bitset.
Definition: dynamic_bitset.hpp:1728
seqan3::dynamic_bitset::operator!=
constexpr friend bool operator!=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1597
seqan3::dynamic_bitset< 58 >::difference_type
ptrdiff_t difference_type
A std::ptrdiff_t.
Definition: dynamic_bitset.hpp:174
seqan3::views::interleave
constexpr auto interleave
A view that interleaves a given range into another range at regular intervals.
Definition: interleave.hpp:385
std::overflow_error
std::string_view
seqan3::dynamic_bitset::shrink_to_fit
constexpr void shrink_to_fit() const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: dynamic_bitset.hpp:1188
seqan3::dynamic_bitset::size
constexpr size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: dynamic_bitset.hpp:1135
seqan3::dynamic_bitset
A constexpr bitset implementation with dynamic size at compile time.
Definition: dynamic_bitset.hpp:49
constructible_from
The std::constructible_from concept specifies that a variable of type T can be initialized with the g...
seqan3::dynamic_bitset::insert
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:1258
std::string::reserve
T reserve(T... args)
seqan3::dynamic_bitset::max_size
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:1158
seqan3::dynamic_bitset::operator>>
constexpr dynamic_bitset operator>>(size_t const count) const noexcept
Performs binary shift right.
Definition: dynamic_bitset.hpp:740
seqan3::dynamic_bitset::cbegin
constexpr const_iterator cbegin() const noexcept
Returns the begin to the dynamic_bitset.
Definition: dynamic_bitset.hpp:523
seqan3::reference_t
typename reference< t >::type reference_t
Shortcut for seqan3::reference (transformation_trait shortcut).
Definition: pre.hpp:77
seqan3::dynamic_bitset::operator>=
constexpr friend bool operator>=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1625
std::vector
seqan3::dynamic_bitset::at
constexpr const_reference at(size_t const i) const
Returns the i-th element.
Definition: dynamic_bitset.hpp:983
seqan3::dynamic_bitset::operator=
constexpr dynamic_bitset & operator=(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition: dynamic_bitset.hpp:304
seqan3::dynamic_bitset::operator<<=
constexpr dynamic_bitset & operator<<=(size_t const count) noexcept
Performs binary shift left on the current object.
Definition: dynamic_bitset.hpp:687
std::istream::peek
T peek(T... args)
seqan3::dynamic_bitset::pop_back
constexpr void pop_back() noexcept
Removes the last element of the container.
Definition: dynamic_bitset.hpp:1433
seqan3::dynamic_bitset::cend
constexpr const_iterator cend() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition: dynamic_bitset.hpp:548
std::istream::get
T get(T... args)
seqan3::views::move
const auto move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
seqan3::dynamic_bitset::reserve
constexpr void reserve(size_t) const noexcept
Since the capacity is fixed on compile time, this is a no-op.
Definition: dynamic_bitset.hpp:1182
seqan3::dynamic_bitset::operator[]
constexpr const_reference operator[](size_t const i) const noexcept
Returns the i-th element.
Definition: dynamic_bitset.hpp:1025
seqan3::dynamic_bitset::front
constexpr const_reference front() const noexcept
Returns the first element.
Definition: dynamic_bitset.hpp:1054
seqan3::dynamic_bitset::empty
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: dynamic_bitset.hpp:1117
seqan3::dynamic_bitset::insert
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:1291
seqan3::dynamic_bitset::operator==
constexpr friend bool operator==(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1590
debug_stream_type.hpp
Provides seqan3::debug_stream and related types.
seqan3::dynamic_bitset::operator>>
friend std::istream & operator>>(std::istream &is, dynamic_bitset &arg)
Formatted input for the seqan3::dynamic_bitset.
Definition: dynamic_bitset.hpp:1745
seqan3::dynamic_bitset::capacity
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:1176
seqan3::dynamic_bitset::operator|=
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:606
seqan3::dynamic_bitset::swap
constexpr void swap(dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition: dynamic_bitset.hpp:1487
seqan3::dynamic_bitset< 58 >::const_reference
bool const_reference
Equals the value_type.
Definition: dynamic_bitset.hpp:168
seqan3::dynamic_bitset::test
constexpr const_reference test(size_t const i) const
Returns the i-th element.
Definition: dynamic_bitset.hpp:992
seqan3::dynamic_bitset::end
constexpr const_iterator end() const noexcept
Returns iterator past the end of the dynamic_bitset.
Definition: dynamic_bitset.hpp:542
seqan3::dynamic_bitset::reset
constexpr dynamic_bitset & reset(size_t const i)
Sets the i'th bit to false.
Definition: dynamic_bitset.hpp:870
seqan3::dynamic_bitset::insert
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:1329
seqan3::dynamic_bitset::operator=
constexpr dynamic_bitset & operator=(char const (&lit)[N])
Assign from literal.
Definition: dynamic_bitset.hpp:356
seqan3::dynamic_bitset::dynamic_bitset
constexpr dynamic_bitset(size_type const n, value_type const value) noexcept
Construct with n times value.
Definition: dynamic_bitset.hpp:285
seqan3::dynamic_bitset::operator<=
constexpr friend bool operator<=(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1618
seqan3::debug_stream_type
A "pretty printer" for most SeqAn data structures and related types.
Definition: debug_stream_type.hpp:70
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
seqan3::dynamic_bitset::operator[]
constexpr reference operator[](size_t const i) noexcept
Returns the i-th element.
Definition: dynamic_bitset.hpp:1018
std::istream::widen
T widen(T... args)
seqan3::dynamic_bitset::resize
constexpr void resize(size_type const count, value_type const value=false) noexcept
Resizes the container to contain count elements.
Definition: dynamic_bitset.hpp:1463
seqan3::dynamic_bitset::dynamic_bitset
constexpr dynamic_bitset(other_range_t &&range) noexcept
Construct from a different range.
Definition: dynamic_bitset.hpp:267
seqan3::dynamic_bitset::operator>
constexpr friend bool operator>(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1611
std::streamsize
seqan3::dynamic_bitset< 58 >::const_iterator
detail::random_access_iterator< dynamic_bitset const > const_iterator
The const_iterator type of this container (a random access iterator).
Definition: dynamic_bitset.hpp:172
repeat_n.hpp
Provides seqan3::views::repeat_n.
seqan3::dynamic_bitset::operator<
constexpr friend bool operator<(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Performs element-wise comparison.
Definition: dynamic_bitset.hpp:1604
to.hpp
Provides seqan3::views::to.
seqan3::dynamic_bitset::dynamic_bitset
constexpr dynamic_bitset(char const (&lit)[N])
Construction from literal.
Definition: dynamic_bitset.hpp:332
std::ostream
seqan3::dynamic_bitset::operator<<
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:1784
seqan3::dynamic_bitset::reset
constexpr dynamic_bitset & reset() noexcept
Sets all bits to 0.
Definition: dynamic_bitset.hpp:845
seqan3::dynamic_bitset::erase
constexpr iterator erase(const_iterator begin_it, const_iterator end_it) noexcept
Removes specified elements from the container.
Definition: dynamic_bitset.hpp:1355
seqan3::dynamic_bitset< 58 >::reference
reference_proxy_type reference
A proxy type that enables assignment.
Definition: dynamic_bitset.hpp:166
seqan3::dynamic_bitset::operator^=
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:634
seqan3::dynamic_bitset::assign
constexpr void assign(begin_it_type begin_it, end_it_type end_it) noexcept
Assign from pair of iterators.
Definition: dynamic_bitset.hpp:493
std::to_string
T to_string(T... args)
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
seqan3::dynamic_bitset::swap
constexpr friend void swap(dynamic_bitset &lhs, dynamic_bitset &rhs) noexcept
Swap contents with another instance.
Definition: dynamic_bitset.hpp:1516
seqan3::dynamic_bitset::at
constexpr reference at(size_t const i)
Returns the i-th element.
Definition: dynamic_bitset.hpp:974
seqan3::dynamic_bitset::assign
constexpr void assign(size_type const count, value_type const value) noexcept
Assign with count times value.
Definition: dynamic_bitset.hpp:440
seqan3::dynamic_bitset::operator^
constexpr friend dynamic_bitset operator^(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Returns dynamic_bitset containing the result of binary XOR on corresponding pairs of bits of lhs and ...
Definition: dynamic_bitset.hpp:1556
seqan3::dynamic_bitset::to_string
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:1655
seqan3::dynamic_bitset::front
constexpr reference front() noexcept
Returns the first element.
Definition: dynamic_bitset.hpp:1047
seqan3::dynamic_bitset::dynamic_bitset
constexpr dynamic_bitset(begin_it_type begin_it, end_it_type end_it) noexcept
Construct from two iterators.
Definition: dynamic_bitset.hpp:242
std::invalid_argument
seqan3::dynamic_bitset::none
constexpr bool none() const noexcept
Checks if no bit is set.
Definition: dynamic_bitset.hpp:948
seqan3::dynamic_bitset::operator&
constexpr friend dynamic_bitset operator&(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Returns dynamic_bitset containing the result of binary AND on corresponding pairs of bits of lhs and ...
Definition: dynamic_bitset.hpp:1536
seqan3::dynamic_bitset::operator|
constexpr friend dynamic_bitset operator|(dynamic_bitset const &lhs, dynamic_bitset< cap > const &rhs) noexcept
Returns dynamic_bitset containing the result of binary OR on corresponding pairs of bits of lhs and r...
Definition: dynamic_bitset.hpp:1576
seqan3::dynamic_bitset::insert
constexpr iterator insert(const_iterator pos, value_type const value) noexcept
Inserts value before pos in the container.
Definition: dynamic_bitset.hpp:1235
seqan3::dynamic_bitset::assign
constexpr void assign(std::initializer_list< value_type > const ilist) noexcept
Assign from std::initializer_list.
Definition: dynamic_bitset.hpp:421
seqan3::dynamic_bitset::set
constexpr dynamic_bitset & set() noexcept
Sets all bits to 1.
Definition: dynamic_bitset.hpp:793
seqan3::dynamic_bitset::end
constexpr iterator end() noexcept
Returns iterator past the end of the dynamic_bitset.
Definition: dynamic_bitset.hpp:536
seqan3::dynamic_bitset::swap
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:1495
seqan3::dynamic_bitset::back
constexpr reference back() noexcept
Returns the last element.
Definition: dynamic_bitset.hpp:1075
seqan3::dynamic_bitset::push_back
constexpr void push_back(value_type const value) noexcept
Appends the given element value to the end of the container.
Definition: dynamic_bitset.hpp:1410
std::hash< seqan3::dynamic_bitset< cap > >::operator()
size_t operator()(seqan3::dynamic_bitset< cap > const arg) const noexcept
Compute the hash for a seqan3::dynamic_bitset.
Definition: dynamic_bitset.hpp:1831
seqan3::dynamic_bitset::begin
constexpr const_iterator begin() const noexcept
Returns the begin to the dynamic_bitset.
Definition: dynamic_bitset.hpp:517
std
SeqAn specific customisations in the standard namespace.
seqan3::dynamic_bitset::operator=
constexpr dynamic_bitset & operator=(dynamic_bitset const &) noexcept=default
Defaulted.
seqan3::dynamic_bitset::erase
constexpr iterator erase(const_iterator pos) noexcept
Removes specified elements from the container.
Definition: dynamic_bitset.hpp:1390
seqan3::dynamic_bitset::flip
constexpr dynamic_bitset & flip(size_t const i)
Flips the i'th bit (binary NOT).
Definition: dynamic_bitset.hpp:919
std::out_of_range
seqan3::dynamic_bitset::dynamic_bitset
constexpr dynamic_bitset() noexcept=default
Defaulted.
cereal.hpp
Adaptions of concepts from the Cereal library.
seqan3::dynamic_bitset::raw_data
constexpr bitfield * raw_data() noexcept
Direct access to the underlying bit field.
Definition: dynamic_bitset.hpp:1089
seqan3::views::repeat_n
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:94
std::conditional_t
seqan3::dynamic_bitset::begin
constexpr iterator begin() noexcept
Returns the begin to the dynamic_bitset.
Definition: dynamic_bitset.hpp:511
seqan3::dynamic_bitset::count
constexpr size_type count() const noexcept
Returns the number of set bits.
Definition: dynamic_bitset.hpp:954
seqan3::dynamic_bitset::set
constexpr dynamic_bitset & set(size_t const i, bool const value=true)
Sets the i'th bit to value.
Definition: dynamic_bitset.hpp:819
std::istream
seqan3::dynamic_bitset::operator~
constexpr dynamic_bitset operator~() const noexcept
Returns a temporary copy of *this with all bits flipped (binary NOT).
Definition: dynamic_bitset.hpp:662
seqan3::dynamic_bitset::flip
constexpr dynamic_bitset & flip() noexcept
Flips all bits (binary NOT).
Definition: dynamic_bitset.hpp:893
seqan3::dynamic_bitset::raw_data
constexpr const bitfield * raw_data() const noexcept
Direct access to the underlying bit field.
Definition: dynamic_bitset.hpp:1095
std::numeric_limits
interleave.hpp
Provides seqan3::views::interleave.
seqan3::dynamic_bitset::value_type
bool value_type
Equals bool.
Definition: dynamic_bitset.hpp:164
std::istream::sentry
seqan3::dynamic_bitset::back
constexpr const_reference back() const noexcept
Returns the last element.
Definition: dynamic_bitset.hpp:1082
seqan3::dynamic_bitset::all
constexpr bool all() const noexcept
Checks if all bit are set.
Definition: dynamic_bitset.hpp:932
std::hash
std::initializer_list
seqan3::dynamic_bitset::operator<<
constexpr dynamic_bitset operator<<(size_t const count) const noexcept
Performs binary shift left.
Definition: dynamic_bitset.hpp:767
seqan3::dynamic_bitset::operator&=
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:578
seqan3::dynamic_bitset< 58 >::iterator
detail::random_access_iterator< dynamic_bitset > iterator
The iterator type of this container (a random access iterator).
Definition: dynamic_bitset.hpp:170