Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] IBF decompression #3082

Merged
merged 4 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ If possible, provide tooling that performs the changes, e.g. a shell-script.
* Char literals returning std::vector are now constexpr if supported by the compiler
([\#3073](https://github.com/seqan/seqan3/pull/3073)).

#### Search

* Added a constructor to the `seqan3::interleaved_bloom_filter` for decompressing a compressed
`seqan3::interleaved_bloom_filter` ([\#3082](https://github.com/seqan/seqan3/pull/3082)).

## Notable Bug-fixes

#### I/O
Expand Down
20 changes: 20 additions & 0 deletions include/seqan3/search/dream_index/interleaved_bloom_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,26 @@ class interleaved_bloom_filter
data = sdsl::bit_vector(technical_bins * bin_size_);
}

/*!\brief Construct an uncompressed Interleaved Bloom Filter.
eseiler marked this conversation as resolved.
Show resolved Hide resolved
* \param[in] ibf The compressed seqan3::interleaved_bloom_filter.
*
* \attention This constructor can only be used to construct **uncompressed** Interleaved Bloom Filters.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* \attention This constructor can only be used to construct **uncompressed** Interleaved Bloom Filters.
*
* \attention This constructor can only be used to construct **uncompressed** Interleaved Bloom Filters (IBFs).
* Construction of compressed from compressed IBFs is trivial and handled by different constructors.
*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or similar.

otherwise you might think it is not possible

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's best to remove that \attention completely?

eseiler marked this conversation as resolved.
Show resolved Hide resolved
* \details
*
* ### Example
*
* \include test/snippet/search/dream_index/interleaved_bloom_filter_constructor_uncompress.cpp
*/
interleaved_bloom_filter(interleaved_bloom_filter<data_layout::compressed> const & ibf)
requires (data_layout_mode == data_layout::uncompressed)
{
std::tie(bins, technical_bins, bin_size_, hash_shift, bin_words, hash_funs) =
std::tie(ibf.bins, ibf.technical_bins, ibf.bin_size_, ibf.hash_shift, ibf.bin_words, ibf.hash_funs);

data = sdsl::bit_vector{ibf.data.begin(), ibf.data.end()};
}

/*!\brief Construct a compressed Interleaved Bloom Filter.
* \param[in] ibf The uncompressed seqan3::interleaved_bloom_filter.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <seqan3/search/dream_index/interleaved_bloom_filter.hpp>

int main()
{
// Construct an uncompressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{4u}, seqan3::bin_size{128u}, seqan3::hash_function_count{3}};

// Insert the values `126`, `712` and `237` into bins `0`, `3` and `9` of the Interleaved Bloom Filter.
ibf.emplace(126, seqan3::bin_index{0u});
ibf.emplace(712, seqan3::bin_index{3u});
ibf.emplace(237, seqan3::bin_index{9u});

// Construct an immutable, compressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter<seqan3::data_layout::compressed> ibf_compressed{ibf};

// Decompress the compressed Interleaved Bloom Filter.
seqan3::interleaved_bloom_filter ibf_decompressed{ibf_compressed};
}
20 changes: 20 additions & 0 deletions test/unit/search/dream_index/interleaved_bloom_filter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,23 @@ TYPED_TEST(interleaved_bloom_filter_test, serialisation)
TypeParam ibf{TestFixture::make_ibf(seqan3::bin_count{73u}, seqan3::bin_size{1024u})};
seqan3::test::do_serialisation(ibf);
}

TEST(interleaved_bloom_filter_test, decompression)
{
seqan3::interleaved_bloom_filter ibf{seqan3::bin_count{64u}, seqan3::bin_size{1024u}};

// Only use every other bin.
auto take_odd = [](auto number)
{
return number & 1;
};
for (size_t bin_idx : std::views::iota(0, 64) | std::views::filter(take_odd))
for (size_t hash : std::views::iota(0, 64))
ibf.emplace(hash, seqan3::bin_index{bin_idx});

seqan3::interleaved_bloom_filter<seqan3::data_layout::compressed> ibf_compressed{ibf};

seqan3::interleaved_bloom_filter ibf_decompressed{ibf_compressed};

EXPECT_TRUE(ibf == ibf_decompressed);
}