hash.c (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <stdio.h> unsigned long long hash(char* str) { unsigned long long h; unsigned char* p; h = 0; for (p = (unsigned char*)str; *p != '\0'; p++) h = 37 * h + *p; return h; // or, h % ARRAY_SIZE; } int main(int argc, char** argv) { printf("%llu\n", hash(argv[1])); return 0; } |