Created
December 4, 2010 10:40
-
-
Save neesenk/728099 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
/* from http://www.isthe.com/chongo/tech/comp/fnv/index.html */ | |
uint32_t fnv(const void *buf, size_t len, uint32_t seed) | |
{ | |
const uint8_t *bp, *be; | |
uint32_t h = seed ^ len; | |
for (bp = (const uint8_t *)buf, be = bp + len; bp < be; bp++) { | |
h ^= (uint32_t)(*bp); | |
/* h *= 0x01000193 */ | |
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24); | |
} | |
return h; | |
} | |
uint32_t fnvs(const void *str, uint32_t seed) | |
{ | |
const uint8_t *bp = (const uint8_t *)str; | |
uint32_t h = seed ^ len; | |
while (*bp) { | |
h ^= (uint32_t)(*bp++); | |
/* h *= 0x01000193 */ | |
h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24); | |
} | |
return h; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment