Hashing
We have seen that an array is the best way to implement a
map if the key type is integer and the range of possible keys is
not too large: access to an array is O(1).
What if the key type does not fit these criteria? The idea of
hashing is to use a hash function
h: KeyType → integer
- Convert a key to an integer so that it can be used as an
array index.
- Randomize, in the sense that two different keys usually
produce different hash values, and hash values are equally likely.
- h should not be too expensive to compute.
Contents
Page-10
Prev
Next
Page+10
Index