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};