In my Android project I have a method to partially invalidate a cache
(HashMap<Integer, Boolean>
).
I am currently using a HashMap for compatibility with third party code.
I found a great answer here but it requires switching to a TreeMap. The given solution is:
treeMap.tailMap(key).clear();
The TreeMap solution is much better than my effort on HashMap:
//where hashMap is a copied instance for the method
for (Integer key : hashMap.keySet()) {
if (key > minPosition) {
hashMap.remove(key);
}
}
Is there a better time/complexity solution for doing this in a HashMap, similar to the TreeMap solution?