Mirror/Assets/Mirror/Runtime/StringHash.cs

19 lines
503 B
C#

namespace Mirror
{
public static class StringHash
{
// string.GetHashCode is not guaranteed to be the same on all machines, but
// we need one that is the same on all machines. simple and stupid:
public static int GetStableHashCode(this string text)
{
unchecked
{
int hash = 23;
foreach (char c in text)
hash = hash * 31 + c;
return hash;
}
}
}
}