19#include <sdsl/suffix_trees.hpp>
28namespace seqan3::detail
33struct fm_index_validator
49 template <semialphabet alphabet_t, text_layout text_layout_mode_, std::ranges::range text_t>
50 static void validate(text_t && text)
54 static_assert(std::ranges::bidirectional_range<text_t>,
"The text must model bidirectional_range.");
55 static_assert(std::convertible_to<range_innermost_value_t<text_t>, alphabet_t>,
56 "The alphabet of the text collection must be convertible to the alphabet of the index.");
57 static_assert(range_dimension_v<text_t> == 1,
"The input cannot be a text collection.");
59 if (std::ranges::empty(text))
64 static_assert(std::ranges::bidirectional_range<text_t>,
65 "The text collection must model bidirectional_range.");
66 static_assert(std::ranges::bidirectional_range<std::ranges::range_reference_t<text_t>>,
67 "The elements of the text collection must model bidirectional_range.");
68 static_assert(std::convertible_to<range_innermost_value_t<text_t>, alphabet_t>,
69 "The alphabet of the text collection must be convertible to the alphabet of the index.");
70 static_assert(range_dimension_v<text_t> == 2,
"The input must be a text collection.");
72 if (std::ranges::empty(text))
75 static_assert(alphabet_size<range_innermost_value_t<text_t>> <= 256,
"The alphabet is too big.");
85template <
typename index_t>
88template <
typename index_t>
89class bi_fm_index_cursor;
95 detail::sdsl_index sdsl_index_type_>
96class reverse_fm_index;
133 sdsl::csa_wt<sdsl::wt_blcd<sdsl::bit_vector,
134 sdsl::rank_support_v<>,
135 sdsl::select_support_scan<>,
136 sdsl::select_support_scan<0>>,
139 sdsl::sa_order_sa_sampling<>,
140 sdsl::isa_sampling<>,
141 sdsl::plain_byte_alphabet>;
198 using sdsl_index_type = sdsl_index_type_;
202 using sdsl_char_type =
typename sdsl_index_type::alphabet_type::char_type;
204 using sdsl_sigma_type =
typename sdsl_index_type::alphabet_type::sigma_type;
207 friend class detail::reverse_fm_index<alphabet_t, text_layout_mode_, sdsl_index_type_>;
210 sdsl_index_type index;
213 sdsl::sd_vector<> text_begin;
215 sdsl::select_support_sd<1> text_begin_ss;
217 sdsl::rank_support_sd<1> text_begin_rs;
238 template <std::ranges::range text_t>
242 void construct(text_t && text)
244 detail::fm_index_validator::validate<alphabet_t, text_layout_mode_>(text);
246 constexpr auto sigma = alphabet_size<alphabet_t>;
253 sdsl::int_vector<8> tmp_text(std::ranges::distance(text));
255 std::ranges::move(text
259 if constexpr (sigma == 256)
263 "character alphabets the last one/two values are reserved"
264 "(single sequence/collection).");
268 | std::views::reverse,
269 std::ranges::begin(tmp_text));
271 sdsl::construct_im(index, tmp_text, 0);
280 template <std::ranges::range text_t>
284 void construct(text_t && text,
bool reverse =
false)
286 detail::fm_index_validator::validate<alphabet_t, text_layout_mode_>(text);
290 for (
auto && t : text)
291 text_sizes.
push_back(std::ranges::distance(t));
293 size_t const number_of_texts{text_sizes.
size()};
298 if (number_of_texts == text_size)
301 constexpr auto sigma = alphabet_size<alphabet_t>;
306 sdsl::sd_vector_builder builder(text_size, number_of_texts);
307 size_t prefix_sum{0};
309 for (
auto &&
size : text_sizes)
311 builder.set(prefix_sum);
312 prefix_sum +=
size + 1;
315 text_begin = sdsl::sd_vector<>(builder);
316 text_begin_ss = sdsl::select_support_sd<1>(&text_begin);
317 text_begin_rs = sdsl::rank_support_sd<1>(&text_begin);
320 sdsl::int_vector<8> tmp_text(text_size - (number_of_texts > 1));
322 constexpr uint8_t delimiter = sigma >= 255 ? 255 : sigma + 1;
324 std::ranges::move(text
330 if constexpr (sigma >= 255)
334 " for full character alphabets the last one/"
335 "two values are reserved (single sequence/"
342 std::ranges::begin(tmp_text));
347 if (number_of_texts == 1)
348 tmp_text.back() = delimiter;
350 std::ranges::reverse(tmp_text);
357 if (number_of_texts == 1)
359 std::ranges::reverse(tmp_text.begin(), tmp_text.end() - 1);
360 tmp_text.back() = delimiter;
364 std::ranges::reverse(tmp_text);
368 sdsl::construct_im(index, tmp_text, 0);
386 template <
typename bi_fm_index_t>
389 template <
typename fm_index_t>
392 template <
typename fm_index_t>
393 friend class detail::fm_index_cursor_node;
402 index{rhs.index}, text_begin{rhs.text_begin}, text_begin_ss{rhs.text_begin_ss}, text_begin_rs{rhs.text_begin_rs}
404 text_begin_ss.set_vector(&text_begin);
405 text_begin_rs.set_vector(&text_begin);
410 index{
std::move(rhs.index)}, text_begin{
std::move(rhs.text_begin)},text_begin_ss{
std::move(rhs.text_begin_ss)},
411 text_begin_rs{
std::move(rhs.text_begin_rs)}
413 text_begin_ss.set_vector(&text_begin);
414 text_begin_rs.set_vector(&text_begin);
420 index = std::move(rhs.index);
421 text_begin = std::move(rhs.text_begin);
422 text_begin_ss = std::move(rhs.text_begin_ss);
423 text_begin_rs = std::move(rhs.text_begin_rs);
425 text_begin_ss.set_vector(&text_begin);
426 text_begin_rs.set_vector(&text_begin);
441 template <std::ranges::b
idirectional_range text_t>
444 construct(std::forward<text_t>(text));
494 return (index == rhs.index) && (text_begin == rhs.text_begin);
510 return !(*
this == rhs);
539 template <cereal_archive archive_t>
540 void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
544 archive(text_begin_ss);
545 text_begin_ss.set_vector(&text_begin);
546 archive(text_begin_rs);
547 text_begin_rs.set_vector(&text_begin);
549 auto sigma = alphabet_size<alphabet_t>;
551 if (sigma != alphabet_size<alphabet_t>)
554 " but it is being read into an fm_index with an alphabet of size " +
563 (tmp ?
"text collection" :
"single text") +
564 " but it is being read into an fm_index expecting a " +
576template <std::ranges::range text_t>
581namespace seqan3::detail
600class reverse_fm_index :
public fm_index<alphabet_t, text_layout_mode, sdsl_index_type>
604 template <std::ranges::range text_t>
605 void construct_(text_t && text)
609 auto reverse_text = text | std::views::reverse;
610 this->construct(reverse_text);
614 auto reverse_text = text | views::deep{std::views::reverse} | std::views::reverse;
615 this->construct(reverse_text,
true);
623 template <std::ranges::b
idirectional_range text_t>
624 explicit reverse_fm_index(text_t && text)
626 construct_(std::forward<text_t>(text));
The <algorithm> header from C++20's standard library.
The SeqAn Bidirectional FM Index Cursor.
Definition: bi_fm_index_cursor.hpp:55
The SeqAn FM Index Cursor.
Definition: fm_index_cursor.hpp:87
The SeqAn FM Index.
Definition: fm_index.hpp:192
fm_index & operator=(fm_index rhs)
When copy/move assigning, also update internal data structures.
Definition: fm_index.hpp:418
fm_index()=default
Defaulted.
static constexpr text_layout text_layout_mode
Indicates whether index is built over a collection.
Definition: fm_index.hpp:373
cursor_type cursor() const noexcept
Returns a seqan3::fm_index_cursor on the index that can be used for searching. .
Definition: fm_index.hpp:527
size_type size() const noexcept
Returns the length of the indexed text including sentinel characters.
Definition: fm_index.hpp:459
bool operator!=(fm_index const &rhs) const noexcept
Compares two indices.
Definition: fm_index.hpp:508
bool empty() const noexcept
Checks whether the index is empty.
Definition: fm_index.hpp:475
bool operator==(fm_index const &rhs) const noexcept
Compares two indices.
Definition: fm_index.hpp:491
~fm_index()=default
Defaulted.
alphabet_t alphabet_type
The type of the underlying character of the indexed text.
Definition: fm_index.hpp:379
fm_index(fm_index &&rhs)
When move constructing, also update internal data structures.
Definition: fm_index.hpp:409
typename sdsl_index_type::size_type size_type
Type for representing positions in the indexed text.
Definition: fm_index.hpp:381
fm_index(text_t &&text)
Constructor that immediately constructs the index given a range. The range cannot be empty.
Definition: fm_index.hpp:442
fm_index(fm_index const &rhs)
When copy constructing, also update internal data structures.
Definition: fm_index.hpp:401
Provides various transformation traits used by the range module.
Provides the internal representation of a node of the seqan3::fm_index_cursor.
The <filesystem> header from C++17's standard library.
Provides the seqan3::fm_index_cursor for searching in the unidirectional seqan3::fm_index.
auto const to_rank
A view that calls seqan3::to_rank() on each element in the input range.
Definition: to_rank.hpp:66
text_layout
The possible text layouts (single, collection) the seqan3::fm_index and seqan3::bi_fm_index can suppo...
Definition: concept.hpp:72
sdsl_wt_index_type default_sdsl_index_type
The default FM Index Configuration.
Definition: fm_index.hpp:148
sdsl::csa_wt< sdsl::wt_blcd< sdsl::bit_vector, sdsl::rank_support_v<>, sdsl::select_support_scan<>, sdsl::select_support_scan< 0 > >, 16, 10 '000 '000, sdsl::sa_order_sa_sampling<>, sdsl::isa_sampling<>, sdsl::plain_byte_alphabet > sdsl_wt_index_type
The FM Index Configuration using a Wavelet Tree.
Definition: fm_index.hpp:141
@ single
The text is a single range.
Definition: concept.hpp:74
@ collection
The text is a range of ranges.
Definition: concept.hpp:76
decltype(detail::transform< trait_t >(list_t{})) transform
Apply a transformation trait to every type in the list and return a seqan3::type_list of the results.
Definition: traits.hpp:471
constexpr auto join_with
A join view, please use std::views::join if you don't need a separator.
Definition: join_with.hpp:29
The basis for seqan3::alphabet, but requires only rank interface (not char).
Provides seqan3::views::join_with.
The main SeqAn3 namespace.
Definition: cigar_operation_table.hpp:2
fm_index(text_t &&) -> fm_index< range_innermost_value_t< text_t >, text_layout
Deduces the alphabet and dimensions of the text.
Definition: fm_index.hpp:577
SeqAn specific customisations in the standard namespace.
The <ranges> header from C++20's standard library.
Provides the concept for seqan3::detail::sdsl_index.
Provides seqan3::views::to_rank.