SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
iota_simd.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
18
19namespace seqan3::detail
20{
21
33template <simd_concept index_simd_t>
35{
36private:
38 index_simd_t count_simd{};
39
40public:
45 using value_type = index_simd_t;
49 using pointer = void;
55
65
72 template <arithmetic index_scalar_t>
73 explicit counted_simd_iterator(index_scalar_t const scalar_index) noexcept :
74 count_simd{simd::fill<index_simd_t>(scalar_index)}
75 {}
77
84 {
85 return count_simd;
86 }
88
95 {
96 count_simd += seqan3::simd::fill<index_simd_t>(1);
97 return *this;
98 }
99
102 {
103 counted_simd_iterator tmp{*this};
104 ++(*this);
105 return tmp;
106 }
107
110 {
111 return count_simd[0] - rhs.count_simd[0];
112 }
114
120 friend bool operator==(counted_simd_iterator const & lhs, counted_simd_iterator const & rhs) noexcept
121 {
122 return lhs.count_simd[0] == rhs.count_simd[0];
123 }
124
126 friend bool operator!=(counted_simd_iterator const & lhs, counted_simd_iterator const & rhs) noexcept
127 {
128 return !(lhs == rhs);
129 }
131};
132
137template <simd_concept index_simd_t>
138class iota_simd_view : public std::ranges::view_interface<iota_simd_view<index_simd_t>>
139{
140private:
145
150
151public:
155 iota_simd_view() = default;
156 iota_simd_view(iota_simd_view const &) noexcept = default;
160 ~iota_simd_view() = default;
161
172
177 iterator_type begin() const noexcept
178 {
180 }
181
183 iterator_type end() const noexcept
184 {
185 return iterator_type{end_index};
186 }
188};
189
194template <simd_concept index_simd_t>
196{
199
207 constexpr auto operator()(index_scalar_type const begin_index, index_scalar_type const end_index) const
208 {
209 return iota_simd_view<index_simd_t>{begin_index, end_index};
210 }
211};
212} // namespace seqan3::detail
213
214namespace seqan3::views
215{
216
270template <simd_concept index_simd_t>
272
273} // namespace seqan3::views
274
275#ifdef __cpp_lib_ranges
276namespace std::ranges
277{
279template <seqan3::simd_concept index_simd_t>
280inline constexpr bool enable_borrowed_range<seqan3::detail::iota_simd_view<index_simd_t>> = true;
282} // namespace std::ranges
283#endif // __cpp_lib_ranges
Provides algorithms to modify seqan3::simd::simd_type.
Implements a special version of a counted iterator over a simd vector.
Definition iota_simd.hpp:35
value_type reference
The reference type.
Definition iota_simd.hpp:47
index_simd_t value_type
The value type.
Definition iota_simd.hpp:45
void pointer
The pointer type.
Definition iota_simd.hpp:49
~counted_simd_iterator()=default
Defaulted.
friend bool operator!=(counted_simd_iterator const &lhs, counted_simd_iterator const &rhs) noexcept
Tests whether lhs != rhs.
Definition iota_simd.hpp:126
index_simd_t count_simd
The currently represented count.
Definition iota_simd.hpp:38
counted_simd_iterator(index_scalar_t const scalar_index) noexcept
Constructs and initialises the iterator with the given index.
Definition iota_simd.hpp:73
difference_type operator-(counted_simd_iterator const &rhs) const
Returns the distance between two iterators.
Definition iota_simd.hpp:109
counted_simd_iterator & operator=(counted_simd_iterator &&)=default
Defaulted.
counted_simd_iterator operator++(int)
Increments the iterator and returns the iterator pointing to the previous index.
Definition iota_simd.hpp:101
counted_simd_iterator & operator++()
Increments the iterator.
Definition iota_simd.hpp:94
friend bool operator==(counted_simd_iterator const &lhs, counted_simd_iterator const &rhs) noexcept
Tests whether lhs == rhs.
Definition iota_simd.hpp:120
reference operator*() const
Return the current simd index.
Definition iota_simd.hpp:83
counted_simd_iterator(counted_simd_iterator &&)=default
Defaulted.
counted_simd_iterator & operator=(counted_simd_iterator const &)=default
Defaulted.
counted_simd_iterator()=default
Defaulted.
counted_simd_iterator(counted_simd_iterator const &)=default
Defaulted.
The simd iota view.
Definition iota_simd.hpp:139
typename simd_traits< index_simd_t >::scalar_type index_scalar_type
The underlying scalar type.
Definition iota_simd.hpp:142
iterator_type begin() const noexcept
Returns seqan3::detail::counted_simd_iterator pointing to the begin of the range.
Definition iota_simd.hpp:177
iota_simd_view(iota_simd_view &&)=default
Defaulted.
iota_simd_view(iota_simd_view const &) noexcept=default
Defaulted.
iota_simd_view(index_scalar_type const begin_index, index_scalar_type const end_index)
Constructs the iota view from the given index pair.
Definition iota_simd.hpp:167
index_scalar_type begin_index
The begin index.
Definition iota_simd.hpp:147
iterator_type end() const noexcept
Returns seqan3::detail::counted_simd_iterator pointing to the end of the range.
Definition iota_simd.hpp:183
iota_simd_view & operator=(iota_simd_view &&)=default
Defaulted.
iota_simd_view()=default
Defaulted.
index_scalar_type end_index
The end index.
Definition iota_simd.hpp:149
iota_simd_view & operator=(iota_simd_view const &)=default
Defaulted.
~iota_simd_view()=default
Defaulted.
constexpr detail::iota_simd_view_fn< index_simd_t > iota_simd
An iota view over a simd vector.
Definition iota_simd.hpp:271
The internal SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
The SeqAn namespace for views.
Definition char_strictly_to.hpp:19
Provides seqan3::simd::simd_traits.
The view adaptor returning the seqan3::detail::iota_simd_view.
Definition iota_simd.hpp:196
constexpr auto operator()(index_scalar_type const begin_index, index_scalar_type const end_index) const
Returns a simd iota view over the given range.
Definition iota_simd.hpp:207
typename simd_traits< index_simd_t >::scalar_type index_scalar_type
The underlying scalar type.
Definition iota_simd.hpp:198
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition simd_traits.hpp:38
Provides concepts that do not have equivalents in C++20.
Provides seqan3::simd::simd_concept.
Hide me