From 7f46653347d59ed4ce3ae4b45674eb4dc13fc82d Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Tue, 18 Aug 2020 13:02:22 +0200 Subject: [PATCH] [FEATURE] Serialise index cursor --- CHANGELOG.md | 2 ++ .../search/fm_index/bi_fm_index_cursor.hpp | 23 +++++++++++++++++++ .../fm_index/detail/fm_index_cursor.hpp | 20 +++++++++++++++- .../search/fm_index/fm_index_cursor.hpp | 18 +++++++++++++++ ..._index_cursor_collection_test_template.hpp | 14 ++++++++++- .../bi_fm_index_cursor_test_template.hpp | 13 ++++++++++- ..._index_cursor_collection_test_template.hpp | 13 ++++++++++- .../fm_index_cursor_test_template.hpp | 13 ++++++++++- 8 files changed, 111 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ad59efe9..ce7322987b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,8 @@ Note that 3.1.0 will be the first API stable release and interfaces in this rele ([\#1853](https://github.com/seqan/seqan3/pull/1853)). * Added `seqan3::search_cfg::on_result`, which allows providing a custom callback for the search algorithm ([\#2019](https://github.com/seqan/seqan3/pull/2019)). +* The `seqan3::fm_index_cursor` and `seqan3::bi_fm_index_cursor` can be serialised + ([\#2048](https://github.com/seqan/seqan3/pull/2019)). ## API changes diff --git a/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp b/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp index be74bf8d6a..889a23eef2 100644 --- a/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp +++ b/include/seqan3/search/fm_index/bi_fm_index_cursor.hpp @@ -34,6 +34,7 @@ namespace seqan3 /*!\brief The SeqAn Bidirectional FM Index Cursor. * \implements seqan3::bi_fm_index_cursor_specialisation * \tparam index_t The type of the underlying index; must model seqan3::bi_fm_index_specialisation. + * \implements seqan3::cerealisable * \details * * The cursor's interface provides searching a string both from left to right as well as from right to left in the @@ -1022,6 +1023,28 @@ class bi_fm_index_cursor return locate_result_value_type{sequence_rank-1, sequence_position}; }); } + + /*!\cond DEV + * \brief Serialisation support function. + * \tparam archive_t Type of `archive`; must satisfy seqan3::cereal_archive. + * \param archive The archive being serialised from/to. + * + * \attention These functions are never called directly, see \ref serialisation for more details. + */ + template + void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive) + { + archive(fwd_lb); + archive(fwd_rb); + archive(rev_lb); + archive(rev_rb); + archive(sigma); + archive(parent_lb); + archive(parent_rb); + archive(_last_char); + archive(depth); + } + //!\endcond }; //!\} diff --git a/include/seqan3/search/fm_index/detail/fm_index_cursor.hpp b/include/seqan3/search/fm_index/detail/fm_index_cursor.hpp index 70c3300950..c7622a676f 100644 --- a/include/seqan3/search/fm_index/detail/fm_index_cursor.hpp +++ b/include/seqan3/search/fm_index/detail/fm_index_cursor.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include namespace seqan3::detail { @@ -27,6 +27,7 @@ namespace seqan3::detail /*!\brief Internal representation of the node of an FM index cursor. * \ingroup fm_index * \tparam index_t The type of the underlying index; must satisfy seqan3::fm_index_specialisation. + * \implements seqan3::cerealisable */ template struct fm_index_cursor_node @@ -61,6 +62,23 @@ struct fm_index_cursor_node { return !(*this == rhs); } + + /*!\cond DEV + * \brief Serialisation support function. + * \tparam archive_t Type of `archive`; must satisfy seqan3::cereal_archive. + * \param archive The archive being serialised from/to. + * + * \attention These functions are never called directly, see \ref serialisation for more details. + */ + template + void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive) + { + archive(lb); + archive(rb); + archive(depth); + archive(last_char); + } + //!\endcond }; // std::tuple get_suffix_array_range(fm_index_cursor const & it) diff --git a/include/seqan3/search/fm_index/fm_index_cursor.hpp b/include/seqan3/search/fm_index/fm_index_cursor.hpp index 3e94a52caf..679e5b1b46 100644 --- a/include/seqan3/search/fm_index/fm_index_cursor.hpp +++ b/include/seqan3/search/fm_index/fm_index_cursor.hpp @@ -35,6 +35,7 @@ namespace seqan3 /*!\brief The SeqAn FM Index Cursor. * \implements seqan3::fm_index_cursor_specialisation * \tparam index_t The type of the underlying index; must model seqan3::fm_index_specialisation. + * \implements seqan3::cerealisable * \details * * The cursor's interface provides searching a string from left to right in the indexed text. @@ -621,6 +622,23 @@ class fm_index_cursor return locate_result_value_type{sequence_rank - 1, sequence_position}; }); } + + /*!\cond DEV + * \brief Serialisation support function. + * \tparam archive_t Type of `archive`; must satisfy seqan3::cereal_archive. + * \param archive The archive being serialised from/to. + * + * \attention These functions are never called directly, see \ref serialisation for more details. + */ + template + void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive) + { + archive(parent_lb); + archive(parent_rb); + archive(node); + archive(sigma); + } + //!\endcond }; //!\} diff --git a/test/unit/search/fm_index_cursor/bi_fm_index_cursor_collection_test_template.hpp b/test/unit/search/fm_index_cursor/bi_fm_index_cursor_collection_test_template.hpp index df92cedab6..5e1ac8c567 100644 --- a/test/unit/search/fm_index_cursor/bi_fm_index_cursor_collection_test_template.hpp +++ b/test/unit/search/fm_index_cursor/bi_fm_index_cursor_collection_test_template.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "../helper.hpp" @@ -220,5 +221,16 @@ TYPED_TEST_P(bi_fm_index_cursor_collection_test, extend_const_char_pointer) } } +TYPED_TEST_P(bi_fm_index_cursor_collection_test, serialisation) +{ + typename TypeParam::index_type bi_fm{this->text_col2}; + + TypeParam it = TypeParam(bi_fm); + it.extend_left(seqan3::views::slice(this->text, 1, 3)); + + seqan3::test::do_serialisation(it); +} + REGISTER_TYPED_TEST_SUITE_P(bi_fm_index_cursor_collection_test, cursor, extend, extend_char, extend_range, - extend_and_cycle, extend_range_and_cycle, to_fwd_cursor, extend_const_char_pointer); + extend_and_cycle, extend_range_and_cycle, to_fwd_cursor, extend_const_char_pointer, + serialisation); diff --git a/test/unit/search/fm_index_cursor/bi_fm_index_cursor_test_template.hpp b/test/unit/search/fm_index_cursor/bi_fm_index_cursor_test_template.hpp index 33e4fa0848..da7eaa2517 100644 --- a/test/unit/search/fm_index_cursor/bi_fm_index_cursor_test_template.hpp +++ b/test/unit/search/fm_index_cursor/bi_fm_index_cursor_test_template.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "../helper.hpp" @@ -184,5 +185,15 @@ TYPED_TEST_P(bi_fm_index_cursor_test, to_fwd_cursor) } } +TYPED_TEST_P(bi_fm_index_cursor_test, serialisation) +{ + typename TypeParam::index_type bi_fm{this->text}; + + TypeParam it(bi_fm); + it.extend_left(seqan3::views::slice(this->text, 1, 3)); + + seqan3::test::do_serialisation(it); +} + REGISTER_TYPED_TEST_SUITE_P(bi_fm_index_cursor_test, cursor, extend, extend_char, extend_range, extend_and_cycle, - extend_range_and_cycle, to_fwd_cursor); + extend_range_and_cycle, to_fwd_cursor, serialisation); diff --git a/test/unit/search/fm_index_cursor/fm_index_cursor_collection_test_template.hpp b/test/unit/search/fm_index_cursor/fm_index_cursor_collection_test_template.hpp index 9bc43860f2..abfe7789fe 100644 --- a/test/unit/search/fm_index_cursor/fm_index_cursor_collection_test_template.hpp +++ b/test/unit/search/fm_index_cursor/fm_index_cursor_collection_test_template.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -348,7 +349,17 @@ TYPED_TEST_P(fm_index_cursor_collection_test, concept_check) EXPECT_TRUE(seqan3::fm_index_cursor_specialisation); } +TYPED_TEST_P(fm_index_cursor_collection_test, serialisation) +{ + typename TypeParam::index_type fm{this->text_col4}; + + TypeParam it(fm); + it.extend_right(seqan3::views::slice(this->text1, 0, 3)); + + seqan3::test::do_serialisation(it); +} + REGISTER_TYPED_TEST_SUITE_P(fm_index_cursor_collection_test, ctr, begin, extend_right_range, extend_right_range_empty_text, extend_right_char, extend_right_range_and_cycle, extend_right_char_and_cycle, extend_right_and_cycle, query, last_rank, incomplete_alphabet, - lazy_locate, extend_const_char_pointer, concept_check); + lazy_locate, extend_const_char_pointer, concept_check, serialisation); diff --git a/test/unit/search/fm_index_cursor/fm_index_cursor_test_template.hpp b/test/unit/search/fm_index_cursor/fm_index_cursor_test_template.hpp index da26f256ed..9913249ec1 100644 --- a/test/unit/search/fm_index_cursor/fm_index_cursor_test_template.hpp +++ b/test/unit/search/fm_index_cursor/fm_index_cursor_test_template.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -300,6 +301,16 @@ TYPED_TEST_P(fm_index_cursor_test, concept_check) EXPECT_TRUE(seqan3::fm_index_cursor_specialisation); } +TYPED_TEST_P(fm_index_cursor_test, serialisation) +{ + typename TypeParam::index_type fm{this->text1}; + + TypeParam it = TypeParam(fm); + it.extend_right(seqan3::views::slice(this->text1, 0, 3)); + + seqan3::test::do_serialisation(it); +} + REGISTER_TYPED_TEST_SUITE_P(fm_index_cursor_test, ctr, begin, extend_right_range, extend_right_char, extend_right_range_and_cycle, extend_right_char_and_cycle, extend_right_and_cycle, query, - last_rank, incomplete_alphabet, lazy_locate, concept_check); + last_rank, incomplete_alphabet, lazy_locate, concept_check, serialisation);