SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
trace_iterator_banded.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, 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 
16 
17 namespace seqan3::detail
18 {
19 
31 template <two_dimensional_matrix_iterator matrix_iter_t>
32 class trace_iterator_banded : public trace_iterator_base<trace_iterator_banded<matrix_iter_t>, matrix_iter_t>
33 {
34 private:
35  static_assert(std::same_as<std::iter_value_t<matrix_iter_t>, trace_directions>,
36  "Value type of the underlying iterator must be trace_directions.");
37 
39  using base_t = trace_iterator_base<trace_iterator_banded<matrix_iter_t>, matrix_iter_t>;
40 
42  friend base_t;
43 
44 public:
48  constexpr trace_iterator_banded() = default;
49  constexpr trace_iterator_banded(trace_iterator_banded const &) = default;
50  constexpr trace_iterator_banded(trace_iterator_banded &&) = default;
51  constexpr trace_iterator_banded & operator=(trace_iterator_banded const &) = default;
52  constexpr trace_iterator_banded & operator=(trace_iterator_banded &&) = default;
53  ~trace_iterator_banded() = default;
54 
60  template <typename index_t>
61  constexpr trace_iterator_banded(matrix_iter_t const matrix_iter,
62  column_index_type<index_t> const & pivot_column) noexcept :
63  base_t{matrix_iter},
64  pivot_column{static_cast<size_t>(pivot_column.get())}
65  {}
66 
76  template <two_dimensional_matrix_iterator other_matrix_iter_t>
77  requires std::constructible_from<matrix_iter_t, other_matrix_iter_t>
78  constexpr trace_iterator_banded(trace_iterator_banded<other_matrix_iter_t> const other) noexcept : base_t{other}
79  {}
81 
83  [[nodiscard]] constexpr matrix_coordinate coordinate() const noexcept
84  {
85  auto coord = base_t::coordinate();
86  coord.row += static_cast<int32_t>(coord.col - pivot_column);
87  return coord;
88  }
89 
90 private:
92  constexpr void go_left(matrix_iter_t & iter) const noexcept
93  {
94  // Note, in the banded matrix, the columns are virtually shifted by one cell.
95  // So going left means go to the previous column and then one row down.
96  iter -= matrix_offset{row_index_type{-1}, column_index_type{1}};
97  }
98 
100  constexpr void go_diagonal(matrix_iter_t & iter) const noexcept
101  {
102  // Note, in the banded matrix, the columns are virtually shifted by one cell.
103  // So going diagonal means go to the previous column and stay in the same row.
104  iter -= matrix_offset{row_index_type{0}, column_index_type{1}};
105  }
106 
107  size_t pivot_column{};
108 };
109 
110 } // namespace seqan3::detail
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
matrix_index< size_t > matrix_coordinate
A coordinate type to access an element inside of a two-dimensional matrix.
Definition: matrix_coordinate.hpp:178
Provides seqan3::detail::trace_iterator_base.