From f969863d54ae3f0ddccce84c6dd054fe1e792cf7 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 20 Jul 2000 01:14:48 +0000 Subject: [PATCH] replaced the hash function in dns_name_hash() by one that is simpler, faster, and produces a much more even distribution, particularly when the data to hash ends with a null byte like domain names often do --- lib/dns/name.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/dns/name.c b/lib/dns/name.c index 2f47192f16..a7cd880142 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: name.c,v 1.95 2000/07/14 19:12:53 tale Exp $ */ +/* $Id: name.c,v 1.96 2000/07/20 01:14:48 gson Exp $ */ #include @@ -448,7 +448,6 @@ dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) { unsigned int length; const unsigned char *s; unsigned int h = 0; - unsigned int g; unsigned char c; /* @@ -463,30 +462,20 @@ dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) { length = 16; /* - * P. J. Weinberger's hash function, adapted from p. 436 of - * _Compilers: Principles, Techniques, and Tools_, Aho, Sethi - * and Ullman, Addison-Wesley, 1986, ISBN 0-201-10088-6. + * This hash function is similar to the one Ousterhout + * uses in Tcl. */ - s = name->ndata; if (case_sensitive) { while (length > 0) { - h = ( h << 4 ) + *s; - if ((g = ( h & 0xf0000000 )) != 0) { - h = h ^ (g >> 24); - h = h ^ g; - } + h += ( h << 4 ) + *s; s++; length--; } } else { while (length > 0) { c = maptolower[*s]; - h = ( h << 4 ) + c; - if ((g = ( h & 0xf0000000 )) != 0) { - h = h ^ (g >> 24); - h = h ^ g; - } + h += ( h << 4 ) + c; s++; length--; }