Created
September 19, 2012 23:06
-
-
Save kpol/3752921 to your computer and use it in GitHub Desktop.
CombineHashCodes
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
| public static int CombineHashCodes(params int[] hashCodes) | |
| { | |
| if (hashCodes == null) | |
| { | |
| throw new ArgumentNullException("hashCodes"); | |
| } | |
| if (hashCodes.Length == 0) | |
| { | |
| throw new IndexOutOfRangeException(); | |
| } | |
| if (hashCodes.Length == 1) | |
| { | |
| return hashCodes[0]; | |
| } | |
| var result = hashCodes[0]; | |
| for (var i = 1; i < hashCodes.Length; i++) | |
| { | |
| result = CombineHashCodes(result, hashCodes[i]); | |
| } | |
| return result; | |
| } | |
| private static int CombineHashCodes(int h1, int h2) | |
| { | |
| return (h1 << 5) + h1 ^ h2; | |
| //unchecked | |
| //{ | |
| // var hash = 17; | |
| // hash = hash * 23 + h1; | |
| // hash = hash * 23 + h2; | |
| // return hash; | |
| //} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment