Skip to content

Commit

Permalink
[IDEA] Dispatch to emplace{,_exists}
Browse files Browse the repository at this point in the history
Would need a dedicated config element later
  • Loading branch information
eseiler committed Oct 15, 2024
1 parent b3d8530 commit 2ead465
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion include/hibf/build/insert_into_ibf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace seqan::hibf::build
* \details
* Automatically does naive splitting if number_of_bins > 1.
*/
void insert_into_ibf(robin_hood::unordered_flat_set<uint64_t> const & kmers,
void insert_into_ibf(build_data const & data,
robin_hood::unordered_flat_set<uint64_t> const & kmers,
size_t const number_of_bins,
size_t const bin_index,
seqan::hibf::interleaved_bloom_filter & ibf,
Expand Down
2 changes: 1 addition & 1 deletion src/build/construct_ibf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ seqan::hibf::interleaved_bloom_filter construct_ibf(robin_hood::unordered_flat_s
local_index_allocation_timer.stop();
data.index_allocation_timer += local_index_allocation_timer;

insert_into_ibf(kmers, number_of_bins, ibf_node.max_bin_index, ibf, data.fill_ibf_timer);
insert_into_ibf(data, kmers, number_of_bins, ibf_node.max_bin_index, ibf, data.fill_ibf_timer);
if (!is_root)
update_parent_kmers(parent_kmers, kmers, data.merge_kmers_timer);

Expand Down
31 changes: 26 additions & 5 deletions src/build/insert_into_ibf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,25 @@
namespace seqan::hibf::build
{

template <bool use_exists>
inline void
dispatch_emplace(seqan::hibf::interleaved_bloom_filter & ibf, auto && values, seqan::hibf::bin_index const bin_index)
{
if constexpr (use_exists)
{
for (auto && value : values)
ibf.emplace_exists(value, bin_index);

Check warning on line 33 in src/build/insert_into_ibf.cpp

View check run for this annotation

Codecov / codecov/patch

src/build/insert_into_ibf.cpp#L33

Added line #L33 was not covered by tests
}
else
{
for (auto && value : values)
ibf.emplace(value, bin_index);
}
}

// automatically does naive splitting if number_of_bins > 1
void insert_into_ibf(robin_hood::unordered_flat_set<uint64_t> const & kmers,
void insert_into_ibf(build_data const & data,
robin_hood::unordered_flat_set<uint64_t> const & kmers,
size_t const number_of_bins,
size_t const bin_index,
seqan::hibf::interleaved_bloom_filter & ibf,
Expand All @@ -40,8 +57,10 @@ void insert_into_ibf(robin_hood::unordered_flat_set<uint64_t> const & kmers,
assert(chunk_number < number_of_bins);
seqan::hibf::bin_index const bin_idx{bin_index + chunk_number};
++chunk_number;
for (size_t const value : chunk)
ibf.emplace_exists(value, bin_idx);
if (data.config.empty_bin_fraction > 0.0)
dispatch_emplace<true>(ibf, std::move(chunk), bin_idx);
else
dispatch_emplace<false>(ibf, std::move(chunk), bin_idx);
}
local_fill_ibf_timer.stop();
fill_ibf_timer += local_fill_ibf_timer;
Expand All @@ -62,8 +81,10 @@ void insert_into_ibf(build_data const & data,

serial_timer local_fill_ibf_timer{};
local_fill_ibf_timer.start();
for (auto && value : values)
ibf.emplace_exists(value, bin_index);
if (data.config.empty_bin_fraction > 0.0)
dispatch_emplace<true>(ibf, std::move(values), bin_index);

Check warning on line 85 in src/build/insert_into_ibf.cpp

View check run for this annotation

Codecov / codecov/patch

src/build/insert_into_ibf.cpp#L85

Added line #L85 was not covered by tests
else
dispatch_emplace<false>(ibf, std::move(values), bin_index);
local_fill_ibf_timer.stop();
data.fill_ibf_timer += local_fill_ibf_timer;
}
Expand Down
5 changes: 3 additions & 2 deletions src/hierarchical_interleaved_bloom_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ size_t hierarchical_build(hierarchical_interleaved_bloom_filter & hibf,
size_t const mutex_id{parent_bin_index / 64};
std::lock_guard<std::mutex> guard{local_ibf_mutex[mutex_id]};
technical_bin_to_ibf_id[parent_bin_index] = new_ibf_pos;
build::insert_into_ibf(kmers, 1, parent_bin_index, ibf, data.fill_ibf_timer);
build::insert_into_ibf(data, kmers, 1, parent_bin_index, ibf, data.fill_ibf_timer);
if (!is_root)
build::update_parent_kmers(parent_kmers, kmers, data.merge_kmers_timer);
}
Expand All @@ -155,7 +155,8 @@ size_t hierarchical_build(hierarchical_interleaved_bloom_filter & hibf,
else
{
compute_kmers(kmers, data, record);
build::insert_into_ibf(kmers,
build::insert_into_ibf(data,
kmers,
record.number_of_technical_bins,
record.storage_TB_id,
ibf,
Expand Down

0 comments on commit 2ead465

Please sign in to comment.