|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.efs.Utils.SimpleLRUMapAutoSizeForHitRate<K,V>
public static final class Utils.SimpleLRUMapAutoSizeForHitRate<K,V>
Simplified map with fixed capacity that discards excess items in LRU (Least Recently Used) order to meet a hit/miss ratio goal. This adjusts its size to maintain a specific hit/miss ratio in get(), a miss being a get() that returns null, trimming away older items at insert to maintain the ratio.
This will also discard entries LRU if memory is under stress while the map is above its minimum size.
This provides optional fixed lower and upper sizes. Attempts to insert more items than the ceiling capacity will result in old items being removed in LRU order, thus leaving the newest items in the cache.
Each put() or get() makes its key/value pair the most-recently used and thus the last to be removed from the map of current key/value pairs when a series of put()s forces the map to overflow.
Thread-safe.
A lock can be held on instances of this object to make compound operations atomic.
Does not support the full Map interface.
| Field Summary | |
|---|---|
static float |
DEFAULT_LOAD_FACTOR
Default load factor. |
static float |
DEFAULT_MAX_MISS_RATE
Default maximum miss rate ]0.0,1.0[. |
static int |
DEFAULT_MIN_SIZE
Default minimum size/capacity, also initial capacity; strictly positive. |
| Constructor Summary | |
|---|---|
Utils.SimpleLRUMapAutoSizeForHitRate()
Create an instance with all defaults and therefore an effectively-unbounded upper capacity of Integer.MAX_VALUE. |
|
Utils.SimpleLRUMapAutoSizeForHitRate(float maxMissRate,
int minSize)
Create an instance with the given parameters. |
|
Utils.SimpleLRUMapAutoSizeForHitRate(float maxMissRate,
int minSize,
int maxCapacity,
float loadFactor)
Create an instance with the given parameters. |
|
Utils.SimpleLRUMapAutoSizeForHitRate(int minSize,
int maxCapacity)
Create an instance with all defaults except for the specified minimum/maximum capacities. |
|
| Method Summary | ||
|---|---|---|
void |
clear()
Clear the map and reset the hit/miss counters. |
|
void |
compact()
Compact by discarding all LRU items above the minimum size, ignoring the miss-rate target. |
|
static
|
create(float maxMissRate,
int minSize,
int maxCapacity,
float loadFactor)
Create an instance with the given parameters. |
|
V |
get(K key)
Get an entry from the map, making it the Most Recently Used; null if no such element. |
|
java.util.Map<K,V> |
getCopy()
Take a copy of the map contents, which does not alter LRU; never null. |
|
V |
put(K key,
V value)
Put an entry in the map, making it the Most Recently Used, returning the previous value if any. |
|
V |
remove(K key)
Remove an entry from the map and return the removed value, if any, else null. |
|
int |
size()
Return the number of entries in the map; non-negative. |
|
java.lang.String |
toString()
Provide a human-readable summary of status. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final float DEFAULT_MAX_MISS_RATE
public static final float DEFAULT_LOAD_FACTOR
public static final int DEFAULT_MIN_SIZE
| Constructor Detail |
|---|
public Utils.SimpleLRUMapAutoSizeForHitRate()
public Utils.SimpleLRUMapAutoSizeForHitRate(int minSize,
int maxCapacity)
public Utils.SimpleLRUMapAutoSizeForHitRate(float maxMissRate,
int minSize)
maxMissRate - the target cache maximum miss rate;
in the range 0.0f to 1.0f exclusive (typically << 0.1)minSize - the minimum (and initial) capacity;
strictly positive
public Utils.SimpleLRUMapAutoSizeForHitRate(float maxMissRate,
int minSize,
int maxCapacity,
float loadFactor)
maxMissRate - the target cache maximum miss rate;
in the range 0.0f to 1.0f exclusive (typically << 0.1)minSize - the minimum (and initial) capacity;
strictly positivemaxCapacity - the maximum capacity;
greater than minCapacity (and this strictly positive)loadFactor - the load factor of the underlying hash table;
in the range 0.0f to 1.0f exclusive (typically ~0.7f)| Method Detail |
|---|
public V get(K key)
public static <K,V> Utils.SimpleLRUMapAutoSizeForHitRate<K,V> create(float maxMissRate,
int minSize,
int maxCapacity,
float loadFactor)
maxMissRate - the target cache maximum miss rate;
in the range 0.0f to 1.0f exclusive (typically << 0.1)minSize - the minimum (and initial) capacity;
strictly positivemaxCapacity - the maximum capacity;
greater than minCapacity (and this strictly positive)loadFactor - the load factor of the underlying hash table;
in the range 0.0f to 1.0f exclusive (typically ~0.7f)public void compact()
May be automatically called in the background when memory is low/stressed.
public V put(K key,
V value)
public V remove(K key)
public void clear()
public int size()
public java.util.Map<K,V> getCopy()
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||