What about the use of salt to avoid hash table collision?

advertisements

If a key collides in a hash table, I want to find another position by salting the key, recursively, until I find a free position (always using the same salt).

For example:

  1. "bee" and "ant" hash to 7
  2. I insert "bee" in the table.
  3. Then when I insert "ant", it collides, I salt "ant" with "!23" (resulting in "!23ant") and call insert again (I store the original key, but use the salted key to get an index).

I searched for hash tables with this method, but did't find any material on it.

What are the downsides of this approach to collision handling?


From a performance perspective, each hash collision requires you to build a new string, which can take a long time if your input string is long. Also note that the cost of building this string increases as you get more and more hash collisions, so the price of a successful lookup ends up depending quadratically on how many collisions you had.

Comparing this salt based approach to other hashing approaches, I'd suspect that this extra cost would make your system slower in practice than other techniques like linear probing or double hashing, which might not have as good a distribution as your approach but don't have to do as much work to compute hash codes and construct auxiliary strings.