SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range > Class Template Reference

Iterator for calculating hash values via a given seqan3::shape. More...

#include <seqan3/search/views/kmer_hash.hpp>

+ Inheritance diagram for seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >:

Public Types

Associated types
using difference_type = typename std::iter_difference_t< it_t >
 Type for distances between iterators.
 
using value_type = size_t
 Value type of this iterator.
 
using pointer = void
 The pointer type.
 
using reference = value_type
 Reference to value_type.
 
using iterator_concept = std::conditional_t< std::contiguous_iterator< it_t >, typename std::random_access_iterator_tag, detail::iterator_concept_tag_t< it_t > >
 Tag this class depending on which concept it_t models.
 
- Public Types inherited from seqan3::detail::maybe_iterator_category< maybe_const_iterator_t< const_range, urng_t > >
using iterator_category = MAYBE_PRESENT(std::iterator_traits< maybe_const_iterator_t< const_range, urng_t > >::iterator_category)
 The iterator category tag. (not always present!)
 

Public Member Functions

value_type operator* () const noexcept
 Return the hash value.
 
basic_iterator operator+ (difference_type const skip) const noexcept
 Forward copy of this iterator.
 
basic_iteratoroperator++ () noexcept
 Pre-increment.
 
basic_iterator operator++ (int) noexcept
 Post-increment.
 
basic_iteratoroperator+= (difference_type const skip) noexcept
 Forward this iterator.
 
basic_iterator operator- (difference_type const skip) const noexcept
 Return decremented copy of this iterator.
 
basic_iteratoroperator-- () noexcept
 Pre-decrement.
 
basic_iterator operator-- (int) noexcept
 Post-decrement.
 
basic_iteratoroperator-= (difference_type const skip) noexcept
 Decrement iterator by skip.
 
reference operator[] (difference_type const n) const
 Move the iterator by a given offset and return the corresponding hash value.
 
Constructors, destructor and assignment
constexpr basic_iterator ()=default
 Defaulted.
 
constexpr basic_iterator (basic_iterator const &)=default
 Defaulted.
 
constexpr basic_iterator (basic_iterator &&)=default
 Defaulted.
 
constexpr basic_iteratoroperator= (basic_iterator const &)=default
 Defaulted.
 
constexpr basic_iteratoroperator= (basic_iterator &&)=default
 Defaulted.
 
 ~basic_iterator ()=default
 Defaulted.
 
constexpr basic_iterator (basic_iterator<!const_range > const &it) noexcept
 Allow iterator on a const range to be constructible from an iterator over a non-const range.
 
 basic_iterator (it_t it_start, sentinel_t it_end, shape s_)
 Construct from a given iterator on the text and a seqan3::shape. /param[in] it_start Iterator pointing to the first position of the text. /param[in] it_end Sentinel pointing to the end of the text. /param[in] s_ The seqan3::shape that determines which positions participate in hashing.
 
 basic_iterator (it_t it_start, sentinel_t it_end, shape s_, bool is_end)
 Construct from a given iterator on the text and a seqan3::shape. /param[in] it_start Iterator pointing to the first position of the text. /param[in] it_end Sentinel pointing to the end of the text. /param[in] s_ The seqan3::shape that determines which positions participate in hashing. /param[in] is_end Indicates that this iterator should point to the end of the text.
 

Private Types

using alphabet_t = std::iter_value_t< it_t >
 The alphabet type of the passed iterator.
 
using it_t = maybe_const_iterator_t< const_range, urng_t >
 The iterator type of the underlying range.
 
using sentinel_t = maybe_const_sentinel_t< const_range, urng_t >
 The sentinel type of the underlying range.
 

Private Member Functions

void hash_backward ()
 Decrements iterator by 1.
 
void hash_backward (difference_type const skip)
 Decrements iterator by skip.
 
void hash_forward ()
 Increments iterator by 1.
 
void hash_forward (difference_type const skip)
 Increments iterator by skip.
 
void hash_full ()
 Calculates a hash value by explicitly looking at each position.
 
void hash_roll_backward ()
 Calculates the previous hash value via rolling hash.
 
void hash_roll_forward ()
 Calculates the next hash value via rolling hash.
 

Private Attributes

size_t hash_value {0}
 The hash value.
 
size_t roll_factor {0}
 The factor for the left most position of the hash value.
 
