Created
February 23, 2013 06:11
-
-
Save deplinenoise/5018663 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
uint32_t Djb2HashNoCase(const char *str_) | |
{ | |
const uint8_t *str = (const uint8_t *) str_; | |
uint32_t hash = 5381; | |
int c; | |
while (0 != (c = *str++)) | |
{ | |
#if 1 | |
// Branch free case folding for ASCII | |
const uint32_t cc = uint32_t(c - 'A'); | |
const uint32_t is_upper = -(cc <= ('Z' - 'A')); | |
const uint32_t lower_case_c = c | 0x20; | |
const uint32_t nocase_c = (lower_case_c & is_upper) | (c & ~is_upper); | |
#else | |
int nocase_c = (c >= 'A') && (c <= 'Z') ? c | 0x20 : c; | |
#endif | |
hash = (hash * 33) + nocase_c; | |
} | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment