Skip to content

Instantly share code, notes, and snippets.

@cobysy
Created June 1, 2015 11:02
Show Gist options
  • Select an option

  • Save cobysy/eee08eff90a6fa0c1ef6 to your computer and use it in GitHub Desktop.

Select an option

Save cobysy/eee08eff90a6fa0c1ef6 to your computer and use it in GitHub Desktop.
/// <summary>
/// "Fast"-implementation of building HashCode
/// </summary>
public static class HashCodeBuilder
{
internal const int Seedingprime = 42;
internal const int Hashingprime = 37;
public static int BuildHashCode(params object[] args)
{
if (args == null)
return 0;
unchecked
{
return args.Where(item => item != null).Aggregate(args.Length == 0 ? Seedingprime : 0, (current, item) =>
{
if (item == null) return current;
if (item.GetType().IsArray) return BuildHashCode(((IEnumerable) item).Cast<object>().ToArray());
return current*Hashingprime + item.GetHashCode();
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment