|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<T>
cz.cuni.jagrlib.IntMap<T>
cz.cuni.jagrlib.LRUCache<T>
public class LRUCache<T>
LRU-caching integer map. Stores only limited number of [int,value] pairs.
Nested Class Summary | |
---|---|
protected static class |
LRUCache.LRUItem
|
Nested classes/interfaces inherited from class cz.cuni.jagrlib.IntMap |
---|
IntMap.CommonIterator, IntMap.TargetIterator, IntMap.TupleIterator |
Field Summary | |
---|---|
protected int |
cacheCapacity
Cache capacity in items. |
protected LRUCache.LRUItem |
head
Head of the LRU-list. |
protected int |
HEAD_KEY
Special value used for LRU-list head. |
protected LRUCache.LRUItem |
recycled
Linked list of recycled items (older is used). |
Fields inherited from class cz.cuni.jagrlib.IntMap |
---|
maxLoad, NULL_KEY, REMOVED_KEY |
Constructor Summary | |
---|---|
LRUCache()
Dafault parameters (small initial capacity, default load factor = 0.6 ). |
|
LRUCache(int capacity)
Explicit map capacity, default load factor ( 0.6 ). |
|
LRUCache(int capacity,
float loadFactor)
Explicit map capacity and load-factor. |
|
LRUCache(java.util.Map<? extends java.lang.Integer,? extends T> m)
The same mappings as the specified Map . |
Method Summary | |
---|---|
protected void |
access(int key)
Marks the given key as most recently used. |
void |
clear()
Removes all mappings from this map. |
java.lang.Object |
clone()
Returns a shallow copy of this IntMap instance:
the values themselves are not cloned. |
void |
compact()
Rehashes the data structure to be more compact (and fast - if remove(int) operations were performed before). |
T |
get(int key)
Returns the value to which this map maps the specified key. |
T |
put(int key,
T value)
Associates the specified value with the specified key in this map If the map previously contained a mapping for this key, the old value is replaced by the specified value (a returned back). |
T |
remove(int key)
Removes the mapping for this key from this map if it is present Returns the value to which the map previously associated the key, or null if the map contained no mapping for this key. |
void |
setCacheCapacity(int cacheCap)
Sets a new cache capacity. |
Methods inherited from class cz.cuni.jagrlib.IntMap |
---|
containsKey, containsValue, find, isEmpty, iterator, keySet, putAll, readObject, rehash, size, tupleIterator, values, writeObject |
Methods inherited from class java.util.AbstractCollection |
---|
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
equals, hashCode |
Field Detail |
---|
protected final int HEAD_KEY
protected LRUCache.LRUItem head
protected int cacheCapacity
protected LRUCache.LRUItem recycled
Constructor Detail |
---|
public LRUCache()
0.6
).
public LRUCache(int capacity)
0.6
).
public LRUCache(int capacity, float loadFactor)
public LRUCache(java.util.Map<? extends java.lang.Integer,? extends T> m)
Map
.
The IntMap
is created with default load factor (0.6)
and an initial capacity sufficient to hold the mappings
in the specified Map
.
m
- the map whose mappings are to be placed in this map.Method Detail |
---|
protected final void access(int key)
public void setCacheCapacity(int cacheCap)
public T get(int key)
put( key, x )
was called) and mapping with null
value (put( key, null )
was called).
The containsKey
predicate can be used to
distinguish these two cases.
get
in class IntMap<T>
key
- Key whose associated value is to be returned.
null
if the map contains no mapping for this key.IntMap.containsKey(int)
public T put(int key, T value)
put
in class IntMap<T>
key
- Key with which the specified value is to be associated.value
- Value to be associated with the specified key.
null
if there was no mapping for key. A null
return can
also indicate that the map previously associated null
with the specified key.public T remove(int key)
Returns the value to which the map previously associated the key, or
null
if the map contained no mapping for this key. (A
null
return can also indicate that the map previously
associated null
with the specified key).
The map will not contain a mapping for the specified key once
the call returns.
remove
in class IntMap<T>
key
- Key whose mapping is to be removed from the map.
null
if there was no mapping for key.public final void clear()
clear
in interface java.util.Collection<T>
clear
in class IntMap<T>
public void compact()
remove(int)
operations were performed before).
compact
in class IntMap<T>
public java.lang.Object clone()
IntMap
instance:
the values themselves are not cloned.
clone
in class IntMap<T>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |