Created
January 11, 2016 22:39
-
-
Save jstedfast/5a752e0adb19bbd3dcac to your computer and use it in GitHub Desktop.
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
class CustomOrdinalIgnoreCaseComparer : IEqualityComparer<string> | |
{ | |
static int ToLower (int c) | |
{ | |
if (c >= 0x41 && c <= 0x5A) | |
return c + 0x20; | |
return c; | |
} | |
public bool Equals (string x, string y) | |
{ | |
if (x.Length != y.Length) | |
return false; | |
for (int i = 0; i < x.Length; i++) { | |
if (ToLower (x[i]) != ToLower (y[i])) | |
return false; | |
} | |
return true; | |
} | |
public int GetHashCode (string obj) | |
{ | |
unsafe { | |
fixed (char *src = obj) { | |
int hash1 = 5381; | |
int hash2 = hash1; | |
char *s = src; | |
int c; | |
while ((c = s[0]) != 0) { | |
hash1 = ((hash1 << 5) + hash1) ^ ToLower (c); | |
c = s[1]; | |
if (c == 0) | |
break; | |
hash2 = ((hash2 << 5) + hash2) ^ ToLower (c); | |
s += 2; | |
} | |
return hash1 + (hash2 * 1566083941); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment