SeqAn3
The Modern C++ library for sequence analysis.
kmer_hash.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, 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 <range/v3/view/sliding.hpp>
16 
20 #include <seqan3/std/ranges>
21 
22 namespace seqan3::detail
23 {
24 // ============================================================================
25 // kmer_hash_fn (adaptor definition)
26 // ============================================================================
27 
30 struct kmer_hash_fn
31 {
33  constexpr auto operator()(size_t const k) const noexcept
34  {
35  return detail::adaptor_from_functor{*this, k};
36  }
37 
44  template <std::ranges::ViewableRange urng_t>
46  requires Semialphabet<reference_t<urng_t>>
48  constexpr auto operator()(urng_t && urange, size_t const k) const noexcept
49  {
50  return std::forward<urng_t>(urange) | ranges::view::sliding(k) | std::view::transform(
51  [] (auto const in)
52  {
54  return h(in);
55  });
56  }
57 };
59 
60 } // namespace seqan3::detail
61 
62 namespace seqan3::view
63 {
106  inline auto constexpr kmer_hash = detail::kmer_hash_fn{};
107 } // namespace seqan3::view
auto constexpr kmer_hash
A view that calls std::hash on each substring of length k in the input range.
Definition: kmer_hash.hpp:106
Auxiliary header for the view submodule .
Adaptations of concepts from the Ranges TS.
The SeqAn3 namespace for views.
Definition: aligned_sequence_concept.hpp:35
Core alphabet concept and free function/type trait wrappers.
Provides various transformation traits used by the range module.
constexpr auto transform
A range adaptor that takes a invocable and returns a view of the elements with the invocable applied...
Definition: ranges:911