On Wed, 2003-03-12 at 15:57, Gianni Tedesco wrote: > I would like to further hack pconn code to key on the binary structures > to get a little more memory efficiency, or at least use a better string > hashing function.
Heck, I just threw together this, it replaces hash_string with the fowler/noll/vo hash. Real world tests and my own experience show it to be possibly the best generic string hashing function out there. Not benchmarked it but thought it might be interesting anyway :) -- // Gianni Tedesco (gianni at scaramanga dot co dot uk) lynx --source www.scaramanga.co.uk/gianni-at-ecsc.asc | gpg --import 8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D
diff -urN squid-3.0-DEVEL-20030310/lib/hash.c squid-3.0-DEVEL-hash/lib/hash.c
--- squid-3.0-DEVEL-20030310/lib/hash.c 2003-01-23 00:37:01.000000000 +0000
+++ squid-3.0-DEVEL-hash/lib/hash.c 2003-03-12 16:05:41.000000000 +0000
@@ -65,18 +65,15 @@
static void hash_next_bucket(hash_table * hid);
+/* Updated to FNV1a hash - Mar 12 2003 - GT */
unsigned int
hash_string(const void *data, unsigned int size)
{
- const char *s = data;
- unsigned int n = 0;
- unsigned int j = 0;
- unsigned int i = 0;
- while (*s) {
- j++;
- n ^= 271 * (unsigned) *s++;
- }
- i = n ^ (j * 271);
+ unsigned int i=2166136261UL;
+
+ while( *data )
+ i = (i * 16777619UL) ^ *data++;
+
return i % size;
}
signature.asc
Description: This is a digitally signed message part
