SeqAn3 3.2.0
The Modern C++ library for sequence analysis.
matrix_coordinate.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
15#include <concepts>
16#include <type_traits>
17
22
23namespace seqan3::detail
24{
29template <typename index_type>
30 requires (std::integral<index_type> || simd_index<index_type>)
31struct column_index_type : detail::strong_type<index_type, column_index_type<index_type>>
32{
34 using detail::strong_type<index_type, column_index_type<index_type>>::strong_type;
35};
36
42template <std::signed_integral index_type>
43column_index_type(index_type) -> column_index_type<std::ptrdiff_t>;
44
46template <std::unsigned_integral index_type>
47column_index_type(index_type) -> column_index_type<size_t>;
48
50template <simd_index index_type>
51column_index_type(index_type) -> column_index_type<index_type>;
53
58template <typename index_type>
59 requires (std::integral<index_type> || simd_index<index_type>)
60struct row_index_type : detail::strong_type<index_type, row_index_type<index_type>>
61{
63 using detail::strong_type<index_type, row_index_type<index_type>>::strong_type;
64};
65
71template <std::signed_integral index_type>
72row_index_type(index_type) -> row_index_type<std::ptrdiff_t>;
73
75template <std::unsigned_integral index_type>
76row_index_type(index_type) -> row_index_type<size_t>;
77
79template <simd_index index_type>
80row_index_type(index_type) -> row_index_type<index_type>;
82
87template <typename index_t>
88 requires (std::integral<index_t> || simd_index<index_t>)
89struct matrix_index
90{
94 constexpr matrix_index() = default;
95 constexpr matrix_index(matrix_index const &) = default;
96 constexpr matrix_index(matrix_index &&) = default;
97 constexpr matrix_index & operator=(matrix_index const &) = default;
98 constexpr matrix_index & operator=(matrix_index &&) = default;
99 ~matrix_index() = default;
100
105 constexpr matrix_index(row_index_type<index_t> const row_idx, column_index_type<index_t> const col_idx) noexcept :
106 row{row_idx.get()},
107 col{col_idx.get()}
108 {}
109
126 template <seqan3::arithmetic scalar_index_t>
127 constexpr matrix_index(row_index_type<scalar_index_t> const row_idx,
128 column_index_type<scalar_index_t> const col_idx) noexcept
129 requires simd_index<index_t>
130 // Note the explicit type conversion is necessary since the scalar type might be of smaller bit size.
131 :
132 row{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(row_idx.get()))},
133 col{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(col_idx.get()))}
134 {}
135
139 template <std::integral other_index_t>
140 requires (!std::same_as<other_index_t, index_t>)
141 explicit constexpr matrix_index(matrix_index<other_index_t> other) noexcept :
142 row{static_cast<index_t>(other.row)},
143 col{static_cast<index_t>(other.col)}
144 {}
146
148 template <std::integral first_index_t, std::integral second_index_t>
149 constexpr explicit operator std::pair<first_index_t, second_index_t>() const noexcept
150 {
151 return std::pair{static_cast<first_index_t>(col), static_cast<second_index_t>(row)};
152 }
153
154 index_t row{};
155 index_t col{};
156};
157
163matrix_index()->matrix_index<std::ptrdiff_t>;
164
166template <std::integral row_index_t, std::integral col_index_t>
167 requires std::common_with<row_index_t, col_index_t>
168matrix_index(row_index_type<row_index_t>, column_index_type<col_index_t>)
169 -> matrix_index<std::common_type_t<row_index_t, col_index_t>>;
170
172template <simd_index index_t>
173matrix_index(row_index_type<index_t>, column_index_type<index_t>) -> matrix_index<index_t>;
175
178using matrix_coordinate = matrix_index<size_t>;
179
184template <simd_index index_t>
185using simd_matrix_coordinate = matrix_index<index_t>;
186
189using matrix_offset = matrix_index<std::ptrdiff_t>;
190} // namespace seqan3::detail
Provides algorithms to modify seqan3::simd::simd_type.
Provides basic data structure for strong types.
Provides concepts that do not have equivalents in C++20.
Provides seqan3::simd::simd_concept.