mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-16 07:46:27 -04:00
refactor: tweak compute_best_split() to use bit-or instead of shift
This commit is contained in:
parent
afe34ed8cf
commit
43e4970a54
@ -34,14 +34,16 @@
|
||||
namespace ricepp::detail {
|
||||
|
||||
template <unsigned FsMax, typename T>
|
||||
requires std::unsigned_integral<typename T::value_type>
|
||||
[[nodiscard]] std::pair<unsigned, unsigned>
|
||||
compute_best_split(T const& delta, size_t size, uint64_t sum) noexcept {
|
||||
auto bits_for_fs = [&](auto fs) {
|
||||
auto bits = size * (fs + 1);
|
||||
auto const mask = std::numeric_limits<typename T::value_type>::max() << fs;
|
||||
unsigned bits{0};
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
bits += delta[i] >> fs;
|
||||
bits += delta[i] & mask;
|
||||
}
|
||||
return bits;
|
||||
return size * (fs + 1) + (bits >> fs);
|
||||
};
|
||||
|
||||
static constexpr auto const kMaxBits = std::numeric_limits<uint64_t>::digits;
|
||||
|
Loading…
x
Reference in New Issue
Block a user