K
- Type of the Cache KeyV
- Type of the Cache Elementspublic class LRUCache<K,V>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
capacity |
private java.util.LinkedHashMap<K,V> |
map |
Constructor and Description |
---|
LRUCache(int capacity)
Consructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(K key) |
V |
evict()
Evicts the least recently used element
|
V |
get(K key)
Gets Element corresponding to key
|
java.util.Iterator<K> |
keySet() |
void |
put(K key,
V value)
Puts element into the cache
|
void |
remove(K key)
Removes element with given key
|
int |
size() |
java.util.Iterator<V> |
values() |
public LRUCache(int capacity)
capacity
- The maximum size of this Cachepublic boolean containsKey(K key)
key
- public V evict()
public void put(K key, V value)
key
- Key of the elementvalue
- The elementpublic int size()
public java.util.Iterator<K> keySet()
public java.util.Iterator<V> values()
public void remove(K key)
key
- The key of element to be removed