static inline unsigned long int hashValue(const char *key, const unsigned long int buckets) { register unsigned long int result = 0; if(!key) return 0; while(*key) result = result * 31 + *(key++); return (result % buckets); } int main(void) { int i; int buckets = 7; const char *keys[] = { "oneword", "wordone", "wordtwo", "threewd", "wordfr4", "hithere", 0 }; for(i = 0; keys[i]; i++) { printf("%s hashes to:\t%d\n", keys[i], hashValue(keys[i], buckets)); } }