generated from seqan/library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOC] More documentation for HIBF and config. (#104)
* [DOC] update HIBF documentation. * [DOC] Update config documentation. * [MISC] automatic linting * Update include/hibf/config.hpp * Update include/hibf/config.hpp * Apply suggestions from code review * Apply suggestions from code review * [MISC] automatic linting * Update test/snippet/hibf/hierarchical_interleaved_bloom_filter.cpp * [MISC] automatic linting * Update hierarchical_interleaved_bloom_filter.cpp * Create hierarchical_interleaved_bloom_filter.out * Apply suggestions from code review --------- Co-authored-by: seqan-actions[bot] <[email protected]> Co-authored-by: Enrico Seiler <[email protected]>
- Loading branch information
1 parent
997d284
commit 320f2c8
Showing
5 changed files
with
170 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <hibf/config.hpp> // for insert_iterator, config | ||
#include <hibf/hierarchical_interleaved_bloom_filter.hpp> // for hierarchical_interleaved_bloom_filter | ||
|
||
int main() | ||
{ | ||
// 2 user bins: | ||
std::vector<std::vector<size_t>> hashes{{1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u}, {1u, 2u, 3u, 4u, 5u}}; | ||
|
||
// input just passes hashes: | ||
auto my_input = [&](size_t const user_bin_id, seqan::hibf::insert_iterator it) | ||
{ | ||
for (auto const hash : hashes[user_bin_id]) | ||
it = hash; | ||
}; | ||
|
||
seqan::hibf::config config{.input_fn = my_input, // required | ||
.number_of_user_bins = 2, // required | ||
.number_of_hash_functions = 2, | ||
.maximum_false_positive_rate = 0.05, // recommended to adapt | ||
.threads = 1, // recommended to adapt | ||
.sketch_bits = 12, | ||
.tmax = 0, // triggers default copmutation | ||
.alpha = 1.2, | ||
.max_rearrangement_ratio = 0.5, | ||
.disable_estimate_union = false, | ||
.disable_rearrangement = false}; | ||
|
||
// construct the HIBF | ||
seqan::hibf::hierarchical_interleaved_bloom_filter hibf{config}; | ||
} |
46 changes: 46 additions & 0 deletions
46
test/snippet/hibf/hierarchical_interleaved_bloom_filter.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <hibf/config.hpp> // for insert_iterator, config | ||
#include <hibf/hierarchical_interleaved_bloom_filter.hpp> // for hierarchical_interleaved_bloom_filter | ||
|
||
void print(std::vector<int64_t> const & vector) | ||
{ | ||
std::cout << '['; | ||
|
||
if (!vector.empty()) | ||
{ | ||
for (size_t i = 0u; i < vector.size() - 1u; ++i) | ||
std::cout << vector[i] << ','; | ||
std::cout << vector.back(); | ||
} | ||
|
||
std::cout << "]\n"; | ||
} | ||
|
||
int main() | ||
{ | ||
// 2 user bins: | ||
std::vector<std::vector<size_t>> hashes{{1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u}, {1u, 2u, 3u, 4u, 5u}}; | ||
|
||
// input just passes hashes: | ||
auto my_input = [&](size_t const user_bin_id, seqan::hibf::insert_iterator it) | ||
{ | ||
for (auto const hash : hashes[user_bin_id]) | ||
it = hash; | ||
}; | ||
|
||
seqan::hibf::config config{.input_fn = my_input, .number_of_user_bins = 2}; | ||
|
||
// construct the HIBF | ||
seqan::hibf::hierarchical_interleaved_bloom_filter hibf{config}; | ||
|
||
// query the HIBF | ||
std::vector<size_t> query{1u, 2u, 3u}; | ||
std::vector<size_t> query2{8u, 9u, 10u}; | ||
|
||
auto agent = hibf.membership_agent(); // you need an agent for efficient queries | ||
auto & result = agent.membership_for(query, 2u); // both user bins have hashes 1,2,3 | ||
print(result); // [1,0] | ||
agent.sort_results(); // Results can also be sorted | ||
print(result); // [0,1] | ||
auto & result2 = agent.membership_for(query2, 2u); // only user bin 0 has hashes 8,9,10 | ||
print(result2); // [0] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[1,0] | ||
[0,1] | ||
[0] |
320f2c8
There was a problem hiding this comment.
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:
hibf – ./
hibf.vercel.app
hibf-seqan.vercel.app
hibf-git-main-seqan.vercel.app