feat: non-generic FNV1a hasher added

This commit is contained in:
2025-10-27 16:02:11 +03:00
parent 98bc0693dd
commit b17f880ecf
2 changed files with 22 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
namespace Engine.Systems.Network;
public static class Hasher
{
public static long FNV1a(string name)
{
const long fnvPrime = 1099511628211;
long result = 1469598103934665603;
unchecked
{
foreach (char c in name)
{
result ^= c;
result *= fnvPrime;
}
}
return result;
}
}

View File

@@ -8,18 +8,7 @@ public static class TypeHasher<T>
get get
{ {
if (_fnv1a == 0) if (_fnv1a == 0)
unchecked _fnv1a = Hasher.FNV1a(typeof(T).FullName ?? typeof(T).Name);
{
const long fnvPrime = 1099511628211;
_fnv1a = 1469598103934665603;
string typeName = typeof(T).FullName ?? typeof(T).Name;
foreach (char c in typeName)
{
_fnv1a ^= c;
_fnv1a *= fnvPrime;
}
}
return _fnv1a; return _fnv1a;
} }