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/c1c67c0051c1bafa00738fbd2908be1f to your computer and use it in GitHub Desktop.
Save joonas-yoon/c1c67c0051c1bafa00738fbd2908be1f to your computer and use it in GitHub Desktop.
hashing string to unique integer + padding (it can be compare)
#define MAX_LENGTH 13
unsigned long long str2llu(const char s[MAX_LENGTH + 1]) {
unsigned long long r = 0;
int i = 0;
for (; s[i]; ++i) r = r * 27 + s[i] - 'a' + 1;
for (; i < MAX_LENGTH; ++i) r = r * 27; // 길이가 동일하도록 패딩(padding) 해준다.
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment