CoriEngine
Loading...
Searching...
No Matches
StringHash.hpp
Go to the documentation of this file.
1#pragma once
2#include <entt/entt.hpp>
3
4namespace Cori {
5 namespace Utility {
9 constexpr std::uint64_t fnv1a64(const char *str, const std::size_t len) {
10 std::uint64_t hash = 0xcbf29ce484222325ULL; // offset basis
11 for (std::size_t i = 0; i < len; ++i) {
12 hash ^= static_cast<unsigned char>(str[i]);
13 hash *= 0x100000001b3ULL; // fnv prime
14 }
15 return hash;
16 }
17
18 using StringHash64 = uint64_t;
19 using StringHash32 = entt::hashed_string::hash_type;
20
21 //constexpr StringHash32 HashString(const char* str) {
22 // return entt::hashed_string(str).value();
23 //}
24//
25 //constexpr StringHash32 HashString(const std::string& str) {
26 // return entt::hashed_string(str.c_str()).value();
27 //}
28 }
29}
30
34[[nodiscard]] consteval Cori::Utility::StringHash32 operator""_hs32(const char* str, [[maybe_unused]] size_t len) {
35 return entt::hashed_string(str).value();
36}
37
41[[nodiscard]] consteval Cori::Utility::StringHash64 operator""_hs64(const char* str, const size_t len) {
42 return Cori::Utility::fnv1a64(str, len);
43}
A namespace for utilities of different kinds.
Definition AABB.hpp:7
uint64_t StringHash64
entt::hashed_string::hash_type StringHash32
constexpr std::uint64_t fnv1a64(const char *str, const std::size_t len)
Computes the 64bit FNV-1a string hash.
Definition StringHash.hpp:9
Global engine namespace.