SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
concept.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 <type_traits>
16 
17 #include <sdsl/suffix_arrays.hpp>
18 
20 #include <seqan3/range/concept.hpp>
22 
23 namespace seqan3::detail
24 {
25 
30  // ============================================================================
31  // sdsl_index
32  // ============================================================================
33 
37 template <typename t>
39 SEQAN3_CONCEPT sdsl_index = requires (t sdsl_index)
40 {
41  typename t::size_type;
42 
43  SEQAN3_RETURN_TYPE_CONSTRAINT(sdsl_index.size(), std::same_as, typename t::size_type);
44  { sdsl_index[0] }; // suffix array access
45  SEQAN3_RETURN_TYPE_CONSTRAINT(sdsl_index.comp2char[0], std::same_as, uint8_t);
46  SEQAN3_RETURN_TYPE_CONSTRAINT(sdsl_index.char2comp[0], std::same_as, uint8_t);
47  { sdsl_index.sigma };
48  { sdsl_index.C[0] };
49 
50  requires requires (t sdsl_index, typename t::char_type const c, typename t::size_type const lb,
51  typename t::size_type const rb, sdsl::int_vector<8> const text)
52  {
53  { sdsl_index.bwt.rank(lb, c) };
54  { sdsl_index.wavelet_tree.lex_count(lb, rb, c) };
55  { sdsl::construct_im(sdsl_index, text, 0) };
56  };
57 };
59 
69 
71 } // namespace seqan3::detail
72 
73 namespace seqan3
74 {
75 
80 enum text_layout : bool
82 {
87 };
88 
89 // ============================================================================
90 // fm_index_specialisation
91 // ============================================================================
92 
98 template <typename t>
100 SEQAN3_CONCEPT fm_index_specialisation = std::semiregular<t> && requires (t index)
101 {
102  typename t::alphabet_type;
103  typename t::size_type;
104  typename t::cursor_type;
105 
106  // NOTE: circular dependency
107  // requires fm_index_cursor_specialisation<typename t::cursor_type>;
108  requires requires (t index, std::conditional_t<t::text_layout_mode == text_layout::collection,
111  {
112  { t(text) };
113  };
114 
115  SEQAN3_RETURN_TYPE_CONSTRAINT(index.cursor(), std::same_as, typename t::cursor_type);
116 
117  SEQAN3_RETURN_TYPE_CONSTRAINT(index.size(), std::same_as, typename t::size_type);
118  SEQAN3_RETURN_TYPE_CONSTRAINT(index.empty(), std::same_as, bool);
119 };
121 
140 // ============================================================================
141 // fm_index_cursor_specialisation
142 // ============================================================================
143 
149 template <typename t>
151 SEQAN3_CONCEPT fm_index_cursor_specialisation = std::semiregular<t> && requires (t cur)
152 {
153  typename t::index_type;
154  typename t::size_type;
155 
157 
158  requires requires (typename t::index_type const index) { { t(index) }; };
159 
160  requires requires (t cur,
161  typename t::index_type::alphabet_type const c,
163  std::conditional_t<t::index_type::text_layout_mode == text_layout::collection,
166  {
167  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.extend_right(), std::same_as, bool);
168  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.extend_right(c), std::same_as, bool);
169  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.extend_right(seq), std::same_as, bool);
170  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.cycle_back(), std::same_as, bool);
171  { cur.path_label(text) };
172  };
173 
174  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.last_rank(), std::same_as, typename t::size_type);
175  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.query_length(), std::same_as, typename t::size_type);
176  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.count(), std::same_as, typename t::size_type);
177  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.locate(),
179  { cur.lazy_locate() };
180 };
182 
195 // ============================================================================
196 // bi_fm_index_specialisation
197 // ============================================================================
198 
204 template <typename t>
206 SEQAN3_CONCEPT bi_fm_index_specialisation = fm_index_specialisation<t> && requires (t index)
207 {
208  typename t::cursor_type; // already required by fm_index_specialisation but has a different documentation
209  typename t::fwd_cursor_type;
210 
211  // NOTE: circular dependency
212  // requires bi_fm_index_cursor_specialisation<typename t::cursor_type>;
213 
214  SEQAN3_RETURN_TYPE_CONSTRAINT(index.fwd_cursor(), std::same_as, typename t::fwd_cursor_type);
215 };
217 
230 // ============================================================================
231 // bi_fm_index_cursor_specialisation
232 // ============================================================================
233 
239 template <typename t>
241 SEQAN3_CONCEPT bi_fm_index_cursor_specialisation = fm_index_cursor_specialisation<t> && requires (t cur)
242 {
244 
245  requires requires (typename t::index_type const index) { { t(index) }; };
246 
247  requires requires (t cur,
248  typename t::index_type::alphabet_type const c,
250  {
251  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.extend_left(), std::same_as, bool);
252  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.extend_left(c), std::same_as, bool);
253  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.extend_left(seq), std::same_as, bool);
254  SEQAN3_RETURN_TYPE_CONSTRAINT(cur.cycle_front(), std::same_as, bool);
255  };
256 
257 };
259 
273 
275 } // namespace seqan3
seqan3::single
@ single
The text is a single range.
Definition: concept.hpp:84
std::pair
std::vector
concept.hpp
Adaptations of concepts from the standard library.
bi_fm_index_cursor_specialisation
Concept for bidirectional FM index cursors.
concept.hpp
Additional non-standard concepts for ranges.
seqan3::seq
constexpr sequenced_policy seq
Global execution policy object for sequenced execution policy.
Definition: execution.hpp:54
seqan3::text_layout
text_layout
The possible text layouts (single, collection) the seqan3::fm_index and seqan3::bi_fm_index can suppo...
Definition: concept.hpp:82
seqan3::collection
@ collection
The text is a range of ranges.
Definition: concept.hpp:86
range.hpp
Provides various transformation traits used by the range module.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
SEQAN3_RETURN_TYPE_CONSTRAINT
#define SEQAN3_RETURN_TYPE_CONSTRAINT(expression, concept_name,...)
Same as writing {expression} -> concept_name<type1[, ...]> in a concept definition.
Definition: platform.hpp:57
bi_fm_index_specialisation
Concept for bidirectional FM indices.
std::conditional_t
fm_index_specialisation
Concept for unidirectional FM indices.
fm_index_cursor_specialisation
Concept for unidirectional FM index cursors.