Package org.apache.activemq.util
Class LFUCache<Key,Value>
- java.lang.Object
-
- org.apache.activemq.util.LFUCache<Key,Value>
-
- All Implemented Interfaces:
Map<Key,Value>
public class LFUCache<Key,Value> extends Object implements Map<Key,Value>
LFU cache implementation based on http://dhruvbird.com/lfu.pdf, with some notable differences:- Frequency list is stored as an array with no next/prev pointers between nodes: looping over the array should be faster and more CPU-cache friendly than using an ad-hoc linked-pointers structure.
- The max frequency is capped at the cache size to avoid creating more and more frequency list entries, and all elements residing in the max frequency entry are re-positioned in the frequency entry linked set in order to put most recently accessed elements ahead of less recently ones, which will be collected sooner.
- The eviction factor determines how many elements (more specifically, the percentage of) will be evicted.
- Author:
- Sergio Bossa
-
-
Constructor Summary
Constructors Constructor Description LFUCache(int maxCacheSize, float evictionFactor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object o)booleancontainsValue(Object o)Set<Map.Entry<Key,Value>>entrySet()intfrequencyOf(Key k)Valueget(Object k)booleanisEmpty()Set<Key>keySet()Valueput(Key k, Value v)voidputAll(Map<? extends Key,? extends Value> map)Valueremove(Object k)intsize()Collection<Value>values()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
frequencyOf
public int frequencyOf(Key k)
-
containsKey
public boolean containsKey(Object o)
- Specified by:
containsKeyin interfaceMap<Key,Value>
-
containsValue
public boolean containsValue(Object o)
- Specified by:
containsValuein interfaceMap<Key,Value>
-
-