mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 08:09:19 +02:00
ECS System WIP
This commit is contained in:
41
registry/NameHash.h
Normal file
41
registry/NameHash.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
constexpr uint64_t FNV1A_OFFSET_BASIS_64 = 14695981039346656037ull;
|
||||
constexpr uint64_t FNV1A_PRIME_64 = 1099511628211ull;
|
||||
|
||||
constexpr uint64_t HashLiteral(const char* str, std::size_t len) noexcept
|
||||
{
|
||||
uint64_t hash = FNV1A_OFFSET_BASIS_64;
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
hash ^= static_cast<unsigned char>(str[i]);
|
||||
hash *= FNV1A_PRIME_64;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
constexpr uint64_t HashLiteral(const char* str) noexcept
|
||||
{
|
||||
uint64_t hash = FNV1A_OFFSET_BASIS_64;
|
||||
while (*str)
|
||||
{
|
||||
hash ^= static_cast<unsigned char>(*str++);
|
||||
hash *= FNV1A_PRIME_64;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
inline uint64_t HashRuntime(std::string_view str) noexcept
|
||||
{
|
||||
uint64_t hash = FNV1A_OFFSET_BASIS_64;
|
||||
for (char c : str)
|
||||
{
|
||||
hash ^= static_cast<unsigned char>(c);
|
||||
hash *= FNV1A_PRIME_64;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
Reference in New Issue
Block a user