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

35 lines
1.1 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
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
{
2021-10-08 23:39:42 +00:00
constexpr AuUInt64 kFnv1MagicVal64 = 0xcbf29ce484222325;
constexpr AuUInt64 kFnv1MagicPrime64 = 0x100000001b3;
2021-06-27 21:25:29 +00:00
2021-10-08 23:39:42 +00:00
inline constexpr AuUInt64 fnv1a(const char *const str, const AuUInt64 value = kFnv1MagicVal64) noexcept
2021-06-27 21:25:29 +00:00
{
2021-10-08 23:39:42 +00:00
return (str[0] == '\0') ? value : fnv1a(&str[1], (value ^ AuUInt64(str[0])) * kFnv1MagicPrime64);
2021-06-27 21:25:29 +00:00
}
inline constexpr uint32_t fnv1a_trunc(const char *const str) noexcept
{
return static_cast<uint32_t>(fnv1a(str));
}
2021-10-08 23:39:42 +00:00
constexpr AuUInt32 kFnv1MagicVal32 = 0x811c9dc5;
constexpr AuUInt32 kFnv1MagicPrime32 = 0x01000193;
2021-06-27 21:25:29 +00:00
2021-10-08 23:39:42 +00:00
inline constexpr uint32_t fnv1a_32(const char *const str, const AuUInt32 value = kFnv1MagicVal32) noexcept
2021-06-27 21:25:29 +00:00
{
2021-10-08 23:39:42 +00:00
return (str[0] == '\0') ? value : fnv1a_32(&str[1], (value ^ AuUInt32(str[0])) * kFnv1MagicPrime32);
2021-06-27 21:25:29 +00:00
}
}
}