hash function for mac needed

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Fri Jun 21 09:53:42 AEST 1991


In article <14396 at dog.ee.lbl.gov> torek at elf.ee.lbl.gov (Chris Torek) writes:
> 		hash = (hash * 33) + (the character);

I see I've converted you from hash * 31 to hash * 33. :-)

  [ on the typical distribution of hash values with chaining ]

It's worth remembering the power series for exp. If your load factor---
that is, the number N of stored elements divided by the number of hash
values---is x, then there will be about exp(-x)N zero-element chains,
exp(-x)Nx one-element chains, exp(-x)Nx^2/2 two-element, exp(-x)Nx^3/3!
three-element, and so on. This holds up quite well in practice, and lets
you judge accurately how often a branch will be taken or how far it's
worth unrolling a loop when you're working with hash tables.

---Dan



More information about the Comp.lang.c mailing list