* LHMCache: New util, replacing several private versions

This commit is contained in:
zzz
2012-09-03 15:33:12 +00:00
parent c965a3dca0
commit 8575437626
6 changed files with 34 additions and 68 deletions

View File

@ -14,7 +14,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -24,6 +23,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.data.SimpleDataStructure;
import net.i2p.util.LHMCache;
import net.i2p.util.Log;
/**
@ -658,7 +658,7 @@ public class KBucketSet<T extends SimpleDataStructure> {
public Range(T us, int bValue) {
_bValue = bValue;
_bigUs = new BigInteger(1, us.getData());
_distanceCache = new LHM(256);
_distanceCache = new LHMCache(256);
}
/** @return 0 to max-1 or -1 for us */
@ -697,20 +697,6 @@ public class KBucketSet<T extends SimpleDataStructure> {
}
}
private static class LHM<K, V> extends LinkedHashMap<K, V> {
private final int _max;
public LHM(int max) {
super(max, 0.75f, true);
_max = max;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > _max;
}
}
/**
* For Collections.binarySearch.
* getRangeBegin == getRangeEnd.