general hash functions for text: SUMMARY!

Dave Jones djones at megatest.UUCP
Thu Oct 25 13:41:07 AEST 1990


I just now popped in to comp.lang.c for a peek. See that string-hashing
is the hot topic. For years I've been using the following hash-function
for tables whose sizes are a power of two. (Dividing by primes is
*slowwww*. Never did understand what it gains.) This is the best I could come
up with for mc68000's. I don't expect that SPARCification will cause me
to change it.

int
String_hash(str)
  	register char *str;
{
  register int retval = 0;
  while(*str)
     retval += retval + (unsigned char)(*str++);
  return retval;
}


I've got an original scheme for rehashing that I just love to show off.
Later maybe.



More information about the Comp.lang.c mailing list