4 ms·
For comparison's sake, here's a simple LRU in Erlang: http://erlangquicktips.heroku.com/2008/10/05/an-erlang-lru-module/ http://erlangquicktips.heroku.com/2008/
by tlack 15y ago
For comparison's sake, here's a simple LRU in Erlang: http://erlangquicktips.heroku.com/2008/10/05/an-erlang-lru-module/ http://erlangquicktips.heroku.com/2008/10/05/an-erlang-lru-m...
- rudiger 15y agoIn 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.
- fogus 15y agoAnd one in Clojure. :-) https://github.com/clojure/core.cache/blob/master/src/main/clojure/clojure/core/cache.clj#L151 https://github.com/clojure/core.cache/blob/master/src/main/c...