Skip to content

Instantly share code, notes, and snippets.

@joonas-yoon
Last active February 21, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonas-yoon/32c473bd5ce28d68929e218f70adda99 to your computer and use it in GitHub Desktop.
Save joonas-yoon/32c473bd5ce28d68929e218f70adda99 to your computer and use it in GitHub Desktop.
hashing string to unique integer
#define MAX_LENGTH 13
unsigned long long str2llu(const char s[MAX_LENGTH + 1]) {
unsigned long long r = 0;
for (int i = 0; s[i]; ++i) r = r * 27 + s[i] - 'a' + 1;
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment