Skip to content

Commit

Permalink
[FEATURE] IBF decompression (#3082)
Browse files Browse the repository at this point in the history
* [FEATURE] IBF decompression

* [MISC] clang-format

* Update include/seqan3/search/dream_index/interleaved_bloom_filter.hpp

Co-authored-by: Svenja Mehringer <svenja.mehringer@gmail.com>

* Update include/seqan3/search/dream_index/interleaved_bloom_filter.hpp

Co-authored-by: seqan-actions[bot] <seqan-actions@users.noreply.github.com>
Co-authored-by: Svenja Mehringer <svenja.mehringer@gmail.com>
  • Loading branch information
3 people committed Nov 3, 2022
1 parent 92164e6 commit 62b3b7d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
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
17 changes: 17 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,23 @@ class interleaved_bloom_filter
data = sdsl::bit_vector(technical_bins * bin_size_);
}

/*!\brief Construct an uncompressed Interleaved Bloom Filter from a compressed one.
* \param[in] ibf The compressed seqan3::interleaved_bloom_filter.
* \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);
}

1 comment on commit 62b3b7d

@vercel
Copy link

@vercel vercel bot commented on 62b3b7d Nov 3, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

seqan3 – ./

seqan3-git-master-seqan.vercel.app
seqan3.vercel.app
seqan3-seqan.vercel.app

Please sign in to comment.