11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
17PROMEKI_NAMESPACE_BEGIN
31constexpr uint64_t fnv1a(
const char *s, uint64_t seed = 0xcbf29ce484222325ULL) {
32 return *s ? fnv1a(s + 1, (seed ^
static_cast<uint64_t
>(*s)) * 0x100000001b3ULL) : seed;
46constexpr uint64_t fnv1aData(
const void *data,
size_t len, uint64_t seed = 0xcbf29ce484222325ULL) {
47 const auto *p =
static_cast<const unsigned char *
>(data);
48 for (
size_t i = 0; i < len; ++i) {
49 seed = (seed ^
static_cast<uint64_t
>(p[i])) * 0x100000001b3ULL;
66constexpr uint64_t fnv1aMixCodepoint(uint64_t seed,
char32_t cp) {
67 constexpr uint64_t prime = 0x100000001b3ULL;
68 seed = (seed ^
static_cast<uint64_t
>((cp >> 0) & 0xffu)) * prime;
69 seed = (seed ^
static_cast<uint64_t
>((cp >> 8) & 0xffu)) * prime;
70 seed = (seed ^
static_cast<uint64_t
>((cp >> 16) & 0xffu)) * prime;
71 seed = (seed ^
static_cast<uint64_t
>((cp >> 24) & 0xffu)) * prime;
87constexpr uint64_t fnv1aCodepoints(
const char32_t *data,
size_t count, uint64_t seed = 0xcbf29ce484222325ULL) {
88 for (
size_t i = 0; i < count; ++i) {
89 seed = fnv1aMixCodepoint(seed, data[i]);
107constexpr uint64_t fnv1aLatin1AsCodepoints(
const void *data,
size_t len, uint64_t seed = 0xcbf29ce484222325ULL) {
108 const auto *p =
static_cast<const unsigned char *
>(data);
109 for (
size_t i = 0; i < len; ++i) {
110 seed = fnv1aMixCodepoint(seed,
static_cast<char32_t>(p[i]));