// Hash modified by Robert Heckendorn based on work // By Arash Partow (http://www.partow.net/programming/hashfunctions/) // // An algorithm produced by me Arash Partow. I took ideas from all of // the above hash functions making a hybrid rotative and additive hash // function algorithm based around four primes 3,5,7 and 11. There isn't // any real mathematical analysis explaining why one should use this // hash function instead of the others described above other than the // fact that I tired to resemble the design as close as possible to a // simple LFBSR. An empirical result which demonstrated the distributive // abilities of the hash algorithm was obtained using a hash-table with // 100003 buckets, hashing The Project Gutenberg Etext of Webster's // Unabridged Dictionary, the longest encountered chain length was 7, // the average chain length was 2, the number of empty buckets was 4579. unsigned int hash(const char *str) { unsigned int hash; char c; hash = 0; for (bool toggle = false; c = *str++; toggle = !toggle) { if (toggle) hash ^= (hash << 7)^c^(hash >> 3); else hash ^= ~(hash << 11)^c^(hash >> 5); } return hash; }