|
Dear
James,
What
you're describing is a good implementation of the LRU (Least-Recently-Used)
cache. Mine is a LFU (Least-Frequently-Used) cache.
Also,
I should mention that the performance of removing from a Vector by item value
(not item index in the List) is O(n) as well, so your implementation probably
suffers from the same problem as mine, i.e. the speed of cache operations
depends linearly on the cache size. I expect that due to using a Vector to
maintain the order you'll get an O(n) performance for both for get() and
add().
Nonetheless, thanks for letting me know
that this works well under "normal circumstances". That is
very encouraging!
BTW, a slightly better implementation of the LRUCache is to use a
hand-made linked list instead of a Vector. That way you get constant-time
performance for get() and add() since you maintain the pointers to the head and
tail of the list, as well as pointers to every individual element (through the
hash) so you don't need to re-shuffle your List every time you remove something,
you just point the (now orphan) child back to the grand-parent and you're
done. By using a linked list to maintain the order, you get O(alpha) (i.e.
constant-time) for the remove() and add() operations (no search time and no
reshuffling) that results in O(alpha) for both get() and add() operations in the
cache. I can send you that implementation if you like.
If
only I could get that kind of O(alpha) performance for the LFUCache
add()... Darn!!
:-)
Greg
--- You are currently subscribed to jdjlist as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] http://www.sys-con.com/fusetalk To unsubscribe from all mailing lists, click: http://sys-con.com/[EMAIL PROTECTED] |
Title: RE: [jdjlist] Re: LFUCache problem
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation Greg Nudelman
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation James Stauffer
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation Greg Nudelman
- [jdjlist] Re: LFUCache -- LRU vs LFU implementation [EMAIL PROTECTED]
