From c903f6b265a3acba2f8c1c99bf11acc2504254d3 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 18 Aug 2023 21:49:49 +0200 Subject: [PATCH] Add constexpr rsync_hash::repeating_window() --- include/dwarfs/cyclic_hash.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/dwarfs/cyclic_hash.h b/include/dwarfs/cyclic_hash.h index 559f899f..36c02531 100644 --- a/include/dwarfs/cyclic_hash.h +++ b/include/dwarfs/cyclic_hash.h @@ -50,6 +50,13 @@ class rsync_hash { len_ = 0; } + static constexpr uint32_t repeating_window(uint8_t byte, size_t length) { + uint16_t v = static_cast(byte); + uint16_t a{static_cast(v * length)}; + uint16_t b{static_cast(v * (length * (length + 1)) / 2)}; + return static_cast(a) | (static_cast(b) << 16); + } + private: uint16_t a_{0}; uint16_t b_{0};