From b0b8ec0f127320d5595409f72695d5721b95e2df Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Mon, 12 Aug 2019 15:05:28 +0200 Subject: [PATCH] [FIX] Add data access for containers --- CHANGELOG.md | 5 +++ .../range/container/bitcompressed_vector.hpp | 23 ++++++++++- .../container/concatenated_sequences.hpp | 40 ++++++++++++++----- .../container/container_of_container_test.cpp | 8 ++-- 4 files changed, 60 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55eadc8b17..bdf53517ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,11 @@ If possible, provide tooling that performs the changes, e.g. a shell-script. * **The `type_list` header has moved:** If you included `` you need to change the path to ``. +#### Range + +* **The `seqan3::concatenated_sequences::data()` function has been deprecated:** + Use `seqan3::concatenated_sequences::raw_data()` instead. + ## Notable Bug-fixes # 3.0.0 ("Escala") diff --git a/include/seqan3/range/container/bitcompressed_vector.hpp b/include/seqan3/range/container/bitcompressed_vector.hpp index 11d36863cb..94ea862567 100644 --- a/include/seqan3/range/container/bitcompressed_vector.hpp +++ b/include/seqan3/range/container/bitcompressed_vector.hpp @@ -518,6 +518,27 @@ class bitcompressed_vector return (*this)[size()-1]; } + /*!\brief Provides direct, unsafe access to underlying data structures. + * \returns A reference to an SDSL bitvector. + * + * \details + * + * \noapi + * + * The exact representation of the data is implementation defined. Do not rely on it for API stability. + */ + constexpr data_type & raw_data() noexcept + { + return data; + } + + //!\copydoc raw_data() + constexpr data_type const & raw_data() const noexcept + { + return data; + } + //!\} + /*!\name Capacity * \{ */ @@ -1008,7 +1029,7 @@ class bitcompressed_vector template void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive) { - archive(data); //TODO: data not yet serialisable + archive(data); } //!\endcond }; diff --git a/include/seqan3/range/container/concatenated_sequences.hpp b/include/seqan3/range/container/concatenated_sequences.hpp index 6d16663e19..7780d5713f 100644 --- a/include/seqan3/range/container/concatenated_sequences.hpp +++ b/include/seqan3/range/container/concatenated_sequences.hpp @@ -53,7 +53,7 @@ namespace seqan3 * * Better cache locality when parsing the sequences linearly (and often also on random access). * * Constant time access to the concatenation of the sequences via concat(). * * This access is also writable so that certain transformations can be done globally, instead of element-wise. - * * Also direct access to the delimiters via data() [this is used by some algorithms]. + * * Also direct access to the delimiters via raw_data() [this is used by some algorithms]. * * The disadvantages are: * @@ -600,18 +600,36 @@ class concatenated_sequences /*!\brief Provides direct, unsafe access to underlying data structures. * \returns An std::pair of the concatenated sequences and the delimiter string. * - * This exact representation of the data is implementation defined. Do not rely on it for API stability. + * \details + * + * \noapi + * + * The exact representation of the data is implementation defined. Do not rely on it for API stability. */ - std::pair data() + std::pair raw_data() { return {data_values, data_delimiters}; } - //!\copydoc data() - std::pair data() const + //!\copydoc raw_data() + std::pair raw_data() const { return {std::as_const(data_values), std::as_const(data_delimiters)}; } + + //!\copydoc raw_data() + //!\deprecated Use raw_data() instead. + SEQAN3_DEPRECATED_310 std::pair data() + { + return raw_data(); + } + + //!\copydoc raw_data() + //!\deprecated Use raw_data() instead. + SEQAN3_DEPRECATED_310 std::pair data() const + { + return raw_data(); + } //!\} /*!\name Capacity @@ -1243,37 +1261,37 @@ class concatenated_sequences //!\brief Checks whether `*this` is equal to `rhs`. constexpr bool operator==(concatenated_sequences const & rhs) const noexcept { - return data() == rhs.data(); + return raw_data() == rhs.raw_data(); } //!\brief Checks whether `*this` is not equal to `rhs`. constexpr bool operator!=(concatenated_sequences const & rhs) const noexcept { - return data() != rhs.data(); + return raw_data() != rhs.raw_data(); } //!\brief Checks whether `*this` is less than `rhs`. constexpr bool operator<(concatenated_sequences const & rhs) const noexcept { - return data() < rhs.data(); + return raw_data() < rhs.raw_data(); } //!\brief Checks whether `*this` is greater than `rhs`. constexpr bool operator>(concatenated_sequences const & rhs) const noexcept { - return data() > rhs.data(); + return raw_data() > rhs.raw_data(); } //!\brief Checks whether `*this` is less than or equal to `rhs`. constexpr bool operator<=(concatenated_sequences const & rhs) const noexcept { - return data() <= rhs.data(); + return raw_data() <= rhs.data(); } //!\brief Checks whether `*this` is greater than or equal to `rhs`. constexpr bool operator>=(concatenated_sequences const & rhs) const noexcept { - return data() >= rhs.data(); + return raw_data() >= rhs.raw_data(); } //!\} diff --git a/test/unit/range/container/container_of_container_test.cpp b/test/unit/range/container/container_of_container_test.cpp index 9bde16e716..af87a89c67 100644 --- a/test/unit/range/container/container_of_container_test.cpp +++ b/test/unit/range/container/container_of_container_test.cpp @@ -152,10 +152,10 @@ TYPED_TEST(container_of_container, element_access) EXPECT_EQ(dna4_vector(t2.concat()), "ACGTACGTGAGGA"_dna4); // data - EXPECT_EQ(std::get<0>(t1.data()), "ACGTACGTGAGGA"_dna4); - EXPECT_EQ(std::get<0>(t2.data()), "ACGTACGTGAGGA"_dna4); - EXPECT_EQ(std::get<1>(t1.data()), (std::vector{0, 4, 8, 13})); - EXPECT_EQ(std::get<1>(t2.data()), (std::vector{0, 4, 8, 13})); + EXPECT_EQ(std::get<0>(t1.raw_data()), "ACGTACGTGAGGA"_dna4); + EXPECT_EQ(std::get<0>(t2.raw_data()), "ACGTACGTGAGGA"_dna4); + EXPECT_EQ(std::get<1>(t1.raw_data()), (std::vector{0, 4, 8, 13})); + EXPECT_EQ(std::get<1>(t2.raw_data()), (std::vector{0, 4, 8, 13})); } }