void afterNodeAccess(Node<K,V> e) { // move node to last
LinkedHashMap.Entry<K,V> last;
if (accessOrder && (last = tail) != e) {
LinkedHashMap.Entry<K,V> p =
(LinkedHashMap.Entry<K,V>)e, b = p.before, a = p.after;
p.after = null;
if (b == null)
head = a;
else
b.after = a;
if (a != null)
a.before = b;
else
last = b;
if (last == null)
head = p;
else {
p.before = last;
last.after = p;
}
tail = p;
++modCount;
}
}
void afterNodeInsertion(boolean evict) { // possibly remove eldest
LinkedHashMap.Entry<K,V> first;
if (evict && (first = head) != null && removeEldestEntry(first)) {
K key = first.key;
removeNode(hash(key), key, null, false, true);
}
}
@Override
public boolean removeEldestEntry(Map.Entry<K, V> eldest){
return size()>capacity;
}
import java.util.Set;
import com.googlecode.concurrentlinkedhashmap.Weighers;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
public class ConcurrentLRUCache<K, V> {
public static final int DEFAULT_CONCURENCY_LEVEL = 32;
private final ConcurrentLinkedHashMap<K, V> map;
public ConcurrentLRUCache(int capacity) {
this(capacity, DEFAULT_CONCURENCY_LEVEL);
}
public ConcurrentLRUCache(int capacity, int concurrency) {
map = new ConcurrentLinkedHashMap.Builder<K, V>().weigher(Weighers.<V> singleton())
.initialCapacity(capacity).maximumWeightedCapacity(capacity)
.concurrencyLevel(concurrency).build();
}
public void put(K key, V value) {
map.put(key, value);
}
public V get(K key) {
V v = map.get(key);
return v;
}
public V getInternal(K key) {
return map.get(key);
}
public void remove(K key) {
map.remove(key);
}
public long getCapacity() {
return map.capacity();
}
public void updateCapacity(int capacity) {
map.setCapacity(capacity);
}
public int getSize() {
return map.size();
}
public void clear() {
map.clear();
}
public Set<K> getKeySet() {
return map.keySet();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有