Created
November 18, 2014 17:02
-
-
Save morbidcamel101/1b5240830ca14c4ca3c1 to your computer and use it in GitHub Desktop.
Jenkins Hash algorithm
This file contains 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 GetJenkinsHash(this int[] values) | |
{ | |
unchecked | |
{ | |
uint hash, i; | |
for (hash = i = 0; i < values.Length; ++i) | |
{ | |
hash += (uint)(values[(int)i]); | |
hash += (hash << 10); | |
hash ^= (hash >> 6); | |
} | |
hash += (hash << 3); | |
hash ^= (hash >> 11); | |
hash += (hash << 15); | |
return (int)hash; | |
} | |
} | |
public static int GetJenkinsHash(this string text) | |
{ | |
// http://en.wikipedia.org/wiki/Jenkins_hash_function | |
unchecked | |
{ | |
uint hash, i; | |
for(hash = i = 0; i < text.Length; ++i) | |
{ | |
hash += (uint)(text[(int)i]); | |
hash += (hash << 10); | |
hash ^= (hash >> 6); | |
} | |
hash += (hash << 3); | |
hash ^= (hash >> 11); | |
hash += (hash << 15); | |
return (int)hash; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment