Created
November 19, 2018 08:25
-
-
Save mjs3339/dcd4622d7d025ab62bf12f91e3d462c7 to your computer and use it in GitHub Desktop.
C# Big Equality Comparer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BigComparer<T> : IBigEqualityComparer<T> | |
{ | |
private static FNV1a64 hash; | |
private static Type _type; | |
public bool Equals(T x, T y) | |
{ | |
if (x == null || y == null) | |
return false; | |
return object.Equals((T)x, (T)y); | |
} | |
public long GetHashCode(T obj) | |
{ | |
if (hash == null) | |
hash = new FNV1a64(); | |
if (_type == null) | |
_type = obj.GetType(); | |
return hash.ComputeHash(Converters.GetBytesObject(obj,_type)).ToLong(); | |
} | |
} | |
public interface IBigEqualityComparer<in T> | |
{ | |
bool Equals(T x, T y); | |
long GetHashCode(T obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment