Loading...
Searching...
No Matches
score_matrix_single_column.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <ranges>
#include <vector>
#include <seqan3/alignment/matrix/detail/affine_cell_proxy.hpp>
#include <seqan3/alignment/matrix/detail/matrix_coordinate.hpp>
#include <seqan3/utility/concept.hpp>
#include <seqan3/utility/container/aligned_allocator.hpp>
#include <seqan3/utility/simd/concept.hpp>
#include <seqan3/utility/views/repeat_n.hpp>
#include <seqan3/utility/views/zip.hpp>
namespace seqan3::detail
{
template <typename score_t>
requires (arithmetic<score_t> || simd_concept<score_t>)
class score_matrix_single_column
{
private:
using physical_column_t = std::vector<score_t, aligned_allocator<score_t, alignof(score_t)>>;
using virtual_column_t = decltype(views::repeat_n(score_t{}, 1));
class matrix_iterator;
physical_column_t optimal_column{};
physical_column_t horizontal_column{};
virtual_column_t vertical_column{};
size_t number_of_columns{};
public:
score_matrix_single_column() = default;
score_matrix_single_column(score_matrix_single_column const &) = default;
score_matrix_single_column(score_matrix_single_column &&) = default;
score_matrix_single_column & operator=(score_matrix_single_column const &) = default;
score_matrix_single_column & operator=(score_matrix_single_column &&) = default;
~score_matrix_single_column() = default;
template <std::integral column_index_t, std::integral row_index_t>
void resize(column_index_type<column_index_t> const number_of_columns,
row_index_type<row_index_t> const number_of_rows,
score_t const initial_value = score_t{})
{
this->number_of_columns = number_of_columns.get();
optimal_column.clear();
horizontal_column.clear();
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START(-Wstringop-overflow)
optimal_column.resize(number_of_rows.get(), initial_value);
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
horizontal_column.resize(number_of_rows.get(), initial_value);
vertical_column = views::repeat_n(initial_value, number_of_rows.get());
}
matrix_iterator begin()
{
return matrix_iterator{*this, 0u};
}
matrix_iterator begin() const = delete;
matrix_iterator end()
{
return matrix_iterator{*this, number_of_columns};
}
matrix_iterator end() const = delete;
};
template <typename score_t>
requires (arithmetic<score_t> || simd_concept<score_t>)
class score_matrix_single_column<score_t>::matrix_iterator
{
private:
using matrix_column_t = decltype(views::zip(std::declval<physical_column_t &>(),
std::declval<physical_column_t &>(),
std::declval<virtual_column_t &>()));
static constexpr auto transform_to_affine_cell = std::views::transform(
[](auto && tpl) -> affine_cell_proxy<std::remove_cvref_t<decltype(tpl)>>
{
using fwd_tuple_t = decltype(tpl);
return affine_cell_proxy<std::remove_cvref_t<fwd_tuple_t>>{std::forward<fwd_tuple_t>(tpl)};
});
score_matrix_single_column * host_ptr{nullptr};
size_t current_column_id{};
public:
using value_type = decltype(std::declval<matrix_column_t>() | transform_to_affine_cell);
using reference = value_type;
using pointer = void;
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;
matrix_iterator() noexcept = default;
matrix_iterator(matrix_iterator const &) noexcept = default;
matrix_iterator(matrix_iterator &&) noexcept = default;
matrix_iterator & operator=(matrix_iterator const &) noexcept = default;
matrix_iterator & operator=(matrix_iterator &&) noexcept = default;
~matrix_iterator() = default;
explicit matrix_iterator(score_matrix_single_column & host_matrix, size_t const initial_column_id) noexcept :
host_ptr{std::addressof(host_matrix)},
current_column_id{initial_column_id}
{}
reference operator*() const
{
return views::zip(host_ptr->optimal_column, host_ptr->horizontal_column, host_ptr->vertical_column)
| transform_to_affine_cell;
}
matrix_iterator & operator++()
{
++current_column_id;
return *this;
}
void operator++(int)
{
++(*this);
}
friend bool operator==(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
{
return lhs.current_column_id == rhs.current_column_id;
}
friend bool operator!=(matrix_iterator const & lhs, matrix_iterator const & rhs) noexcept
{
return !(lhs == rhs);
}
};
} // namespace seqan3::detail
std::addressof
T addressof(T... args)
affine_cell_proxy.hpp
Provides seqan3::detail::affine_cell_proxy.
aligned_allocator.hpp
Provides seqan3::aligned_allocator.
std::begin
T begin(T... args)
std::declval
T declval(T... args)
std::end
T end(T... args)
std::forward
T forward(T... args)
seqan3::views::zip
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
seqan3::views::repeat_n
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition repeat_n.hpp:88
matrix_coordinate.hpp
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START
#define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_START(...)
Denotes the start of a block where diagnostics are ignored.
Definition platform.hpp:268
SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
#define SEQAN3_WORKAROUND_GCC_BOGUS_MEMCPY_STOP
Denotes the end of a block where diagnostics are ignored.
Definition platform.hpp:277
repeat_n.hpp
Provides seqan3::views::repeat_n.
concept.hpp
Provides concepts that do not have equivalents in C++20.
vector
zip.hpp
Provides seqan3::views::zip.
Hide me