// persistable and synchronized
sclass MRUAndAllTimeTop_naive {
Map mru = syncMRUCache(10); // most recently used
new MultiSet allTimeTop;
int size;
// increase a's score in all time top and move to front int MRU
void add(A a) {
mru.remove(a); // force re-insertion
mru.put(a, true);
allTimeTop.add(a);
}
void addAll(Iterable l) { fOr (A a : l) add(a); }
// may count elements twice
int size() {
ret l(mru) + allTimeTop.uniqueSize();
}
// interleave latest and most often accessed elements
ItIt mixedIterator() {
ret uniqueIterator(roundRobinCombinedIterator(
reversedIterator(keysList(mru)),
iterator(allTimeTop.highestFirst())));
}
}