Skip to content

Instantly share code, notes, and snippets.

@korchoon
Last active May 6, 2020 10:09
Show Gist options
  • Select an option

  • Save korchoon/e21ab6dfea73029f1d8e075e13e2fde6 to your computer and use it in GitHub Desktop.

Select an option

Save korchoon/e21ab6dfea73029f1d8e075e13e2fde6 to your computer and use it in GitHub Desktop.
static class DirtyUtils {
static bool Same<T1, T2>(ref int hash, in T1 v1, in T2 v2) {
var prev = hash;
hash = v1.GetHashCode();
hash = (hash * 397) ^ v2.GetHashCode();
return hash == prev;
}
public static int HashCode<T1, T2>(in T1 v1, in T2 v2) {
var hash = v1.GetHashCode();
hash = (hash * 397) ^ v2.GetHashCode();
return hash;
}
public static int HashCode<T1, T2, T3>(in T1 v1, in T2 v2, in T3 v3) {
var hash = v1.GetHashCode();
hash = (hash * 397) ^ v2.GetHashCode();
hash = (hash * 397) ^ v3.GetHashCode();
return hash;
}
public static int HashCode<T1, T2, T3, T4>(in T1 v1, in T2 v2, in T3 v3, in T4 v4)
{
var hash = v1.GetHashCode();
hash = (hash * 397) ^ v2.GetHashCode();
hash = (hash * 397) ^ v3.GetHashCode();
hash = (hash * 397) ^ v4.GetHashCode();
return hash;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment