de.fu_berlin.ties.util
Class AdaptableLRUMap
java.lang.Object
java.util.AbstractMap
org.apache.commons.collections.map.AbstractHashedMap
org.apache.commons.collections.map.AbstractLinkedMap
org.apache.commons.collections.map.LRUMap
de.fu_berlin.ties.util.AdaptableLRUMap
- All Implemented Interfaces:
- Serializable, Cloneable, Map, BoundedMap, IterableMap, OrderedMap
public class AdaptableLRUMap
- extends LRUMap
A fixed-size map that uses an flexible adaptable strategy for pruning
entries based on LRU (pruning one the least recently used entries).
Instances of this class are not thread-safe and must be synchronized
externally, if required.
- Version:
- $Revision: 1.14 $, $Date: 2006/10/21 16:04:27 $, $Author: siefkes $
- Author:
- Christian Siefkes
- See Also:
- Serialized Form
Nested classes/interfaces inherited from interface java.util.Map |
Map.Entry<K,V> |
Fields inherited from class org.apache.commons.collections.map.AbstractHashedMap |
data, DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, entrySet, GETKEY_INVALID, GETVALUE_INVALID, keySet, loadFactor, MAXIMUM_CAPACITY, modCount, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID, size, threshold, values |
Constructor Summary |
AdaptableLRUMap(int maxSize,
float loadFactor,
Pruner prun,
RemoveCallback rmCallback,
int candidates,
int pruneNum)
Constructs a new, empty map with the specified initial capacity and
load factor. |
AdaptableLRUMap(int maxSize,
Pruner prun,
RemoveCallback rmCallback,
int candidates,
int pruneNum)
Constructs a new, empty map with the specified initial capacity and
a load factor of 0.8. |
Methods inherited from class org.apache.commons.collections.map.LRUMap |
addMapping, clone, doReadObject, doWriteObject, get, isFull, isScanUntilRemovable, maxSize, moveToMRU, reuseMapping, updateEntry |
Methods inherited from class org.apache.commons.collections.map.AbstractLinkedMap |
addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, init, lastKey, mapIterator, nextKey, orderedMapIterator, previousKey, removeEntry |
Methods inherited from class org.apache.commons.collections.map.AbstractHashedMap |
calculateNewCapacity, calculateThreshold, checkCapacity, containsKey, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, getEntry, hash, hashCode, hashIndex, isEmpty, isEqualKey, isEqualValue, keySet, put, putAll, removeMapping, reuseEntry, size, toString, values |
Methods inherited from interface java.util.Map |
clear, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, size, values |
AdaptableLRUMap
public AdaptableLRUMap(int maxSize,
Pruner prun,
RemoveCallback rmCallback,
int candidates,
int pruneNum)
throws IllegalArgumentException
- Constructs a new, empty map with the specified initial capacity and
a load factor of 0.8. If the number of candidates is one, this
class behaves like a normal
LRUMap
; otherwise the
Pruner
is consulted to decide which entry to prune.
- Parameters:
maxSize
- the maximum size of the mapprun
- Used to decide which entries to prunermCallback
- will be called back whenever a key is removed from this
map; might be null
candidates
- The number of candidates to consider for each pruning
operationpruneNum
- The number of elements to remove by each pruning
operation, must not be larger than candidates
- Throws:
IllegalArgumentException
- if one of the input parameters is
invalid
AdaptableLRUMap
public AdaptableLRUMap(int maxSize,
float loadFactor,
Pruner prun,
RemoveCallback rmCallback,
int candidates,
int pruneNum)
throws IllegalArgumentException
- Constructs a new, empty map with the specified initial capacity and
load factor. If the number of candidates is one, this
class behaves like a normal
LRUMap
; otherwise the
Pruner
is consulted to decide which entry to prune. A callback
object can be specified that will be informed whenever a key is removed
from this map.
- Parameters:
maxSize
- the maximum size of the maploadFactor
- the load factorprun
- used to decide which entries to prunermCallback
- will be called back whenever a key is removed from this
map; might be null
candidates
- the number of candidates to consider for each pruning
operationpruneNum
- the number of elements to remove by each pruning
operation, must not be larger than candidates
- Throws:
IllegalArgumentException
- if one of the input parameters is
invalid
getCandidateNumber
public int getCandidateNumber()
- Returns the number of candidates considered for each pruning operation.
- Returns:
- the value of the attribute
getPruneNumber
public int getPruneNumber()
- Returns the number of elements removed by each pruning operation.
- Returns:
- the value of the attribute
remove
public Object remove(Object key)
-
- Specified by:
remove
in interface Map
- Overrides:
remove
in class AbstractHashedMap
removeLRU
protected boolean removeLRU(AbstractLinkedMap.LinkEntry entry)
- Controls removal of one of the least recently used entries from the map.
Lets the pruner decide if there are multiple candidates to consider.
- Overrides:
removeLRU
in class LRUMap
- Parameters:
entry
- the least recently used entry
- Returns:
true
if the superclass should delete the
specified entry; false
if this class took the necessary
action by deleting the first getPruneNumber()
entries selected
by the pruner
Copyright © 2003-2007 Christian Siefkes. All Rights Reserved.