optimizationhashhashtable

Hash tables optimization


In several hash table implementations I've seen the usage of heuristics like "transpose" or "move to front" for items in a bucket.

  1. What are the advantages of using such heuristics? I could't figure it out myself.
  2. Which other optimizations can be done at the hash table / bucket level, why, and under which circumstances?

Optimizing hashing functions aside, please.


Solution

  • If collisions are happening and hence buckets have several items in them, which must be examined it would be convenient if commonly accessed items were early in the list.

    These heuristics make sense if there is reason to suppose that an item recently accessed is likely to be accessed again soon. When one considers something such as news stories, it's quite likely that breaking news would be accessed frequently.