Skip to content

Commit

Permalink
better and more performant synchronization in SimpleARC, the caching …
Browse files Browse the repository at this point in the history
…object for word hashes. Speeds up indexing.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5925 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed May 5, 2009
1 parent e6773cb commit 71a4cad
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions source/de/anomic/kelondro/index/SimpleARC.java
Expand Up @@ -24,6 +24,7 @@

package de.anomic.kelondro.index;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

Expand All @@ -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;
}
};
});
}

/**
Expand All @@ -64,7 +65,7 @@ public SimpleARC(int cacheSize) {
* @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);
Expand All @@ -76,7 +77,7 @@ public synchronized void put(K s, V 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);
Expand All @@ -91,7 +92,7 @@ public synchronized V get(K s) {
/**
* clear the cache
*/
public synchronized void clear() {
public void clear() {
this.levelA.clear();
this.levelB.clear();
}
Expand Down

0 comments on commit 71a4cad

Please sign in to comment.