AuroraRuntime/Include/Aurora/Hashing/CE/fnv1.hpp

35 lines
1.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: fnv1.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Hashing
{
namespace CE
{
constexpr AuUInt64 kFnv1MagicVal64 = 0xcbf29ce484222325;
constexpr AuUInt64 kFnv1MagicPrime64 = 0x100000001b3;
inline constexpr AuUInt64 fnv1a(const char *const str, const AuUInt64 value = kFnv1MagicVal64) noexcept
{
return (str[0] == '\0') ? value : fnv1a(&str[1], (value ^ AuUInt64(str[0])) * kFnv1MagicPrime64);
}
inline constexpr AuUInt32 fnv1a_trunc(const char *const str) noexcept
{
return static_cast<AuUInt32>(fnv1a(str));
}
constexpr AuUInt32 kFnv1MagicVal32 = 0x811c9dc5;
constexpr AuUInt32 kFnv1MagicPrime32 = 0x01000193;
inline constexpr AuUInt32 fnv1a_32(const char *const str, const AuUInt32 value = kFnv1MagicVal32) noexcept
{
return (str[0] == '\0') ? value : fnv1a_32(&str[1], (value ^ AuUInt32(str[0])) * kFnv1MagicPrime32);
}
}
}