Skip to content

Commit

Permalink
[FIX] Add data access for containers
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Aug 14, 2019
1 parent 22539ca commit 25d06a0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ If possible, provide tooling that performs the changes, e.g. a shell-script.

If you included `<seqan3/core/type_list.hpp>` you need to change the path to `<seqan3/core/type_list/type_list.hpp>`.

### The `data()` function of `seqan3::concatenated_sequences` has been deprecated

Use `raw_data()` instead.

## Notable Bug-fixes

# 3.0.0 ("Escala")
Expand Down
27 changes: 20 additions & 7 deletions include/seqan3/range/container/bitcompressed_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,19 @@ class bitcompressed_vector
return (*this)[size()-1];
}

//!\brief Direct access to the underlying SDSL vector.
constexpr data_type & raw_data() noexcept
{
return data;
}

//!\copydoc raw_data()
constexpr data_type const & raw_data() const noexcept
{
return data;
}
//!\}

/*!\name Capacity
* \{
*/
Expand Down Expand Up @@ -964,37 +977,37 @@ class bitcompressed_vector
//!\brief Checks whether `*this` is equal to `rhs`.
constexpr bool operator==(bitcompressed_vector 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!=(bitcompressed_vector 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<(bitcompressed_vector 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>(bitcompressed_vector 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<=(bitcompressed_vector const & rhs) const noexcept
{
return data <= rhs.data;
return raw_data() <= rhs.raw_data();
}

//!\brief Checks whether `*this` is greater than or equal to `rhs`.
constexpr bool operator>=(bitcompressed_vector const & rhs) const noexcept
{
return data >= rhs.data;
return raw_data() >= rhs.raw_data();
}
//!\}

Expand All @@ -1008,7 +1021,7 @@ class bitcompressed_vector
template <CerealArchive archive_t>
void CEREAL_SERIALIZE_FUNCTION_NAME(archive_t & archive)
{
archive(data); //TODO: data not yet serialisable
archive(data);
}
//!\endcond
};
Expand Down
34 changes: 24 additions & 10 deletions include/seqan3/range/container/concatenated_sequences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -602,16 +602,30 @@ class concatenated_sequences
*
* This exact representation of the data is implementation defined. Do not rely on it for API stability.
*/
std::pair<decltype(data_values) &, decltype(data_delimiters) &> data()
std::pair<decltype(data_values) &, decltype(data_delimiters) &> raw_data()
{
return {data_values, data_delimiters};
}

//!\copydoc data()
std::pair<decltype(data_values) const &, decltype(data_delimiters) const &> data() const
//!\copydoc raw_data()
std::pair<decltype(data_values) const &, decltype(data_delimiters) const &> 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<decltype(data_values) &, decltype(data_delimiters) &> data()
{
return raw_data();
}

//!\copydoc raw_data()
//!\deprecated Use raw_data() instead.
SEQAN3_DEPRECATED_310 std::pair<decltype(data_values) const &, decltype(data_delimiters) const &> data() const
{
return raw_data();
}
//!\}

/*!\name Capacity
Expand Down Expand Up @@ -1243,37 +1257,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();
}
//!\}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/range/container/container_of_container_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_type>{0, 4, 8, 13}));
EXPECT_EQ(std::get<1>(t2.data()), (std::vector<size_type>{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<size_type>{0, 4, 8, 13}));
EXPECT_EQ(std::get<1>(t2.raw_data()), (std::vector<size_type>{0, 4, 8, 13}));
}

}
Expand Down

0 comments on commit 25d06a0

Please sign in to comment.