SeqAn3 3.2.0-rc.1
The Modern C++ library for sequence analysis.
iota_simd.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
15#include <seqan3/std/ranges>
16
21
22namespace seqan3::detail
23{
24
36template <simd_concept index_simd_t>
38{
39private:
41 index_simd_t count_simd{};
42
43public:
48 using value_type = index_simd_t;
52 using pointer = void;
58
68
75 template <arithmetic index_scalar_t>
76 explicit counted_simd_iterator(index_scalar_t const scalar_index) noexcept :
77 count_simd{simd::fill<index_simd_t>(scalar_index)}
78 {}
80
87 {
88 return count_simd;
89 }
91
98 {
99 count_simd += seqan3::simd::fill<index_simd_t>(1);
100 return *this;
101 }
102
105 {
106 counted_simd_iterator tmp{*this};
107 ++(*this);
108 return tmp;
109 }
110
113 {
114 return count_simd[0] - rhs.count_simd[0];
115 }
117
123 friend bool operator==(counted_simd_iterator const & lhs, counted_simd_iterator const & rhs) noexcept
124 {
125 return lhs.count_simd[0] == rhs.count_simd[0];
126 }
127
129 friend bool operator!=(counted_simd_iterator const & lhs, counted_simd_iterator const & rhs) noexcept
130 {
131 return !(lhs == rhs);
132 }
134};
135
140template <simd_concept index_simd_t>
141class iota_simd_view : public std::ranges::view_interface<iota_simd_view<index_simd_t>>
142{
143private:
148
153
154public:
158 iota_simd_view() = default;
159 iota_simd_view(iota_simd_view const &) noexcept = default;
163 ~iota_simd_view() = default;
164
173 {}
175
180 iterator_type begin() const noexcept
181 {
183 }
184
186 iterator_type end() const noexcept
187 {
188 return iterator_type{end_index};
189 }
191};
192
197template <simd_concept index_simd_t>
199{
202
210 constexpr auto operator()(index_scalar_type const begin_index, index_scalar_type const end_index) const
211 {
212 return iota_simd_view<index_simd_t>{begin_index, end_index};
213 }
214};
215} // namespace seqan3::detail
216
217namespace seqan3::views
218{
219
273template <simd_concept index_simd_t>
275
276} // namespace seqan3::views
277
278namespace ranges
279{
281template <seqan3::simd_concept index_simd_t>
282inline constexpr bool enable_borrowed_range<seqan3::detail::iota_simd_view<index_simd_t>> = true;
284} // namespace ranges
285
286#ifdef __cpp_lib_ranges
287namespace std::ranges
288{
290template <seqan3::simd_concept index_simd_t>
291inline constexpr bool enable_borrowed_range<seqan3::detail::iota_simd_view<index_simd_t>> = true;
293} // namespace std::ranges
294#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:38
value_type reference
The reference type.
Definition: iota_simd.hpp:50
index_simd_t value_type
The value type.
Definition: iota_simd.hpp:48
void pointer
The pointer type.
Definition: iota_simd.hpp:52
~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:129
index_simd_t count_simd
The currently represented count.
Definition: iota_simd.hpp:41
counted_simd_iterator(index_scalar_t const scalar_index) noexcept
Constructs and initialises the iterator with the given index.
Definition: iota_simd.hpp:76
difference_type operator-(counted_simd_iterator const &rhs) const
Returns the distance between two iterators.
Definition: iota_simd.hpp:112
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:104
counted_simd_iterator & operator++()
Increments the iterator.
Definition: iota_simd.hpp:97
friend bool operator==(counted_simd_iterator const &lhs, counted_simd_iterator const &rhs) noexcept
Tests whether lhs == rhs.
Definition: iota_simd.hpp:123
reference operator*() const
Return the current simd index.
Definition: iota_simd.hpp:86
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:142
typename simd_traits< index_simd_t >::scalar_type index_scalar_type
The underlying scalar type.
Definition: iota_simd.hpp:145
iterator_type begin() const noexcept
Returns seqan3::detail::counted_simd_iterator pointing to the begin of the range.
Definition: iota_simd.hpp:180
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:170
index_scalar_type begin_index
The begin index.
Definition: iota_simd.hpp:150
iterator_type end() const noexcept
Returns seqan3::detail::counted_simd_iterator pointing to the end of the range.
Definition: iota_simd.hpp:186
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:152
iota_simd_view & operator=(iota_simd_view const &)=default
Defaulted.
~iota_simd_view()=default
Defaulted.
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
constexpr detail::iota_simd_view_fn< index_simd_t > iota_simd
An iota view over a simd vector.
Definition: iota_simd.hpp:274
The internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
The SeqAn namespace for views.
Definition: char_strictly_to.hpp:22
The <ranges> header from C++20's standard library.
Provides seqan3::simd::simd_traits.
The view adaptor returning the seqan3::detail::iota_simd_view.
Definition: iota_simd.hpp:199
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:210
typename simd_traits< index_simd_t >::scalar_type index_scalar_type
The underlying scalar type.
Definition: iota_simd.hpp:201
seqan3::simd::simd_traits is the trait class that provides uniform interface to the properties of sim...
Definition: simd_traits.hpp:41
Provides seqan3::simd::simd_concept.