From 43e4970a5438a1867fbae4425802a9b4e14eaab9 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 3 Feb 2024 21:25:50 +0100 Subject: [PATCH] refactor: tweak compute_best_split() to use bit-or instead of shift --- ricepp/include/ricepp/detail/encode.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ricepp/include/ricepp/detail/encode.h b/ricepp/include/ricepp/detail/encode.h index ae3add63..19e249d7 100644 --- a/ricepp/include/ricepp/detail/encode.h +++ b/ricepp/include/ricepp/detail/encode.h @@ -34,14 +34,16 @@ namespace ricepp::detail { template + requires std::unsigned_integral [[nodiscard]] std::pair 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::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::digits;