19#include <sdsl/suffix_trees.hpp>
49 template <semialphabet alphabet_t, text_layout text_layout_mode_, std::ranges::range text_t>
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>;
238 template <std::ranges::range text_t>
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>
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;
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>
441 template <std::ranges::b
idirectional_range text_t>
510 return !(*
this == rhs);
539 template <cereal_archive archive_t>
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>
604 template <std::ranges::range text_t>
609 auto reverse_text = text | std::views::reverse;
614 auto reverse_text = text | views::deep{std::views::reverse} | std::views::reverse;
623 template <std::ranges::b
idirectional_range text_t>
Adaptations of algorithms from the Ranges TS.
The SeqAn Bidirectional FM Index Cursor.
Definition: bi_fm_index_cursor.hpp:55
An FM Index specialisation that handles reversing the given text.
Definition: fm_index.hpp:601
void construct_(text_t &&text)
Constructs the index given a range. The range cannot be an rvalue (i.e. a temporary object) and has t...
Definition: fm_index.hpp:605
reverse_fm_index(text_t &&text)
Constructor that immediately constructs the index given a range. The range cannot be empty.
Definition: fm_index.hpp:624
The SeqAn FM Index Cursor.
Definition: fm_index_cursor.hpp:87
The SeqAn FM Index.
Definition: fm_index.hpp:192
sdsl_index_type_ sdsl_index_type
The type of the underlying SDSL index.
Definition: fm_index.hpp:198
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. Cursor is pointing to...
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
sdsl::rank_support_sd< 1 > text_begin_rs
Rank support for text_begin.
Definition: fm_index.hpp:217
sdsl_index_type index
Underlying index from the SDSL.
Definition: fm_index.hpp:210
bool operator!=(fm_index const &rhs) const noexcept
Compares two indices.
Definition: fm_index.hpp:508
typename sdsl_index_type::alphabet_type::sigma_type sdsl_sigma_type
The type of the alphabet size of the underlying SDSL index.
Definition: fm_index.hpp:204
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
typename sdsl_index_type::alphabet_type::char_type sdsl_char_type
The type of the reduced alphabet type. (The reduced alphabet might be smaller than the original alpha...
Definition: fm_index.hpp:202
~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
void construct(text_t &&text, bool reverse=false)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: fm_index.hpp:284
void construct(text_t &&text)
Constructs the index given a range. The range cannot be an rvalue (i.e. a temporary object) and has t...
Definition: fm_index.hpp:242
typename sdsl_index_type::size_type size_type
Type for representing positions in the indexed text.
Definition: fm_index.hpp:381
sdsl::sd_vector text_begin
Bitvector storing begin positions for collections.
Definition: fm_index.hpp:213
sdsl::select_support_sd< 1 > text_begin_ss
Select support for text_begin.
Definition: fm_index.hpp:215
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.
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
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 internal SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
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.
Adaptations of concepts from the Ranges TS.
Provides the concept for seqan3::detail::sdsl_index.
Internal representation of the node of an FM index cursor.
Definition: fm_index_cursor.hpp:30
Class used to validate the requirements on the input text of the fm_index.
Definition: fm_index.hpp:34
static void validate(text_t &&text)
Validates the fm_index template parameters and text.
Definition: fm_index.hpp:50
Provides seqan3::views::to_rank.