1515#include < hibf/config.hpp> // for config, insert_iterator
1616#include < hibf/contrib/robin_hood.hpp> // for hash, unordered_flat_set
1717#include < hibf/interleaved_bloom_filter.hpp> // for interleaved_bloom_filter, bin_count, bin_index, bin_size, hash_...
18+ #include < hibf/misc/add_empty_bins.hpp> // for add_empty_bins
1819#include < hibf/misc/bit_vector.hpp> // for bit_vector
1920#include < hibf/misc/divide_and_ceil.hpp> // for divide_and_ceil
2021#include < hibf/misc/unreachable.hpp> // for assert, unreachable
@@ -32,11 +33,12 @@ namespace seqan::hibf
3233interleaved_bloom_filter::interleaved_bloom_filter (seqan::hibf::bin_count const bins_,
3334 seqan::hibf::bin_size const size,
3435 seqan::hibf::hash_function_count const funs,
35- bool const track_occupancy_) :
36+ seqan::hibf::empty_bin_fraction const empty_bin_fraction,
37+ seqan::hibf::track_occupancy const track_occupancy) :
3638 bins{bins_.value },
3739 bin_size_{size.value },
3840 hash_funs{funs.value },
39- track_occupancy{track_occupancy_ }
41+ track_occupancy{track_occupancy. value || empty_bin_fraction. value > 0.0 }
4042{
4143 if (bins == 0 )
4244 throw std::logic_error{" The number of bins must be > 0." };
@@ -47,7 +49,14 @@ interleaved_bloom_filter::interleaved_bloom_filter(seqan::hibf::bin_count const
4749
4850 hash_shift = std::countl_zero (bin_size_);
4951 bin_words = divide_and_ceil (bins, 64u );
50- technical_bins = bin_words * 64u ;
52+ // Note: If the IBF is constructed as part of an HIBF, the layout only contains information about the
53+ // non-empty bins. Hence, we need to add the empty bins to the total number of bins.
54+ // Example: tmax = 320, empty_bin_fraction = 0.2
55+ // user bins = 320 * (1 - 0.2) = 256
56+ // The layout only contains information about the 256 bins.
57+ // The HIBF construction will then request an IBF with 256 bins.
58+ size_t const user_and_empty_bins = add_empty_bins (bins, empty_bin_fraction.value );
59+ technical_bins = next_multiple_of_64 (user_and_empty_bins);
5160 resize (technical_bins * bin_size_);
5261 occupancy.resize (technical_bins, 0u );
5362}
@@ -105,7 +114,8 @@ interleaved_bloom_filter::interleaved_bloom_filter(config & configuration, size_
105114 interleaved_bloom_filter{seqan::hibf::bin_count{configuration.number_of_user_bins },
106115 seqan::hibf::bin_size{max_bin_size (configuration, max_bin_elements)},
107116 seqan::hibf::hash_function_count{configuration.number_of_hash_functions },
108- configuration.track_occupancy }
117+ seqan::hibf::empty_bin_fraction{configuration.empty_bin_fraction },
118+ seqan::hibf::track_occupancy{configuration.track_occupancy }}
109119{
110120 size_t const chunk_size = std::clamp<size_t >(std::bit_ceil (bin_count () / configuration.threads ), 8u , 64u );
111121
@@ -150,12 +160,13 @@ void interleaved_bloom_filter::clear(bin_index const bin) noexcept
150160bool interleaved_bloom_filter::try_increase_bin_number_to (seqan::hibf::bin_count const new_bin_count) noexcept
151161{
152162 size_t const new_bins = new_bin_count.value ;
153- size_t const new_bin_words = divide_and_ceil (new_bins, 64u );
163+ size_t const new_technical_bins = next_multiple_of_64 (new_bins);
154164
155- if (new_bins < bins || new_bin_words > bin_words )
165+ if (new_bins < bins || new_technical_bins > technical_bins )
156166 return false ;
157167
158168 bins = new_bins;
169+ bin_words = divide_and_ceil (new_bins, 64u );
159170 return true ;
160171}
161172
0 commit comments