replaced HashARC with SizeLimited Objects which are less costly

pull/1/head
orbiter 13 years ago
parent d4291ac1f3
commit 7f851d62a7

@ -365,7 +365,7 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
}
// resolve '..'
public static final String resolveBackpath(final String path) {
private static final String resolveBackpath(final String path) {
String p = path;
if (p.length() == 0 || p.charAt(0) != '/') { p = "/" + p; }
final Matcher qm = patternQuestion.matcher(p); // do not resolve backpaths in the post values

@ -0,0 +1,40 @@
/**
* SizeLimitedMap
* Copyright 2012 by Michael Peter Christen, mc@yacy.net, Frankfurt a. M., Germany
* First released 04.07.2012 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.storage;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
public class SizeLimitedMap<K, V> extends LinkedHashMap<K, V> implements Map<K, V>, Cloneable, Serializable {
private static final long serialVersionUID = 6088727126150060068L;
final int sizeLimit;
public SizeLimitedMap(int sizeLimit) {
this.sizeLimit = sizeLimit;
}
@Override protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return size() > this.sizeLimit;
}
}

@ -0,0 +1,80 @@
/**
* SizeLimitedSet
* Copyright 2012 by Michael Peter Christen, mc@yacy.net, Frankfurt a. M., Germany
* First released 04.07.2012 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.cora.storage;
import java.io.Serializable;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Set;
public class SizeLimitedSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, Serializable {
private static final long serialVersionUID = -1674392695322189500L;
private transient SizeLimitedMap<E,Object> map;
private static final Object OBJECT = new Object();
public SizeLimitedSet(int sizeLimit) {
map = new SizeLimitedMap<E,Object>(sizeLimit);
}
public Iterator<E> iterator() {
return map.keySet().iterator();
}
public int size() {
return map.size();
}
public boolean isEmpty() {
return map.isEmpty();
}
public boolean contains(Object o) {
return map.containsKey(o);
}
public boolean add(E e) {
return map.put(e, OBJECT) == null;
}
public boolean remove(Object o) {
return map.remove(o) == OBJECT;
}
public void clear() {
map.clear();
}
@SuppressWarnings("unchecked")
public Object clone() {
try {
SizeLimitedSet<E> n = (SizeLimitedSet<E>) super.clone();
n.map = (SizeLimitedMap<E, Object>) map.clone();
return n;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
}
}

@ -46,7 +46,8 @@ import javax.swing.event.EventListenerList;
import net.yacy.cora.document.MultiProtocolURI;
import net.yacy.cora.sorting.ClusteredScoreMap;
import net.yacy.cora.storage.HashARC;
import net.yacy.cora.storage.SizeLimitedMap;
import net.yacy.cora.storage.SizeLimitedSet;
import net.yacy.cora.util.NumberTools;
import net.yacy.document.SentenceReader;
import net.yacy.document.parser.htmlParser;
@ -158,14 +159,14 @@ public class ContentScraper extends AbstractScraper implements Scraper {
this.root = root;
this.maxLinks = maxLinks;
this.evaluationScores = new Evaluation();
this.rss = new HashARC<MultiProtocolURI, String>(maxLinks);
this.css = new HashARC<MultiProtocolURI, String>(maxLinks);
this.anchors = new HashARC<MultiProtocolURI, Properties>(maxLinks);
this.images = new HashARC<MultiProtocolURI, ImageEntry>(maxLinks);
this.embeds = new HashARC<MultiProtocolURI, EmbedEntry>(maxLinks);
this.frames = new HashSet<MultiProtocolURI>();
this.iframes = new HashSet<MultiProtocolURI>();
this.metas = new HashARC<String, String>(maxLinks);
this.rss = new SizeLimitedMap<MultiProtocolURI, String>(maxLinks);
this.css = new SizeLimitedMap<MultiProtocolURI, String>(maxLinks);
this.anchors = new SizeLimitedMap<MultiProtocolURI, Properties>(maxLinks);
this.images = new SizeLimitedMap<MultiProtocolURI, ImageEntry>(maxLinks);
this.embeds = new SizeLimitedMap<MultiProtocolURI, EmbedEntry>(maxLinks);
this.frames = new SizeLimitedSet<MultiProtocolURI>(maxLinks);
this.iframes = new SizeLimitedSet<MultiProtocolURI>(maxLinks);
this.metas = new SizeLimitedMap<String, String>(maxLinks);
this.script = new HashSet<MultiProtocolURI>();
this.title = EMPTY_STRING;
this.headlines = new ArrayList[6];

Loading…
Cancel
Save