String hash function #3

Here is a string hash function that uses Horner’s rule to compute a polynomial in
x
=16, using all the characters in the nullterminated string argument, plus doing some additional manipulations:
long hash(char* key) {
long hashVal = 0;
while (*key != ’/0’) {
hashVal = (hashVal << 4) + *(key++);
long g = hashval & 0xF0000000L;
if (g != 0) hashVal ^= g >>> 24;
hashVal &= ~g;
}
return hashVal;
}

This function is used in some C++ object file linking code

It apparently works well in practice, but its design is obscure!
CONTENTS PREVIOUS NEXT