SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
search_scheme_precomputed.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 <array>
16 #include <vector>
17 
18 #include <seqan3/core/platform.hpp>
19 
20 namespace seqan3::detail
21 {
22 
27 template <uint8_t nbr_blocks>
30 struct search
31 {
33  typedef std::array<size_t, nbr_blocks> blocks_length_type;
34 
41 
43  constexpr uint8_t blocks() const noexcept
44  {
45  return nbr_blocks;
46  }
47 };
48 
51 struct search_dyn
52 {
54  typedef std::vector<size_t> blocks_length_type;
55 
62 
64  uint8_t blocks() const noexcept
65  {
66  return pi.size();
67  }
68 };
69 
71 template <uint8_t nbr_searches, uint8_t nbr_blocks>
72 using search_scheme_type = std::array<search<nbr_blocks>, nbr_searches>;
73 
75 using search_scheme_dyn_type = std::vector<search_dyn>;
76 
85 template <uint8_t min_error, uint8_t max_error>
86 inline int constexpr optimum_search_scheme;
87 
89 
90 template <>
91 inline search_scheme_type<1, 1> constexpr optimum_search_scheme<0, 0>
92 {{
93  {{1}, {0}, {0}}
94 }};
95 
96 template <>
97 inline search_scheme_type<2, 2> constexpr optimum_search_scheme<0, 1>
98 {{
99  {{1, 2}, {0, 0}, {0, 1}},
100  {{2, 1}, {0, 1}, {0, 1}}
101 }};
102 
103 template <>
104 inline search_scheme_type<2, 2> constexpr optimum_search_scheme<1, 1>
105 {{
106  {{1, 2}, {0, 1}, {0, 1}},
107  {{2, 1}, {0, 1}, {0, 1}}
108 }};
109 
110 template <>
111 inline search_scheme_type<3, 4> constexpr optimum_search_scheme<0, 2>
112 {{
113  {{1, 2, 3, 4}, {0, 0, 1, 1}, {0, 0, 2, 2}},
114  {{3, 2, 1, 4}, {0, 0, 0, 0}, {0, 1, 1, 2}},
115  {{4, 3, 2, 1}, {0, 0, 0, 2}, {0, 1, 2, 2}}
116 }};
117 
118 template <>
119 inline search_scheme_type<3, 4> constexpr optimum_search_scheme<1, 2>
120 {{
121  {{1, 2, 3, 4}, {0, 0, 0, 1}, {0, 0, 2, 2}},
122  {{3, 2, 1, 4}, {0, 0, 1, 1}, {0, 1, 1, 2}},
123  {{4, 3, 2, 1}, {0, 0, 0, 2}, {0, 1, 2, 2}}
124 }};
125 
126 template <>
127 inline search_scheme_type<3, 4> constexpr optimum_search_scheme<2, 2>
128 {{
129  {{4, 3, 2, 1}, {0, 0, 1, 2}, {0, 0, 2, 2}},
130  {{2, 3, 4, 1}, {0, 0, 0, 2}, {0, 1, 1, 2}},
131  {{1, 2, 3, 4}, {0, 0, 0, 2}, {0, 1, 2, 2}}
132 }};
133 
134 template <>
135 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<0, 3>
136 {{
137  // TODO: benchmark whether the first search is really the fastest one (see \details of optimum_search_scheme)
138  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 0}, {0, 0, 3, 3, 3}},
139  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 1}, {0, 1, 1, 2, 3}},
140  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 2}, {0, 1, 2, 2, 3}},
141  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
142 }};
143 
144 template <>
145 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<1, 3>
146 {{
147  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 1}, {0, 0, 3, 3, 3}},
148  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 1}, {0, 1, 1, 2, 3}},
149  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 2}, {0, 1, 2, 2, 3}},
150  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
151 }};
152 
153 template <>
154 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<2, 3>
155 {{
156  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 2}, {0, 0, 3, 3, 3}},
157  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 2}, {0, 1, 1, 2, 3}},
158  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 2}, {0, 1, 2, 2, 3}},
159  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
160 }};
161 
162 template <>
163 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<3, 3>
164 {{
165  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 3}, {0, 0, 3, 3, 3}},
166  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 3}, {0, 1, 1, 2, 3}},
167  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 3}, {0, 1, 2, 2, 3}},
168  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
169 }};
170 
171 // TODO: add the following missing optimum search schemes (computation has not finished yet)
172 // optimum_search_scheme<i, 4>, 0 < i <= 4
173 
175 
177 
178 } // namespace seqan3::detail
vector
std::vector::size
T size(T... args)
array
platform.hpp
Provides platform and dependency checks.
seqan3::search
auto search(queries_t &&queries, index_t const &index, configuration_t const &cfg=search_cfg::default_configuration)
Search a query or a range of queries in an index.
Definition: search.hpp:105