2

While implementing a custom hash table with open addressing, I discovered that for my application, it helps performance if I swap the probed element in a row of filled slots with the one in the first probe location. (To optimize the table to quicker yield often-accessed elements)

Is there a name for this optimization?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
onno
  • 1,291
  • 2
  • 9
  • 7
  • 3
    In general this approach is called MRU caching. It's not specific to hash tables though. – rustyx Aug 29 '16 at 19:03
  • Thanks. I googled 'caching' and 'move to front' but only found articles about hash tables being used for implementing caches... I am wondering whether there are more variants for optimizing read accesses and what they (and this) are called in the literature, to -if available- try them out in my application. – onno Aug 29 '16 at 19:10

2 Answers2

1

The most general term for this kind of optimization is probably self-organization.

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
  • Thanks. This is indeed a good term. I found an old paper apparently describing the swapping: http://www.sciencedirect.com/science/article/pii/0020019085901036 I didn't buy the paper yet - but the first page is shown, and my optimization appears to be called method H2 in there. – onno Aug 30 '16 at 08:45
1

Your problem is very similar to the list update problem from the field of online-competitive algorithms.

The solution you used is known as MTF (move to front). This solution is known to be 2-competitive, meaning that it will do at most twice as bad as a hypothetical adversary which knows the future in advance.

Note that you can do slightly better than that with the bit algorithm, which requires another bit + random op, but is 7-4 competitive.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
  • Thank you, **list update problem** indeed seems to be appropriate! I looked for _hash table_ related links, but should have figured that a run of filled probing locations can of course be seen as a _list_ ... – onno Sep 16 '16 at 14:51
  • You're welcome. FWIW, I think it's a fascinating problem too. Note that if you would have used collision chaining, it would have been exactly this problem. Probing is slightly different - the cost of moving the last item to some position, shifting everything back, is not constant as in a list. Nevertheless, I think this is the closest problem to yours. – Ami Tavory Sep 16 '16 at 15:07