Package ghidra.util.datastruct
Class LRUMap<K,V>
java.lang.Object
ghidra.util.datastruct.LRUMap<K,V>
- Type Parameters:
K
- the key typeV
- the value type
- All Implemented Interfaces:
Map<K,
V>
- Direct Known Subclasses:
LRUSet
A LRU (Least Recently Used) map that maintains access-order (newest to oldest)
iteration over the elements.
This map is limited to the given size.
As new items are added, the older items will be removed from this map.
If you need to be notified of removals, then you can override
eldestEntryRemoved(java.util.Map.Entry)
.
If you don't want the eldest removed, override
removeEldestEntry(java.util.Map.Entry)
and return false;
If you would like to have the iteration order of your LRU structure be based upon access,
but want it to iterate from least recently used to most recently used, then you should see
FixedSizeHashMap
.
Note: this class is not thread safe.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) protected void
eldestEntryRemoved
(Map.Entry<K, V> eldest) This is called after an item has been removed from the cache.entrySet()
boolean
isEmpty()
keySet()
void
protected boolean
removeEldestEntry
(Map.Entry<K, V> eldest) int
size()
toString()
values()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
map
-
-
Constructor Details
-
LRUMap
public LRUMap(int cacheSize)
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
removeEldestEntry
-
eldestEntryRemoved
This is called after an item has been removed from the cache.- Parameters:
eldest
- the item being removed
-
toString
-