This commit is contained in:
2026-09-18 09:48:11 +03:00
parent cf36c0186f
commit 09f4647ede

View File

@@ -1,14 +1,15 @@
#pragma once
#include "../concepts/snplib_concepts.h"
#include <iterator>
#include "../concepts/snplib_concepts.h"
namespace snplib {
namespace snplib
{
template <snplib_input_char_range_c R>
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<decltype(begin)> auto end)
static constexpr size_t hash_FNV1a(std::forward_iterator auto begin, std::sentinel_for<decltype(begin)> auto end)
requires std::same_as<std::remove_cv_t<std::iter_value_t<decltype(begin)>>, 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 <snplib_hashable_c T, snplib_hashable_c ...Ts>
static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&& ... vs) {
template <snplib_hashable_c T, snplib_hashable_c... Ts>
static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&&... vs)
{
static constexpr auto digits = std::numeric_limits<std::size_t>::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<T>()(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<T>()(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
} // namespace snplib