I am working on a simple data structure that will implement a cache eviction policy. The two possible scenarios I want to implement are LRU and MRU
I am looking for a map-like data structure where keys are possibly time (or maybe just auto incremented integer) to know which cache block is most recently used or least recently used. And values are the IDs of the blocks.
Is there an existent Data structure that sorts the data by the keys on insert, and retrieves the value of a certain key in O(1) time?
For instance Java's HashMap has the constant time lookup, but I will need to get all keys, sort them and pick the last or the first depending on the algorithm I am implementing. Is SortedMap what I should go for? Do you suggest any other data structures that work well with LRU and MRU implementations?
Thanks