Class LRUMap<K,V>

java.lang.Object
ghidra.util.datastruct.LRUMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
Map<K,V>
Direct Known Subclasses:
LRUSet

public class LRUMap<K,V> extends Object implements Map<K,V>
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 Details

    • map

      protected HashMap<K,ghidra.util.datastruct.LRUMap.Entry<K,V>> map
  • Constructor Details

    • LRUMap

      public LRUMap(int cacheSize)
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
    • removeEldestEntry

      protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
    • eldestEntryRemoved

      protected void eldestEntryRemoved(Map.Entry<K,V> eldest)
      This is called after an item has been removed from the cache.
      Parameters:
      eldest - the item being removed
    • toString

      public String toString()
      Overrides:
      toString in class Object