SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
score_matrix_single_column.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <ranges>
13#include <vector>
14
19#include <seqan3/utility/simd/concept.hpp>
22
23namespace seqan3::detail
24{
25
48template <typename score_t>
49 requires (arithmetic<score_t> || simd_concept<score_t>)
50class score_matrix_single_column
51{
52private:
54 using physical_column_t = std::vector<score_t, aligned_allocator<score_t, alignof(score_t)>>;
56 using virtual_column_t = decltype(views::repeat_n(score_t{}, 1));
57
58 class matrix_iterator;
59
61 physical_column_t optimal_column{};
63 physical_column_t horizontal_column{};
65 virtual_column_t vertical_column{};
67 size_t number_of_columns{};
68
69public:
73 score_matrix_single_column() = default;
74 score_matrix_single_column(score_matrix_single_column const &) = default;
75 score_matrix_single_column(score_matrix_single_column &&) = default;
76 score_matrix_single_column & operator=(score_matrix_single_column const &) = default;
77 score_matrix_single_column & operator=(score_matrix_single_column &&) = default;
78 ~score_matrix_single_column() = default;
79
81
108 template <std::integral column_index_t, std::integral row_index_t>
109 void resize(column_index_type<column_index_t> const number_of_columns,
110 row_index_type<row_index_t> const number_of_rows,
111 score_t const initial_value = score_t{})
112 {
113 this->number_of_columns = number_of_columns.get();
114 optimal_column.clear();
115 horizontal_column.clear();
116 optimal_column.resize(number_of_rows.get(), initial_value);
117 horizontal_column.resize(number_of_rows.get(), initial_value);
118 vertical_column = views::repeat_n(initial_value, number_of_rows.get());
119 }
120
125 matrix_iterator begin()
126 {
127 return matrix_iterator{*this, 0u};
128 }
129
131 matrix_iterator begin() const = delete;
132
134 matrix_iterator end()
135 {
136 return matrix_iterator{*this, number_of_columns};
137 }
138
140 matrix_iterator end() const = delete;
142};
143
155template <typename score_t>
156 requires (arithmetic<score_t> || simd_concept<score_t>)
157class score_matrix_single_column<score_t>::matrix_iterator
158{
159private:
161 using matrix_column_t = decltype(views::zip(std::declval<physical_column_t &>(),
162 std::declval<physical_column_t &>(),
163 std::declval<virtual_column_t &>()));
164
166 static constexpr auto transform_to_affine_cell = std::views::transform(
167 [](auto && tpl) -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
168 {
169 using fwd_tuple_t = decltype(tpl);
170 return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
171 });
172
174 score_matrix_single_column * host_ptr{nullptr};
176 size_t current_column_id{};
177
178public:
183 using value_type = decltype(std::declval<matrix_column_t>() | transform_to_affine_cell);
185 using reference = value_type;
187 using pointer = void;
189 using difference_type = std::ptrdiff_t;
191 using iterator_category = std::input_iterator_tag;
193
197 matrix_iterator() noexcept = default;
198 matrix_iterator(matrix_iterator const &) noexcept = default;
199 matrix_iterator(matrix_iterator &&) noexcept = default;
200 matrix_iterator & operator=(matrix_iterator const &) noexcept = default;
201 matrix_iterator & operator=(matrix_iterator &&) noexcept = default;
202 ~matrix_iterator() = default;
203
209 explicit matrix_iterator(score_matrix_single_column & host_matrix, size_t const initial_column_id) noexcept :
210 host_ptr{std::addressof(host_matrix)},
211 current_column_id{initial_column_id}
212 {}
214
219 reference operator*() const
220 {
221 return views::zip(host_ptr->optimal_column, host_ptr->horizontal_column, host_ptr->vertical_column)
222 | transform_to_affine_cell;
223 }
225
230 matrix_iterator & operator++()
231 {
232 ++current_column_id;
233 return *this;
234 }
235
237 void operator++(int)
238 {
239 ++(*this);
240 }
242
247 friend bool operator==(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
248 {
249 return lhs.current_column_id == rhs.current_column_id;
250 }
251
253 friend bool operator!=(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
254 {
255 return !(lhs == rhs);
256 }
258};
259
260} // namespace seqan3::detail
T addressof(T... args)
Provides seqan3::detail::affine_cell_proxy.
Provides seqan3::aligned_allocator.
T begin(T... args)
T clear(T... args)
T end(T... args)
seqan::stl::views::zip zip
A view adaptor that takes several views and returns tuple-like values from every i-th element of each...
Definition zip.hpp:24
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
A type that satisfies std::is_arithmetic_v<t>.
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
T operator!=(T... args)
Provides seqan3::views::repeat_n.
Provides concepts that do not have equivalents in C++20.
Provides seqan3::views::zip.
Hide me