45 #include <sdsl/suffix_trees.hpp> 47 #include <range/v3/view/iota.hpp> 48 #include <range/v3/view/slice.hpp> 90 template <
typename index_t>
111 using node_type = detail::fm_index_iterator_node<index_t>;
114 using sdsl_char_type =
typename index_type::sdsl_char_type;
126 template <
typename _index_t>
139 template <detail::sdsl_index_concept csa_t>
140 bool backward_search(csa_t
const & csa, sdsl_char_type
const c,
size_type & l,
size_type & r)
const noexcept
142 assert(l <= r && r < csa.size());
149 cc = csa.char2comp[c];
150 if (cc == 0 && c > 0)
155 if (l == 0 && r + 1 == csa.size())
158 _r = csa.C[cc + 1] - 1;
163 _l = c_begin + csa.bwt.rank(l, c);
164 _r = c_begin + csa.bwt.rank(r + 1, c) - 1;
171 assert(r + 1 - l >= 0);
191 fm_index_iterator(index_t const & _index) noexcept : index(&_index), node({0, _index.index.size() - 1, 0, 0})
209 assert(index !=
nullptr);
210 assert(node != rhs.node || (
query_length() == 0 || (parent_lb == rhs.parent_lb && parent_rb == rhs.parent_rb)));
214 return node == rhs.node;
231 assert(index !=
nullptr);
233 return !(*
this == rhs);
257 assert(index !=
nullptr);
259 sdsl_char_type c = 1;
261 while (c < index->index.sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb))
266 if (c != index->index.sigma)
270 node = {_lb, _rb, node.depth + 1, c};
290 template <alphabet_concept
char_t>
296 assert(index !=
nullptr);
300 sdsl_char_type c_char =
to_rank(c) + 1;
302 if (backward_search(index->index, c_char, _lb, _rb))
306 node = {_lb, _rb, node.depth + 1, c_char};
328 template <std::ranges::RandomAccessRange seq_t>
334 auto first = seq.begin();
335 auto last = seq.end();
337 assert(index !=
nullptr);
340 size_type new_parent_lb = parent_lb, new_parent_rb = parent_rb;
344 for (
auto it = first; it != last; ++it)
350 if (!backward_search(index->index, c, _lb, _rb))
354 parent_lb = new_parent_lb;
355 parent_rb = new_parent_rb;
356 node = {_lb, _rb, last - first + node.depth, c};
390 assert(parent_lb <= parent_rb);
392 sdsl_char_type c = node.last_char + 1;
393 size_type _lb = parent_lb, _rb = parent_rb;
395 while (c < index->index.sigma && !backward_search(index->index, index->index.comp2char[c], _lb, _rb))
400 if (c != index->index.sigma)
402 node = {_lb, _rb, node.depth, c};
426 assert(index !=
nullptr &&
query_length() > 0 && parent_lb <= parent_rb);
428 typename index_t::char_type c;
429 assign_rank(c, index->index.comp2char[node.last_char] - 1);
449 assert(index !=
nullptr);
450 assert(node.depth != 0 || (node.lb == 0 && node.rb == index->size() - 1));
471 assert(index !=
nullptr && index->text !=
nullptr);
473 size_type const query_begin = offset() - index->index[node.lb];
474 return *index->text | ranges::view::slice(query_begin, query_begin +
query_length());
480 assert(index !=
nullptr && index->text !=
nullptr);
498 assert(index !=
nullptr);
500 return 1 + node.rb - node.lb;
516 assert(index !=
nullptr);
518 std::vector<size_type> occ(
count());
519 for (
size_type i = 0; i < occ.size(); ++i)
521 occ[i] = offset() - index->index[node.lb + i];
540 assert(index !=
nullptr);
543 |
view::transform([*
this, _offset = offset()] (
auto sa_pos) {
return _offset - index->index[sa_pos]; });
constexpr simd_t iota(typename simd_traits< simd_t >::scalar_type const offset)
Fills a seqan3::simd::simd_type vector with the scalar values offset, offset+1, offset+2, ...
Definition: simd_algorithm.hpp:100
Provides the internal representation of a node of the seqan3::fm_index_iterator.
constexpr auto transform
A range adaptor that takes a invocable and returns a view of the elements with the invocable applied...
Definition: transform.hpp:95
bool cycle_back() noexcept
Tries to replace the rightmost character of the query by the next lexicographically larger character ...
Definition: fm_index_iterator.hpp:386
bool extend_right(seq_t &&seq) noexcept
Tries to extend the query by seq to the right.
Definition: fm_index_iterator.hpp:332
auto lazy_locate() const
Locates the occurrences of the searched query in the text on demand, i.e. a ranges::view is returned ...
Definition: fm_index_iterator.hpp:538
bool extend_right(char_t const c) noexcept
Tries to extend the query by the character c to the right.
Definition: fm_index_iterator.hpp:294
Provides an alphabet mapping that implements an identity map (i.e. each character is mapped to its ra...
size_type query_length() const noexcept
Returns the length of the searched query.
Definition: fm_index_iterator.hpp:447
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
The SeqAn FM Index Iterator.
Definition: fm_index_iterator.hpp:91
bool extend_right() noexcept
Tries to extend the query by the smallest possible character to the right such that the query is foun...
Definition: fm_index_iterator.hpp:253
auto query() const noexcept
Returns the searched query.
Definition: fm_index_iterator.hpp:469
auto operator*() const noexcept
Returns the searched query.
Definition: fm_index_iterator.hpp:478
index_t index_type
Type of the index.
Definition: fm_index_iterator.hpp:100
constexpr alphabet_type & assign_rank(alphabet_type &alph, underlying_rank_t< alphabet_type > const rank) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::assign_rank() that delegates to a member function...
Definition: member_exposure.hpp:110
index_t::char_type last_char() noexcept
Outputs the rightmost character.
Definition: fm_index_iterator.hpp:423
Meta-header for the alphabet module.
bool operator==(fm_index_iterator const &rhs) const noexcept
Compares two iterators.
Definition: fm_index_iterator.hpp:207
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
typename index_type::size_type size_type
Type for representing positions in the indexed text.
Definition: fm_index_iterator.hpp:102
Provides C++20 additions to the type_traits header.
The SeqAn Bidirectional FM Index Iterator.
Definition: bi_fm_index_iterator.hpp:83
std::vector< size_type > locate() const
Locates the occurrences of the searched query in the text.
Definition: fm_index_iterator.hpp:514
Resolves to std::ranges::ImplicitlyConvertibleTo<type1, type2>().
bool operator!=(fm_index_iterator const &rhs) const noexcept
Compares two iterators.
Definition: fm_index_iterator.hpp:229
Provides various metafunctions used by the range module.
Provides the unidirectional seqan3::fm_index.
constexpr underlying_rank_t< alphabet_type > to_rank(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::to_rank() that delegates to a member function...
Definition: member_exposure.hpp:97
size_type count() const noexcept
Counts the number of occurrences of the searched query in the text.
Definition: fm_index_iterator.hpp:496
fm_index_iterator() noexcept=default
Default constructor. Accessing member functions on a default constructed object is undefined behavior...