...
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../concepts/snplib_concepts.h"
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include "../concepts/snplib_concepts.h"
|
||||||
|
|
||||||
namespace snplib {
|
namespace snplib
|
||||||
|
{
|
||||||
|
|
||||||
template <snplib_input_char_range_c R>
|
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;
|
size_t hash = 0, prime = 0;
|
||||||
if constexpr (sizeof(size_t) == 8) { // 64-bit
|
if constexpr (sizeof(size_t) == 8) { // 64-bit
|
||||||
@@ -27,10 +28,10 @@ static constexpr size_t FNV1aHash(const R& r)
|
|||||||
return hash;
|
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>
|
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;
|
size_t hash = 0, prime = 0;
|
||||||
if constexpr (sizeof(size_t) == 8) { // 64-bit
|
if constexpr (sizeof(size_t) == 8) { // 64-bit
|
||||||
@@ -51,10 +52,11 @@ static constexpr size_t FNV1aHash(std::forward_iterator auto begin, std::sentine
|
|||||||
|
|
||||||
|
|
||||||
// Boost implementation of hash combining
|
// Boost implementation of hash combining
|
||||||
template <snplib_hashable_c T, snplib_hashable_c ...Ts>
|
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 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 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) {
|
if constexpr (digits == 64) {
|
||||||
std::size_t x = seed + 0x9e3779b9 + std::hash<T>()(v);
|
std::size_t x = seed + 0x9e3779b9 + std::hash<T>()(v);
|
||||||
@@ -65,8 +67,7 @@ static constexpr void snplib_hash_combine(std::size_t& seed, const T& v, Ts&& ..
|
|||||||
x *= m;
|
x *= m;
|
||||||
x ^= x >> 28;
|
x ^= x >> 28;
|
||||||
seed = x;
|
seed = x;
|
||||||
}
|
} else { // 32-bits
|
||||||
else { // 32-bits
|
|
||||||
std::size_t x = seed + 0x9e3779b9 + std::hash<T>()(v);
|
std::size_t x = seed + 0x9e3779b9 + std::hash<T>()(v);
|
||||||
const std::size_t m1 = 0x21f0aaad;
|
const std::size_t m1 = 0x21f0aaad;
|
||||||
const std::size_t m2 = 0x735a2d97;
|
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
|
||||||
Reference in New Issue
Block a user