shape shape_
 The shape to use.
 
it_t text_left
 Iterator to the leftmost position of the k-mer.
 
it_t text_right
 Iterator to the rightmost position of the k-mer.
 

Static Private Attributes

static constexpr auto const sigma {alphabet_size<alphabet_t>}
 The alphabet size.
 

Friends

basic_iterator operator+ (difference_type const skip, basic_iterator const &it) noexcept
 Non-member operator+ delegates to non-friend operator+.
 
difference_type operator- (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Return offset between two iterator's positions.
 
difference_type operator- (basic_iterator const &lhs, sentinel_t const &rhs) noexcept
 Return offset this and remote sentinel's position.
 
basic_iterator operator- (difference_type const skip, basic_iterator const &it) noexcept
 Non-member operator- delegates to non-friend operator-.
 
difference_type operator- (sentinel_t const &lhs, basic_iterator const &rhs) noexcept
 Return offset between remote sentinel's position and this.
 
Comparison operators

bool operator== (basic_iterator const &lhs, sentinel_t const &rhs) noexcept
 Compare to iterator on text.
 
bool operator== (sentinel_t const &lhs, basic_iterator const &rhs) noexcept
 Compare to iterator on text.
 
bool operator== (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Compare to another basic_iterator.
 
bool operator!= (basic_iterator const &lhs, sentinel_t const &rhs) noexcept
 Compare to iterator on text.
 
bool operator!= (sentinel_t const &lhs, basic_iterator const &rhs) noexcept
 Compare to iterator on text.
 
bool operator!= (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Compare to another basic_iterator.
 
bool operator< (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Compare to another basic_iterator.
 
bool operator> (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Compare to another basic_iterator.
 
bool operator<= (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Compare to another basic_iterator.
 
bool operator>= (basic_iterator const &lhs, basic_iterator const &rhs) noexcept
 Compare to another basic_iterator.
 

Detailed Description

template<std::ranges::view urng_t>
template<bool const_range>
class seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >

Iterator for calculating hash values via a given seqan3::shape.

Template Parameters
urng_tType of the text. Must model std::forward_range. Reference type must model seqan3::semialphabet.

The basic_iterator can be used to iterate over the hash values of a text. The basic_iterator needs an iterator of the text and a seqan3::shape that defines how to hash the text.

Depending on the type of the iterator passed to the basic_iterator, different functionality is available:

Concept modelled by passed text iterator Available functions
std::forward_iterator Comparison operators
Pre-increment (++it)
Post-increment (it++)
Indirection operator (*it)
std::bidirectional_iterator Pre-decrement (--it)
Post-decrement (it--)
std::random_access_iterator Forward (it +=)
Forward copy (it +)
Decrement(it -=)
Decrement copy (it -)
Difference (it1 - it2)
Subscript (it[])

When using a gapped seqan3::shape, the 0s of the seqan3::shape are virtually removed from the hashed k-mer. Note that any shape is expected to start with a 1 and end with a 1.

This entity is experimental and subject to change in the future.

Implementation detail

To avoid dereferencing the sentinel when iterating, the basic_iterator computes the hash value up until the second to last position and performs the addition of the last position upon access (operator* and operator[]).

Constructor & Destructor Documentation

◆ basic_iterator() [1/2]

template<std::ranges::view urng_t>
template<bool const_range>
seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::basic_iterator ( it_t  it_start,
sentinel_t  it_end,
shape  s_ 
)
inline

Construct from a given iterator on the text and a seqan3::shape. /param[in] it_start Iterator pointing to the first position of the text. /param[in] it_end Sentinel pointing to the end of the text. /param[in] s_ The seqan3::shape that determines which positions participate in hashing.

Complexity

Linear in size of shape.

◆ basic_iterator() [2/2]

template<std::ranges::view urng_t>
template<bool const_range>
seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::basic_iterator ( it_t  it_start,
sentinel_t  it_end,
shape  s_,
bool  is_end 
)
inline

Construct from a given iterator on the text and a seqan3::shape. /param[in] it_start Iterator pointing to the first position of the text. /param[in] it_end Sentinel pointing to the end of the text. /param[in] s_ The seqan3::shape that determines which positions participate in hashing. /param[in] is_end Indicates that this iterator should point to the end of the text.

If we have a common_range as underlying range, we want to preserve this property. This means that we need to have a basic_iterator that can act as end for the kmer_hash_view, i.e. the text_right iterator is equal to the end iterator of the underlying range. However, we still need to do some initialisation via hash_full: When using std::views::reverse, we start iterating from the end and decrement the iterator. After calling hash_full, we need to reset our text_right iterator to point to the end again.

Another difference to the other constructor is that we need to do some work to determine the position of the text_left iterator. Note that we use std::ranges::next instead of std::ranges::prev because the latter only works for bidirectional ranges. *

Complexity

Linear in size of shape.

Member Function Documentation

◆ hash_backward() [1/2]

template<std::ranges::view urng_t>
template<bool const_range>
void seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::hash_backward ( )
inlineprivate

Decrements iterator by 1.

Attention
This function is only available if it_t models std::bidirectional_iterator.

◆ hash_backward() [2/2]

template<std::ranges::view urng_t>
template<bool const_range>
void seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::hash_backward ( difference_type const  skip)
inlineprivate

Decrements iterator by skip.

Parameters
skipAmount to decrement.
Attention
This function is only available if it_t models std::bidirectional_iterator.

◆ hash_forward()

template<std::ranges::view urng_t>
template<bool const_range>
void seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::hash_forward ( difference_type const  skip)
inlineprivate

Increments iterator by skip.

Parameters
skipAmount to increment.
Attention
This function is only available if it_t models std::random_access_iterator.

◆ hash_roll_backward()

template<std::ranges::view urng_t>
template<bool const_range>
void seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::hash_roll_backward ( )
inlineprivate

Calculates the previous hash value via rolling hash.

Attention
This function is only available if it_t models std::bidirectional_iterator.

◆ operator+()

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator+ ( difference_type const  skip) const
inlinenoexcept

Forward copy of this iterator.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator+=()

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator & seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator+= ( difference_type const  skip)
inlinenoexcept

Forward this iterator.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator-()

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator- ( difference_type const  skip) const
inlinenoexcept

Return decremented copy of this iterator.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator--() [1/2]

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator & seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator-- ( )
inlinenoexcept

Pre-decrement.

Attention
This function is only available if it_t models std::bidirectional_iterator.

◆ operator--() [2/2]

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator-- ( int  )
inlinenoexcept

Post-decrement.

Attention
This function is only available if it_t models std::bidirectional_iterator.

◆ operator-=()

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator & seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator-= ( difference_type const  skip)
inlinenoexcept

Decrement iterator by skip.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator[]()

template<std::ranges::view urng_t>
template<bool const_range>
reference seqan3::detail::kmer_hash_view< urng_t >::basic_iterator< const_range >::operator[] ( difference_type const  n) const
inline

Move the iterator by a given offset and return the corresponding hash value.

Attention
This function is only available if it_t models std::random_access_iterator.

Friends And Related Symbol Documentation

◆ operator+

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator operator+ ( difference_type const  skip,
basic_iterator< const_range > const &  it 
)
friend

Non-member operator+ delegates to non-friend operator+.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator- [1/4]

template<std::ranges::view urng_t>
template<bool const_range>
difference_type operator- ( basic_iterator< const_range > const &  lhs,
basic_iterator< const_range > const &  rhs 
)
friend

Return offset between two iterator's positions.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator- [2/4]

template<std::ranges::view urng_t>
template<bool const_range>
difference_type operator- ( basic_iterator< const_range > const &  lhs,
sentinel_t const &  rhs 
)
friend

Return offset this and remote sentinel's position.

Attention
This function is only available if it_t and sentinel_t model std::sized_sentinel_for.

◆ operator- [3/4]

template<std::ranges::view urng_t>
template<bool const_range>
basic_iterator operator- ( difference_type const  skip,
basic_iterator< const_range > const &  it 
)
friend

Non-member operator- delegates to non-friend operator-.

Attention
This function is only available if it_t models std::random_access_iterator.

◆ operator- [4/4]

template<std::ranges::view urng_t>
template<bool const_range>
difference_type operator- ( sentinel_t const &  lhs,
basic_iterator< const_range > const &  rhs 
)
friend

Return offset between remote sentinel's position and this.

Attention
This function is only available if sentinel_t and it_t model std::sized_sentinel_for.

The documentation for this class was generated from the following file:
Hide me