The HIBF Cookbook
This document provides example recipes on how to carry out particular tasks using the HIBF functionalities in C++. Please note that these recipes are not ordered. You can use the links in the table of contents or the search function of your browser to navigate them.
It will take some time, but we hope to expand this document into containing numerous great examples. If you have suggestions for how to improve the Cookbook and/or examples you would like included, please feel free to contact us.
All HIBF documentation snippets
The following lists all snippets that appear in our documentation. Search for keywords with Strg + F.
#include <hibf/config.hpp>
int main()
{
{
it = 42;
};
}
Definition insert_iterator.hpp:24
The configuration used to build an (H)IBF.
Definition config.hpp:74
std::function< void(size_t const, insert_iterator &&) input_fn)
A function for how to hash your input [REQUIRED].
Definition config.hpp:109
#include <hibf/test/temporary_snippet_file.hpp>
seqan::hibf::test::temporary_snippet_file file1{"file1.fa", "ACGT"};
seqan::hibf::test::temporary_snippet_file file2{"file2.fa", "ACGT"};
#include <hibf/config.hpp>
int main()
{
{
for (
size_t i = 0; i < line.
size() - 1; ++i)
{
uint64_t hash = 4 * line[i] + line[i + 1];
it = hash;
}
};
}
#include <hibf/config.hpp>
struct dna
{
int rank{0};
};
int main()
{
{
auto const & seq = user_bins[user_bin_id];
for (size_t i = 0; i < seq.size() - 1; ++i)
{
uint64_t hash = 4 * seq[i].rank + seq[i + 1].rank;
it = hash;
}
};
}
#include <hibf/config.hpp>
int main()
{
{
it = 42;
};
}
#include <hibf/config.hpp>
#include <hibf/hierarchical_interleaved_bloom_filter.hpp>
int main()
{
std::vector<std::vector<size_t>> hashes{{1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u}, {1u, 2u, 3u, 4u, 5u}};
{
for (auto const hash : hashes[user_bin_id])
it = hash;
};
.number_of_user_bins = 2,
.number_of_hash_functions = 2,
.maximum_fpr = 0.05,
.threads = 1,
.sketch_bits = 12,
.tmax = 0,
.alpha = 1.2,
.max_rearrangement_ratio = 0.5,
.disable_estimate_union = false,
.disable_rearrangement = false};
}
The Hierarchical Interleaved Bloom Filter (HIBF) - Fast answers to set-membership queries for multipl...
Definition hierarchical_interleaved_bloom_filter.hpp:129
#include <hibf/config.hpp>
#include <hibf/hierarchical_interleaved_bloom_filter.hpp>
#include <hibf/misc/print.hpp>
int main()
{
std::vector<std::vector<size_t>> hashes{{1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u}, {1u, 2u, 3u, 4u, 5u}};
{
for (auto const hash : hashes[user_bin_id])
it = hash;
};
auto agent = hibf.membership_agent();
auto & result = agent.membership_for(query, 2u);
seqan::hibf::print(result);
agent.sort_results();
seqan::hibf::print(result);
auto & result2 = agent.membership_for(query2, 2u);
seqan::hibf::print(result2);
}
#include <hibf/misc/print.hpp>
int main()
{
auto sequence1 = std::views::iota(0u, 20u);
auto sequence2 = std::views::iota(10u, 30u);
auto sequence3 = std::views::iota(25u, 35u);
for (auto && value : sequence1)
ibf.emplace(value, seqan::hibf::bin_index{0u});
for (auto && value : sequence2)
ibf.emplace(value, seqan::hibf::bin_index{4u});
for (auto && value : sequence3)
ibf.emplace(value, seqan::hibf::bin_index{7u});
auto agent = ibf.counting_agent();
auto & result = agent.bulk_count(sequence1);
seqan::hibf::print(result);
seqan::hibf::print(agent.bulk_count(values));
seqan::hibf::print(agent.bulk_count(std::views::iota(0u, 1024u)));
auto agent2 = ibf.counting_agent<uint8_t>();
seqan::hibf::print(agent2.bulk_count(sequence1));
}
The IBF binning directory. A data structure that efficiently answers set-membership queries for multi...
Definition interleaved_bloom_filter.hpp:144
Provides seqan::hibf::interleaved_bloom_filter.
A strong type that represents the number of bins for the seqan::hibf::interleaved_bloom_filter.
Definition interleaved_bloom_filter.hpp:41
A strong type that represents the number of bits for each bin in the seqan::hibf::interleaved_bloom_f...
Definition interleaved_bloom_filter.hpp:50
A strong type that represents the number of hash functions for the seqan::hibf::interleaved_bloom_fil...
Definition interleaved_bloom_filter.hpp:59
int main()
{
auto agent = ibf.counting_agent();
agent = ibf.counting_agent();
}
#include <hibf/misc/print.hpp>
int main()
{
auto agent = ibf.membership_agent();
counts += agent.bulk_contains(712);
seqan::hibf::print(counts);
counts += agent.bulk_contains(237);
seqan::hibf::print(counts);
counts += agent.bulk_contains(126);
seqan::hibf::print(counts);
counts += counts;
seqan::hibf::print(counts);
}
A data structure that behaves like a std::vector and can be used to consolidate the results of multip...
Definition counting_vector.hpp:146
Provides seqan::hibf::counting_vector.
A strong type that represents the bin index for the seqan::hibf::interleaved_bloom_filter.
Definition interleaved_bloom_filter.hpp:68
#include <hibf/misc/print.hpp>
int main()
{
auto sequence1 = std::views::iota(0u, 20u);
auto sequence2 = std::views::iota(10u, 30u);
auto sequence3 = std::views::iota(25u, 35u);
for (auto && value : sequence1)
ibf.emplace(value, seqan::hibf::bin_index{0u});
for (auto && value : sequence2)
ibf.emplace(value, seqan::hibf::bin_index{4u});
for (auto && value : sequence3)
ibf.emplace(value, seqan::hibf::bin_index{7u});
auto agent = ibf.counting_agent();
seqan::hibf::print(agent.bulk_count(sequence1));
seqan::hibf::print(agent.bulk_count(sequence1));
seqan::hibf::print(agent.bulk_count(std::views::iota(0u, 1024u)));
seqan::hibf::print(agent.bulk_count(std::views::iota(0u, 1024u)));
}
#include <hibf/misc/print.hpp>
int main()
{
auto agent = ibf.membership_agent();
seqan::hibf::print(agent.bulk_contains(126));
seqan::hibf::print(agent.bulk_contains(712));
seqan::hibf::print(agent.bulk_contains(237));
}
#include <hibf/misc/print.hpp>
int main()
{
auto agent = ibf.membership_agent();
auto & result = agent.bulk_contains(712);
seqan::hibf::print(result);
agent = ibf.membership_agent();
}
int main()
{
auto agent = ibf.membership_agent();
agent = ibf.membership_agent();
}
#include <hibf/config.hpp>
#include <hibf/hierarchical_interleaved_bloom_filter.hpp>
int main()
{
{
for (auto value : user_bin_data[user_bin_id])
it = value;
};
.number_of_user_bins = 3u,
.number_of_hash_functions = 2u,
.maximum_fpr = 0.05,
.threads = 1u};
auto agent = hibf.membership_agent();
auto & result1 = agent.membership_for(query1, 2u);
for (int64_t hit_user_bin : result1)
std::cout << hit_user_bin <<
' ';
auto query2 = std::views::iota(0u, 15u);
auto & result2 = agent.membership_for(query2, 5u);
agent.sort_results();
for (int64_t hit_user_bin : result2)
std::cout << hit_user_bin <<
' ';
}
#include <gtest/gtest.h>
#include <hibf/test/sandboxed_path.hpp>
#include <hibf/test/tmp_directory.hpp>
TEST(snippet_tmp_directory, tmp_directory_)
{
seqan::hibf::test::tmp_directory tmp{};
{
ofs << "Hello World!";
}
EXPECT_TRUE(tmp.empty());
}