views:

68

answers:

1

Hi

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.

+3  A: 

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.

djna
This is also known as a *self-optimizing list*, wherein the most commonly accessed items bubble to the front of the list.
Loadmaster
What Loadmaster said... Plus: Take a look at the splay-tree (wiki!) for ideas why moving things to the front is a good idea in general.
Nils Pipenbrinck