Links
- To read:
- Perfect Hashing
- Cuckoo Hashing
- Murmur and Jenkins Hashing
- These two hash functions are not cryptographic, but do generate reasonably well distributed values (good for bloom filters.)
- Good hash functions – with supporting data (Dr Dobbs)
- Hash functions
- Jenkins hash
- Five Myths about Hash Tables
- In-memory Hash Tables for Accumulating Text Vocabularies
- Has a few fast hash function definitions.
- Fastest is: bitwisehash.c
- bitwisehash.c
- radixhash.c
- Redis' hashing code
Snippets
bitwisehash.c
/* Author J. Zobel, April 2001. Permission to use this code is freely granted, provided that this statement is retained. */ /* Modified by chirayu for personal quick readibility. */ /* Bitwise hash function. Note that tsize does not have to be prime. */ unsigned int bitwisehash(char *word, int tsize, unsigned int seed) { char c; for (unsigned int h=seed; (c=*word) != '\0'; word++) { h ^= ( (h << 5) + c + (h >> 2) ); } h = (h & 0x7fffffff) % tsize; return ((unsigned int) h); }