Created
June 1, 2015 11:02
-
-
Save cobysy/eee08eff90a6fa0c1ef6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /// <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