Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Created July 2, 2022 16:29
Show Gist options
  • Save codebrainz/d981938138248be266c52d4790c5a40f to your computer and use it in GitHub Desktop.
Save codebrainz/d981938138248be266c52d4790c5a40f to your computer and use it in GitHub Desktop.
A decent C string hashing function
#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