SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
score_matrix_single_column.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/ranges>
16 #include <vector>
17 
25 
26 namespace seqan3::detail
27 {
28 
51 template <typename score_t>
53  requires (arithmetic<score_t> || simd_concept<score_t>)
55 class score_matrix_single_column
56 {
57 private:
59  using physical_column_t = std::vector<score_t, aligned_allocator<score_t, alignof(score_t)>>;
61  using virtual_column_t = decltype(views::repeat_n(score_t{}, 1));
62 
63  class matrix_iterator;
64 
66  physical_column_t optimal_column{};
68  physical_column_t horizontal_column{};
70  virtual_column_t vertical_column{};
72  size_t number_of_columns{};
73 
74 public:
78  score_matrix_single_column() = default;
79  score_matrix_single_column(score_matrix_single_column const &) = default;
80  score_matrix_single_column(score_matrix_single_column &&) = default;
81  score_matrix_single_column & operator=(score_matrix_single_column const &) = default;
82  score_matrix_single_column & operator=(score_matrix_single_column &&) = default;
83  ~score_matrix_single_column() = default;
84 
112  template <std::integral column_index_t, std::integral row_index_t>
113  void resize(column_index_type<column_index_t> const number_of_columns,
114  row_index_type<row_index_t> const number_of_rows,
115  score_t const initial_value = score_t{})
116  {
117  this->number_of_columns = number_of_columns.get();
118  optimal_column.clear();
119  horizontal_column.clear();
120  optimal_column.resize(number_of_rows.get(), initial_value);
121  horizontal_column.resize(number_of_rows.get(), initial_value);
122  vertical_column = views::repeat_n(initial_value, number_of_rows.get());
123  }
124 
128  matrix_iterator begin()
130  {
131  return matrix_iterator{*this, 0u};
132  }
133 
135  matrix_iterator begin() const = delete;
136 
138  matrix_iterator end()
139  {
140  return matrix_iterator{*this, number_of_columns};
141  }
142 
144  matrix_iterator end() const = delete;
146 };
147 
159 template <typename score_t>
160 class score_matrix_single_column<score_t>::matrix_iterator
161 {
162 private:
163 
165  using matrix_column_t = decltype(views::zip(std::declval<physical_column_t &>(),
166  std::declval<physical_column_t &>(),
167  std::declval<virtual_column_t &>()));
168 
170  static constexpr auto transform_to_affine_cell = std::views::transform([] (auto && tpl)
171  -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
172  {
173  using fwd_tuple_t = decltype(tpl);
174  return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
175  });
176 
178  score_matrix_single_column * host_ptr{nullptr};
180  size_t current_column_id{};
181 
182 public:
186  using value_type = decltype(std::declval<matrix_column_t>() | transform_to_affine_cell);
189  using reference = value_type;
191  using pointer = void;
193  using difference_type = std::ptrdiff_t;
195  using iterator_category = std::input_iterator_tag;
197 
201  matrix_iterator() noexcept = default;
202  matrix_iterator(matrix_iterator const &) noexcept = default;
203  matrix_iterator(matrix_iterator &&) noexcept = default;
204  matrix_iterator & operator=(matrix_iterator const &) noexcept = default;
205  matrix_iterator & operator=(matrix_iterator &&) noexcept = default;
206  ~matrix_iterator() = default;
207 
213  explicit matrix_iterator(score_matrix_single_column & host_matrix, size_t const initial_column_id) noexcept :
214  host_ptr{std::addressof(host_matrix)},
215  current_column_id{initial_column_id}
216  {}
218 
222  reference operator*() const
224  {
225  return views::zip(host_ptr->optimal_column, host_ptr->horizontal_column, host_ptr->vertical_column)
226  | transform_to_affine_cell;
227  }
229 
233  matrix_iterator & operator++()
235  {
236  ++current_column_id;
237  return *this;
238  }
239 
241  void operator++(int)
242  {
243  ++(*this);
244  }
246 
250  friend bool operator==(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
252  {
253  return lhs.current_column_id == rhs.current_column_id;
254  }
255 
257  friend bool operator!=(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
258  {
259  return !(lhs == rhs);
260  }
262 };
263 
264 } // namespace seqan3::detail
matrix_coordinate.hpp
Provides seqan3::detail::alignment_coordinate and associated strong types.
zip.hpp
Provides seqan3::views::zip.
std::rel_ops::operator!=
T operator!=(T... args)
vector
std::input_iterator_tag
concept.hpp
Provides seqan3::simd::simd_concept.
std::addressof
T addressof(T... args)
repeat_n.hpp
Provides seqan3::views::repeat_n.
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
affine_cell_proxy.hpp
Provides seqan3::detail::affine_cell_proxy.
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::remove_cvref_t
arithmetic
A type that satisfies std::is_arithmetic_v<t>.
seqan3::views::repeat_n
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:94
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