use a simpler, faster hash function

This commit is contained in:
Andreas Gustafsson
2001-03-07 23:52:16 +00:00
parent a771f831b9
commit d55642259e

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: symtab.c,v 1.22 2001/01/09 21:56:31 bwelling Exp $ */
/* $Id: symtab.c,v 1.23 2001/03/07 23:52:16 gson Exp $ */
#include <config.h>
@@ -120,32 +120,22 @@ static inline unsigned int
hash(const char *key, isc_boolean_t case_sensitive) {
const char *s;
unsigned int h = 0;
unsigned int g;
int c;
/*
* 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.
*/
if (case_sensitive) {
for (s = key; *s != '\0'; s++) {
h = ( h << 4 ) + *s;
if ((g = ( h & 0xf0000000 )) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
h += (h << 3) + *s;
}
} else {
for (s = key; *s != '\0'; s++) {
c = *s;
c = tolower((unsigned char)c);
h = ( h << 4 ) + c;
if ((g = ( h & 0xf0000000 )) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
h += (h << 3) + c;
}
}