SeqAn3 3.1.0
The Modern C++ library for sequence analysis.
trace_iterator_banded.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2021, 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
17namespace seqan3::detail
18{
19
31template <two_dimensional_matrix_iterator matrix_iter_t>
32class trace_iterator_banded : public trace_iterator_base<trace_iterator_banded<matrix_iter_t>, matrix_iter_t>
33{
34private:
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
44public:
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, column_index_type<index_t> const & pivot_column)
62 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>
78 requires std::constructible_from<matrix_iter_t, other_matrix_iter_t>
80 constexpr trace_iterator_banded(trace_iterator_banded<other_matrix_iter_t> const other) noexcept : base_t{other}
81 {}
83
85 [[nodiscard]] constexpr matrix_coordinate coordinate() const noexcept
86 {
87 auto coord = base_t::coordinate();
88 coord.row += static_cast<int32_t>(coord.col - pivot_column);
89 return coord;
90 }
91
92private:
94 constexpr void go_left(matrix_iter_t & iter) const noexcept
95 {
96 // Note, in the banded matrix, the columns are virtually shifted by one cell.
97 // So going left means go to the previous column and then one row down.
98 iter -= matrix_offset{row_index_type{-1}, column_index_type{1}};
99 }
100
102 constexpr void go_diagonal(matrix_iter_t & iter) const noexcept
103 {
104 // Note, in the banded matrix, the columns are virtually shifted by one cell.
105 // So going diagonal means go to the previous column and stay in the same row.
106 iter -= matrix_offset{row_index_type{0}, column_index_type{1}};
107 }
108
109 size_t pivot_column{};
110};
111
112} // namespace seqan3::detail
Provides seqan3::detail::trace_iterator_base.