SeqAn3
search_scheme_precomputed.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 namespace seqan3::detail
43 {
44 
49 template <uint8_t nbr_blocks>
52 struct search
53 {
55  typedef std::array<size_t, nbr_blocks> blocks_length_type;
56 
58  std::array<uint8_t, nbr_blocks> pi;
60  std::array<uint8_t, nbr_blocks> l;
62  std::array<uint8_t, nbr_blocks> u;
63 
65  constexpr uint8_t blocks() const noexcept
66  {
67  return nbr_blocks;
68  }
69 };
70 
73 struct search_dyn
74 {
76  typedef std::vector<size_t> blocks_length_type;
77 
79  std::vector<uint8_t> pi;
81  std::vector<uint8_t> l;
83  std::vector<uint8_t> u;
84 
86  uint8_t blocks() const noexcept
87  {
88  return pi.size();
89  }
90 };
91 
93 template <uint8_t nbr_searches, uint8_t nbr_blocks>
94 using search_scheme_type = std::array<search<nbr_blocks>, nbr_searches>;
95 
97 using search_scheme_dyn_type = std::vector<search_dyn>;
98 
107 template <uint8_t min_error, uint8_t max_error>
108 inline int constexpr optimum_search_scheme;
109 
111 
112 template <>
113 inline search_scheme_type<1, 1> constexpr optimum_search_scheme<0, 0>
114 {{
115  {{1}, {0}, {0}}
116 }};
117 
118 template <>
119 inline search_scheme_type<2, 2> constexpr optimum_search_scheme<0, 1>
120 {{
121  {{1, 2}, {0, 0}, {0, 1}},
122  {{2, 1}, {0, 1}, {0, 1}}
123 }};
124 
125 template <>
126 inline search_scheme_type<2, 2> constexpr optimum_search_scheme<1, 1>
127 {{
128  {{1, 2}, {0, 1}, {0, 1}},
129  {{2, 1}, {0, 1}, {0, 1}}
130 }};
131 
132 template <>
133 inline search_scheme_type<3, 4> constexpr optimum_search_scheme<0, 2>
134 {{
135  {{1, 2, 3, 4}, {0, 0, 1, 1}, {0, 0, 2, 2}},
136  {{3, 2, 1, 4}, {0, 0, 0, 0}, {0, 1, 1, 2}},
137  {{4, 3, 2, 1}, {0, 0, 0, 2}, {0, 1, 2, 2}}
138 }};
139 
140 template <>
141 inline search_scheme_type<3, 4> constexpr optimum_search_scheme<1, 2>
142 {{
143  {{1, 2, 3, 4}, {0, 0, 0, 1}, {0, 0, 2, 2}},
144  {{3, 2, 1, 4}, {0, 0, 1, 1}, {0, 1, 1, 2}},
145  {{4, 3, 2, 1}, {0, 0, 0, 2}, {0, 1, 2, 2}}
146 }};
147 
148 template <>
149 inline search_scheme_type<3, 4> constexpr optimum_search_scheme<2, 2>
150 {{
151  {{4, 3, 2, 1}, {0, 0, 1, 2}, {0, 0, 2, 2}},
152  {{2, 3, 4, 1}, {0, 0, 0, 2}, {0, 1, 1, 2}},
153  {{1, 2, 3, 4}, {0, 0, 0, 2}, {0, 1, 2, 2}}
154 }};
155 
156 template <>
157 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<0, 3>
158 {{
159  // TODO: benchmark whether the first search is really the fastest one (see \details of optimum_search_scheme)
160  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 0}, {0, 0, 3, 3, 3}},
161  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 1}, {0, 1, 1, 2, 3}},
162  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 2}, {0, 1, 2, 2, 3}},
163  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
164 }};
165 
166 template <>
167 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<1, 3>
168 {{
169  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 1}, {0, 0, 3, 3, 3}},
170  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 1}, {0, 1, 1, 2, 3}},
171  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 2}, {0, 1, 2, 2, 3}},
172  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
173 }};
174 
175 template <>
176 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<2, 3>
177 {{
178  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 2}, {0, 0, 3, 3, 3}},
179  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 2}, {0, 1, 1, 2, 3}},
180  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 2}, {0, 1, 2, 2, 3}},
181  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
182 }};
183 
184 template <>
185 inline search_scheme_type<4, 5> constexpr optimum_search_scheme<3, 3>
186 {{
187  {{5, 4, 3, 2, 1}, {0, 0, 0, 0, 3}, {0, 0, 3, 3, 3}},
188  {{3, 4, 5, 2, 1}, {0, 0, 1, 1, 3}, {0, 1, 1, 2, 3}},
189  {{2, 3, 4, 5, 1}, {0, 0, 0, 2, 3}, {0, 1, 2, 2, 3}},
190  {{1, 2, 3, 4, 5}, {0, 0, 0, 0, 3}, {0, 2, 2, 3, 3}}
191 }};
192 
193 // TODO: add the following missing optimum search schemes (computation has not finished yet)
194 // optimum_search_scheme<i, 4>, 0 < i <= 4
195 
197 
199 
200 } // namespace seqan3::detail
auto search(index_t const &index, queries_t &&queries, configuration_t const &cfg)
Search a query or a range of queries in an index.
Definition: search.hpp:82
Definition: aligned_sequence_concept.hpp:288