diff --git a/TACTLib/Core/Key/CASCKeyComparer.cs b/TACTLib/Core/Key/CASCKeyComparer.cs index 5cff7a0..bd9aa2d 100644 --- a/TACTLib/Core/Key/CASCKeyComparer.cs +++ b/TACTLib/Core/Key/CASCKeyComparer.cs @@ -3,9 +3,6 @@ namespace TACTLib.Core.Key { public class CASCKeyComparer : IEqualityComparer, IEqualityComparer { - private const uint FnvPrime32 = 0x1000193; - private const uint FnvOffset32 = 0x811C9DC5; - /// Static instance public static readonly CASCKeyComparer Instance = new CASCKeyComparer(); @@ -21,35 +18,16 @@ private static bool Equals(ReadOnlySpan spanA, ReadOnlySpan spanB) { return spanA.SequenceEqual(spanB); } - public unsafe int GetHashCode(TruncatedKey obj) { - var hash = FnvOffset32; - var ptr = (uint*) &obj; - - for (var i = 0; i < 2; i++) { - hash ^= ptr[i]; - hash *= FnvPrime32; - } - - var hashPtr = (byte*) &hash; - var b = *((byte*)ptr + 8); - for (var i = 0; i < 4; ++i) { - hashPtr[i] ^= b; - } - - return unchecked((int) hash); + public int GetHashCode(TruncatedKey obj) { + var h = new HashCode(); + h.AddBytes(obj); + return h.ToHashCode(); } - public unsafe int GetHashCode(FullKey obj) { - var hash = FnvOffset32; - - var ptr = (uint*) &obj; - - for (var i = 0; i < 4; i++) { - hash ^= ptr[i]; - hash *= FnvPrime32; - } - - return unchecked((int) hash); + public int GetHashCode(FullKey obj) { + var h = new HashCode(); + h.AddBytes(obj); + return h.ToHashCode(); } } } \ No newline at end of file