Hash functions: desiderata

A hash function should be very fast to compute

A hash function should also distribute keys as uniformly as possible in the hash table, to avoid collisions as much as possible

For example, you don’t want a hash function that will map the set of keys to only a subset of the locations in the table!

Ideally: all the bits in the hash function should depend on each bit in the key

A hash function should be consistent with the equality testing function

If two keys are equal, the hash function should map them to the same table location

Otherwise, the fundamental hash table operations will not work correctly

A good choice of hash function can depend on the type of keys, the distribution of key insert requests, and the size of the table; and it is often difficult to design a good one

(If you know the actual keys in advance, you can construct a "perfect" hash function, which never has any collisions; this has some uses, but obviously it’s more usual not to know the keys in advance)

We will look at some commonly used hash functions for some different types of keys
CONTENTS PREVIOUS NEXT