galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
FNV1a.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_MATH_FNV1A_HPP_
9#define GALAXY_MATH_FNV1A_HPP_
10
11#include <type_traits>
12
13namespace galaxy
14{
15 namespace math
16 {
22 template<typename T>
23 concept valid_fnv_bits = std::is_same_v<T, std::uint32_t> || std::is_same_v<T, std::uint64_t>;
24
30 template<valid_fnv_bits bits = std::uint64_t>
32
36 template<>
37 struct fnv_1a_params<std::uint32_t>
38 {
39 static constexpr auto offset = 2166136261;
40 static constexpr auto prime = 16777619;
41 };
42
46 template<>
47 struct fnv_1a_params<std::uint64_t>
48 {
49 static constexpr auto offset = 14695981039346656037ull;
50 static constexpr auto prime = 1099511628211ull;
51 };
52
63 template<valid_fnv_bits bits = std::uint64_t>
64 inline constexpr bits fnv1a(const char* const str, const bits value = fnv_1a_params<bits>::offset) noexcept
65 {
66 return (str[0] == '\0') ? fnv_1a_params<bits>::offset : fnv1a<bits>(&str[1], (fnv_1a_params<bits>::offset ^ static_cast<bits>(str[0])) * fnv_1a_params<bits>::prime);
67 }
68 } // namespace math
69} // namespace galaxy
70
71#endif
Concept to enforce fnv bit types.
Definition FNV1a.hpp:23
constexpr bits fnv1a(const char *const str, const bits value=fnv_1a_params< bits >::offset) noexcept
Convert string to hash.
Definition FNV1a.hpp:64
Timer.hpp galaxy.
Definition Async.hpp:17
STL namespace.
Base specialization for fnv1a params.
Definition FNV1a.hpp:31