For managing some cache, I need a sort of Hashtable with the ability to remove the oldest elements in order to keep the MAXSIZE last elements in the table. I need to program this in Java but any algorithm with pseudo code would be fine too.
public interface LimitedHashtable<K, V> {
void put(K k, V v); // will remove the oldest element from the table if size > MAXSIZE
V get(K k);
}
Any idea?
The only way I know is to keep a queue of the keys in your hash, and use that to expel keys when the table & queue get too big