4 ms·
In Java, LinkedHashMap[1] is well-suited to building LRU caches. [1] http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashMap.html http://docs.oracle.c
by rudiger 15y ago
In Java, LinkedHashMap[1] is well-suited to building LRU caches.
[1] http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashMap.html http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHas...
- Someone 15y agoHowever, one should be aware of that "Note that insertion order is not affected if a key is re-inserted into the map". Because of that, a timestamps update must do: Cache.remove(key); Cache.put(key,value); Only doing the latter will not move the item to its correct location. Also, I am too lazy to chrck it, but I do not think this will have the same big-O as the C++ code.