Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think they are implying you only pop() when you are doing the replacement (Trim). The rest of the time you Sink and Swim depending on how the LRU was done. IE: every time you get() an item you set the access time to now() and then call sink/swim to fix the ordering. This would give logn time to get and set.

See here for a very good writeup of priority queues and variants. http://algs4.cs.princeton.edu/24pq/

(not hugely familiar with Java so this stuff might be wrong) The implementation presented has some bad timing issues (List.Contains is a linear search). I think List.Remove is also a linear search. As well this implementation doesn't seem to do Point (1).



The OP is talking about a list with at most five items in it. Linear search is not an issue. Using a dict may even be slower than just searching a 5 element array linearly...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: