Created
March 30, 2016 12:00
-
-
Save matsumotory/ec4867e0aa60dec98853e3f0a2eab802 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // $ ./a.out 728_time_time_time | |
| // key offset: 5819 | |
| // $ ./a.out 414_time_time_time | |
| // key offset: 5819 | |
| // | |
| #include <stdio.h> | |
| #include <string.h> | |
| #define BUCKETS 20731 | |
| unsigned long hash(const char *s, size_t l) | |
| { | |
| unsigned long v; | |
| size_t i; | |
| for (v = 0, i = 0; i++ < l; s++) { v = *s + 31 * v; } | |
| return v; | |
| } | |
| int main(int argc, char **argv) | |
| { | |
| if (argc != 2) | |
| return 1; | |
| printf("key offset: %lu\n", hash(argv[1], strlen(argv[1])) % BUCKETS); | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/kazuho/status/715280296489275392
Kazuho Oku @kazuho
31=英語のアルファベットの種類より大きく、最小のコスト(ビットシフトと加算1回)で乗算できる素数 RT @matsumotory: 緩募:このキーオフセットの決め方の意味 / “create_key.c · GitHub” http://htn.to/aS71tSSnXJu
Today at 05:51