Created
July 2, 2022 16:29
-
-
Save codebrainz/d981938138248be266c52d4790c5a40f to your computer and use it in GitHub Desktop.
A decent C string hashing function
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
#include <stddef.h> | |
// sdbm from here: | |
// http://www.cse.yorku.ca/~oz/hash.html | |
static size_t cstr_hash(const char *str) | |
{ | |
size_t hash = 0; | |
int c; | |
while ((c = *str++)) | |
hash = c + (hash << 6) + (hash << 16) - hash; | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment