better and more performant synchronization in SimpleARC, the caching object for word hashes. Speeds up indexing.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5925 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent e6773cbb33
commit 71a4cadf31

@ -24,6 +24,7 @@
package de.anomic.kelondro.index;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@ -40,22 +41,22 @@ public class SimpleARC <K, V> {
public final static boolean accessOrder = false; // if false, then a insertion-order is used
private int cacheSize;
private LinkedHashMap<K, V> levelA, levelB;
private Map<K, V> levelA, levelB;
public SimpleARC(int cacheSize) {
this.cacheSize = cacheSize / 2;
this.levelA = new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) {
this.levelA = Collections.synchronizedMap(new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) {
private static final long serialVersionUID = 1L;
@Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > SimpleARC.this.cacheSize;
}
};
this.levelB = new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) {
});
this.levelB = Collections.synchronizedMap(new LinkedHashMap<K, V>(cacheSize, 0.1f, accessOrder) {
private static final long serialVersionUID = 1L;
@Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
return size() > SimpleARC.this.cacheSize;
}
};
});
}
/**
@ -64,7 +65,7 @@ public class SimpleARC <K, V> {
* @param s
* @param v
*/
public synchronized void put(K s, V v) {
public void put(K s, V v) {
assert this.levelA.get(s) == null;
assert this.levelB.get(s) == null;
this.levelA.put(s, v);
@ -76,7 +77,7 @@ public class SimpleARC <K, V> {
* @param s
* @return the value
*/
public synchronized V get(K s) {
public V get(K s) {
V v = this.levelB.get(s);
if (v != null) return v;
v = this.levelA.remove(s);
@ -91,7 +92,7 @@ public class SimpleARC <K, V> {
/**
* clear the cache
*/
public synchronized void clear() {
public void clear() {
this.levelA.clear();
this.levelB.clear();
}

Loading…
Cancel
Save