From 09f4647edefd4b3966c87b5e34b3306280fe5751 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Fri, 18 Sep 2026 09:48:11 +0300 Subject: [PATCH] ... --- include/snipplib/utils/snplib_hash.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/include/snipplib/utils/snplib_hash.h b/include/snipplib/utils/snplib_hash.h index 804a9c4..e960a81 100644 --- a/include/snipplib/utils/snplib_hash.h +++ b/include/snipplib/utils/snplib_hash.h @@ -1,14 +1,15 @@ #pragma once -#include "../concepts/snplib_concepts.h" #include +#include "../concepts/snplib_concepts.h" -namespace snplib { +namespace snplib +{ template -static constexpr size_t FNV1aHash(const R& r) +static constexpr size_t hash_FNV1a(const R& r) { - static_assert(sizeof(size_t) == 8 || sizeof(size_t) == 4, "ONLY FOR 32 or 64-bit size_t!!!"); + static_assert(sizeof(size_t) == 8 || sizeof(size_t) == 4, "The ONLY 32 or 64-bit std::size_t are supported!!!"); size_t hash = 0, prime = 0; if constexpr (sizeof(size_t) == 8) { // 64-bit @@ -27,10 +28,10 @@ static constexpr size_t FNV1aHash(const R& r) return hash; } -static constexpr size_t FNV1aHash(std::forward_iterator auto begin, std::sentinel_for auto end) +static constexpr size_t hash_FNV1a(std::forward_iterator auto begin, std::sentinel_for auto end) requires std::same_as>, char> { - static_assert(sizeof(size_t) == 8 || sizeof(size_t) == 4, "ONLY FOR 32 or 64-bit size_t!!!"); + static_assert(sizeof(size_t) == 8 || sizeof(size_t) == 4, "The ONLY 32 or 64-bit std::size_t are supported!!!"); size_t hash = 0, prime = 0; if constexpr (sizeof(size_t) == 8) { // 64-bit @@ -51,11 +52,12 @@ static constexpr size_t FNV1aHash(std::forward_iterator auto begin, std::sentine // Boost implementation of hash combining -template -static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&& ... vs) { +template +static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&&... vs) +{ static constexpr auto digits = std::numeric_limits::digits; - static_assert(digits == 64 || digits == 32, "Unsupported 'size_t' type size!"); - + static_assert(digits == 64 || digits == 32, "The ONLY 32 or 64-bit std::size_t are supported!!!"); + if constexpr (digits == 64) { std::size_t x = seed + 0x9e3779b9 + std::hash()(v); const std::size_t m = 0xe9846af9b1a615d; @@ -65,8 +67,7 @@ static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&& .. x *= m; x ^= x >> 28; seed = x; - } - else { // 32-bits + } else { // 32-bits std::size_t x = seed + 0x9e3779b9 + std::hash()(v); const std::size_t m1 = 0x21f0aaad; const std::size_t m2 = 0x735a2d97; @@ -83,4 +84,4 @@ static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&& .. } } -} // end of snplib namespace \ No newline at end of file +} // namespace snplib \ No newline at end of file