SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
coordinate_matrix.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 
15 #include <seqan3/std/concepts>
16 #include <seqan3/std/ranges>
17 
26 
27 namespace seqan3::detail
28 {
29 
30 //------------------------------------------------------------------------------
31 // coordinate_matrix
32 //------------------------------------------------------------------------------
33 
62 template <typename index_t>
64  requires (std::integral<index_t> || simd_index<index_t>)
66 class coordinate_matrix
67 {
68 private:
76  struct convert_to_matrix_coordinate
77  {
79  index_t column_index{};
80 
87  auto operator()(index_t const row_index) noexcept
88  {
89  return matrix_index{row_index_type{row_index}, column_index_type{column_index}};
90  }
91  };
92 
94  template <typename simd_index_t>
95  using lazy_scalar_type_t = typename simd_traits<simd_index_t>::scalar_type;
96 
98  using size_type = lazy_conditional_t<simd_concept<index_t>, lazy<lazy_scalar_type_t, index_t>, index_t>;
99 
100  // The coordinate matrix iterator.
101  class iterator;
102 
104  size_type column_count{};
106  size_type row_count{};
107 
108 public:
112  coordinate_matrix() = default;
113  coordinate_matrix(coordinate_matrix const &) = default;
114  coordinate_matrix(coordinate_matrix &&) = default;
115  coordinate_matrix & operator=(coordinate_matrix const &) = default;
116  coordinate_matrix & operator=(coordinate_matrix &&) = default;
117  ~coordinate_matrix() = default;
118 
137  template <std::integral column_index_t, std::integral row_index_t>
138  void resize(column_index_type<column_index_t> const column_count,
139  row_index_type<row_index_t> const row_count) noexcept
140  {
141  this->column_count = column_count.get();
142  this->row_count = row_count.get();
143  }
145 
149  iterator begin() const noexcept
151  {
152  return iterator{size_type{}, row_count};
153  }
154 
156  iterator end() const noexcept
157  {
158  return iterator{column_count, row_count};
159  }
161 };
162 
163 //------------------------------------------------------------------------------
164 // iterator
165 //------------------------------------------------------------------------------
166 
176 template <typename index_t>
178  requires (std::integral<index_t> || simd_index<index_t>)
180 class coordinate_matrix<index_t>::iterator
181 {
182 private:
184  using iota_view_t = lazy_conditional_t<simd_index<index_t>,
185  lazy<iota_simd_view, index_t>,
186  decltype(std::views::iota(size_type{}, size_type{}))>;
188  index_t column_id{0};
190  size_type row_count{0};
191 
192 public:
196  using value_type = decltype(std::declval<iota_view_t>()
198  | std::views::transform(convert_to_matrix_coordinate{column_id}));
200  using reference = value_type;
202  using pointer = void;
204  using difference_type = std::ptrdiff_t;
206  using iterator_category = std::forward_iterator_tag;
208 
212  iterator() = default;
213  iterator(iterator const &) = default;
214  iterator(iterator &&) = default;
215  iterator & operator=(iterator const &) = default;
216  iterator & operator=(iterator &&) = default;
217  ~iterator() = default;
218 
225  explicit iterator(size_type column_id, size_type row_count) noexcept :
226  row_count{std::move(row_count)}
227  {
228  if constexpr (simd_index<index_t>)
229  this->column_id = simd::fill<index_t>(std::move(column_id));
230  else
231  this->column_id = std::move(column_id);
232  }
234 
239  auto operator*() const
241  {
242  if constexpr (simd_index<index_t>)
243  {
244  return views::iota_simd<index_t>(size_type{}, row_count)
245  | std::views::transform(convert_to_matrix_coordinate{column_id});
246  }
247  else
248  {
249  return std::views::iota(size_type{}, row_count)
250  | std::views::transform(convert_to_matrix_coordinate{column_id});
251  }
252  }
254 
259  iterator & operator++()
261  {
262  ++column_id;
263  return *this;
264  }
265 
267  iterator operator++(int)
268  {
269  iterator tmp{*this};
270  ++(*this);
271  return tmp;
272  }
274 
279  friend bool operator==(iterator const & lhs, iterator const & rhs)
281  {
282  if constexpr (simd_index<index_t>)
283  return lhs.column_id[0] == rhs.column_id[0];
284  else
285  return lhs.column_id == rhs.column_id;
286  }
287 
289  friend bool operator!=(iterator const & lhs, iterator const & rhs)
290  {
291  return !(lhs == rhs);
292  }
294 };
295 } // namespace seqan3::detail
matrix_coordinate.hpp
Provides seqan3::detail::alignment_coordinate and associated strong types.
std::rel_ops::operator!=
T operator!=(T... args)
std::forward_iterator_tag
template_inspection.hpp
Provides seqan3::type_list and auxiliary type traits.
concept.hpp
Provides seqan3::simd::simd_concept.
concepts
The Concepts library.
simd_algorithm.hpp
Provides algorithms to modify seqan3::simd::simd_type.
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
simd_traits.hpp
Provides seqan3::simd::simd_traits.
aligned_allocator.hpp
Provides seqan3::aligned_allocator.
ranges
Adaptations of concepts from the Ranges TS.
std::begin
T begin(T... args)
std::ptrdiff_t
std::end
T end(T... args)
seqan3::pack_traits::transform
seqan3::type_list< trait_t< pack_t >... > transform
Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
Definition: traits.hpp:307
view_iota_simd.hpp
Provides seqan3::detail::counted_simd_iterator and seqan3::views::iota_simd.
lazy.hpp
Provides lazy template instantiation traits.