2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-01 15:05:23 +00:00

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
This commit is contained in:
Andreas Gustafsson
2000-07-20 01:14:48 +00:00
parent dae5ce6ddb
commit f969863d54

View File

@@ -15,7 +15,7 @@
* SOFTWARE. * 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 <config.h> #include <config.h>
@@ -448,7 +448,6 @@ dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) {
unsigned int length; unsigned int length;
const unsigned char *s; const unsigned char *s;
unsigned int h = 0; unsigned int h = 0;
unsigned int g;
unsigned char c; unsigned char c;
/* /*
@@ -463,30 +462,20 @@ dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) {
length = 16; length = 16;
/* /*
* P. J. Weinberger's hash function, adapted from p. 436 of * This hash function is similar to the one Ousterhout
* _Compilers: Principles, Techniques, and Tools_, Aho, Sethi * uses in Tcl.
* and Ullman, Addison-Wesley, 1986, ISBN 0-201-10088-6.
*/ */
s = name->ndata; s = name->ndata;
if (case_sensitive) { if (case_sensitive) {
while (length > 0) { while (length > 0) {
h = ( h << 4 ) + *s; h += ( h << 4 ) + *s;
if ((g = ( h & 0xf0000000 )) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++; s++;
length--; length--;
} }
} else { } else {
while (length > 0) { while (length > 0) {
c = maptolower[*s]; c = maptolower[*s];
h = ( h << 4 ) + c; h += ( h << 4 ) + c;
if ((g = ( h & 0xf0000000 )) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++; s++;
length--; length--;
} }