I realized 13.4 LRU java book solution is currently using LinkedHashMap…
LinkedHashMap already supports access-order iteration and eviction via its 3-param constructor.
public LinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder)
A special constructor is provided to create a linked hash map whose order of iteration is the order in which its entries were last accessed, from least-recently accessed to most-recently (access-order). This kind of map is well-suited to building LRU caches. Invoking the put or get method results in an access to the corresponding entry (assuming it exists after the invocation completes).
so lookup() can just call get() and be done.
even re-insertion also places it to the front automatically if access-order is set to true. i just tested it.
so insert() can just call put() and be done.
in fact, if we’re allowed to use LinkedHashMap in the first place, we can just give LinkedHashMap with just removeEldestEntry overriden… it satisfies all the problem requirements in java. otherwise, we should not be allowed to use this class.