SeqAn3
The Modern C++ library for sequence analysis.
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 
16 #include <seqan3/std/ranges>
17 
18 namespace std
19 {
24 template <typename alphabet_t>
28 struct hash<alphabet_t>
29 {
37  size_t operator()(alphabet_t const character) const noexcept
38  {
39  using seqan3::to_rank;
40  return to_rank(character);
41  }
42 };
43 
49 template <ranges::InputRange urng_t>
53 struct hash<urng_t>
54 {
61  size_t operator()(urng_t const & range) const noexcept
62  {
63  using alphabet_t = seqan3::value_type_t<urng_t>;
64  size_t result{0};
65  hash<alphabet_t> h{};
66  for (auto const character : range)
67  {
68  result *= seqan3::alphabet_size<alphabet_t>;
69  result += h(character);
70  }
71  return result;
72  }
73 };
74 } // namespace std
The basis for seqan3::Alphabet, but requires only rank interface (not char).
typename value_type< t >::type value_type_t
Shortcut for seqan3::value_type (TransformationTrait shortcut).
Definition: pre.hpp:48
constexpr auto to_rank
Return the rank representation of a (semi-)alphabet object.
Definition: concept.hpp:103
SeqAn specific customisations in the standard namespace.
size_t operator()(alphabet_t const character) const noexcept
Compute the hash for a character.
Definition: hash.hpp:37
Adaptations of concepts from the Ranges TS.
size_t operator()(urng_t const &range) const noexcept
Compute the hash for a range of characters.
Definition: hash.hpp:61
Struct for hashing a character.
Definition: hash.hpp:28
Provides various transformation traits used by the range module.