xrxs/hash.c

16 lines
No EOL
301 B
C

#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;
}