Skip to content

Instantly share code, notes, and snippets.

@mjs3339
Created November 19, 2018 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjs3339/dcd4622d7d025ab62bf12f91e3d462c7 to your computer and use it in GitHub Desktop.
Save mjs3339/dcd4622d7d025ab62bf12f91e3d462c7 to your computer and use it in GitHub Desktop.
C# Big Equality Comparer
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