HIBF
1.0.0-rc.1
Loading...
Searching...
No Matches
subtract_empty_bins.hpp
1
// SPDX-FileCopyrightText: 2006-2026, Knut Reinert & Freie Universität Berlin
2
// SPDX-FileCopyrightText: 2016-2026, Knut Reinert & MPI für molekulare Genetik
3
// SPDX-License-Identifier: BSD-3-Clause
4
5
#pragma once
6
7
#include <
algorithm
>
// for clamp
8
#include <
cmath
>
// for ceil
9
#include <
cstddef
>
// for size_t
10
11
#include <
hibf/platform.hpp
>
12
13
namespace
seqan::hibf
14
{
15
22
[[nodiscard]]
constexpr
size_t
subtract_empty_bins
(
size_t
const
tmax,
double
const
fraction)
noexcept
23
{
24
// There must be at least 2 technical bins available without empty bins.
25
// Otherwise, there would only ever be one technical bin available.
26
if
(fraction == 0.0 || tmax <= 2u)
27
return
tmax;
28
29
// `tmax * fraction` may exceed an integer by a rounding error, e.g., for the fraction `1 - subtracted / tmax` that
30
// config::validate_and_set_defaults() sets. It then counts as that integer. Otherwise, a repeated
31
// config::validate_and_set_defaults() could change the fraction again.
32
double
const
rounding_error = tmax * 1e-12;
33
size_t
const
number_of_empty_bins =
std::clamp<size_t>
(
std::ceil
(tmax * fraction - rounding_error), 1, tmax - 2);
34
return
tmax - number_of_empty_bins;
35
}
36
37
}
// namespace seqan::hibf
algorithm
std::ceil
T ceil(T... args)
cmath
cstddef
seqan::hibf::subtract_empty_bins
constexpr size_t subtract_empty_bins(size_t const tmax, double const fraction) noexcept
Returns the number of technical bins available for use.
Definition
subtract_empty_bins.hpp:22
std::is_base_of_v
T is_base_of_v
platform.hpp
Provides platform and dependency checks.
hibf
misc
subtract_empty_bins.hpp
Generated on Fri Oct 30 2026 02:59:02 for HIBF by
1.10.0