Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

continuing String-hash - to - byte[]-hash redesign that was started in SVN 6775 and continued in SVN 6790 The result should be a less usage of new String() and less memory usage (since a String-encapsulated byte[] has 40 bytes overhead)

orbiter1a8a134e0c03
diff --git a/htroot/CrawlResults.java b/htroot/CrawlResults.java
index 97b7477ce..f3c3f2f75 100644
--- a/htroot/CrawlResults.java
+++ b/htroot/CrawlResults.java
@@ -197,8 +197,8 @@ public class CrawlResults {
urlstr = metadata.url().toNormalform(false, true);
urltxt = nxTools.shortenURLString(urlstr, 72); // shorten the string text like a URL
}
- initiatorSeed = sb.peers.getConnected(new String(entry.getValue().initiatorHashb));
- executorSeed = sb.peers.getConnected(new String(entry.getValue().executorHashb));
+ initiatorSeed = sb.peers.getConnected(new String(entry.getValue().initiatorHash));
+ executorSeed = sb.peers.getConnected(new String(entry.getValue().executorHash));
prop.put("table_indexed_" + cnt + "_dark", (dark) ? "1" : "0");
prop.put("table_indexed_" + cnt + "_feedbackpage", "CrawlResults.html");
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.java
index e1d1c00ae..9b576b8d1 100644
--- a/htroot/IndexControlRWIs_p.java
+++ b/htroot/IndexControlRWIs_p.java
@@ -30,11 +30,9 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
+import java.util.TreeMap;
import net.yacy.document.Condenser;
import net.yacy.kelondro.data.meta.DigestURI;
@@ -42,8 +40,10 @@ import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.data.word.WordReferenceRow;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
+import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.rwi.ReferenceContainer;
@@ -114,7 +114,9 @@ public class IndexControlRWIs_p {
prop.putHTML("keyhash", new String(keyhash));
// read values from checkboxes
- String[] urlx = post.getAll("urlhx.*");
+ String[] urls = post.getAll("urlhx.*");
+ HandleSet urlb = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, urls.length);
+ if (urls != null) for (String s: urls) try { urlb.put(s.getBytes()); } catch (RowSpaceExceededException e) { Log.logException(e); }
final boolean delurl = post.containsKey("delurl");
final boolean delurlref = post.containsKey("delurlref");
@@ -155,23 +157,18 @@ public class IndexControlRWIs_p {
ReferenceContainer<WordReference> index = null;
index = segment.termIndex().get(keyhash, null);
final Iterator<WordReference> en = index.entries();
- i = 0;
- urlx = new String[index.size()];
- while (en.hasNext()) {
- urlx[i++] = en.next().metadataHash();
- }
+ urlb = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, index.size());
+ while (en.hasNext()) try { urlb.put(en.next().metadataHash()); } catch (RowSpaceExceededException e) { Log.logException(e); }
index = null;
}
if (delurlref) {
- for (i = 0; i < urlx.length; i++) segment.removeAllUrlReferences(urlx[i].getBytes(), sb.loader, true);
+ segment.removeAllUrlReferences(urlb, sb.loader, true);
}
// delete the word first because that is much faster than the deletion of the urls from the url database
segment.termIndex().delete(keyhash);
// now delete all urls if demanded
if (delurl || delurlref) {
- for (i = 0; i < urlx.length; i++) {
- sb.urlRemove(segment, urlx[i].getBytes());
- }
+ for (byte[] b: urlb) sb.urlRemove(segment, b);
}
post.remove("keyhashdeleteall");
post.put("urllist", "generated");
@@ -182,15 +179,13 @@ public class IndexControlRWIs_p {
// delete selected URLs
if (post.containsKey("keyhashdelete")) try {
if (delurlref) {
- for (i = 0; i < urlx.length; i++) segment.removeAllUrlReferences(urlx[i].getBytes(), sb.loader, true);
+ segment.removeAllUrlReferences(urlb, sb.loader, true);
}
if (delurl || delurlref) {
- for (i = 0; i < urlx.length; i++) {
- sb.urlRemove(segment, urlx[i].getBytes());
- }
+ for (byte[] b: urlb) sb.urlRemove(segment, b);
}
- final Set<String> urlHashes = new HashSet<String>();
- for (i = 0; i < urlx.length; i++) urlHashes.add(urlx[i]);
+ final HandleSet urlHashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
+ for (byte[] b: urlb) try { urlHashes.put(b); } catch (RowSpaceExceededException e) { Log.logException(e); }
segment.termIndex().remove(keyhash, urlHashes);
// this shall lead to a presentation of the list; so handle that the remaining program
// thinks that it was called for a list presentation
@@ -238,15 +233,19 @@ public class IndexControlRWIs_p {
index = segment.termIndex().get(keyhash, null);
// built urlCache
final Iterator<WordReference> urlIter = index.entries();
- final HashMap<String, URIMetadataRow> knownURLs = new HashMap<String, URIMetadataRow>();
- final HashSet<String> unknownURLEntries = new HashSet<String>();
+ final TreeMap<byte[], URIMetadataRow> knownURLs = new TreeMap<byte[], URIMetadataRow>(Base64Order.enhancedCoder);
+ final HandleSet unknownURLEntries = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, index.size());
Reference iEntry;
URIMetadataRow lurl;
while (urlIter.hasNext()) {
iEntry = urlIter.next();
- lurl = segment.urlMetadata().load(iEntry.metadataHash().getBytes(), null, 0);
+ lurl = segment.urlMetadata().load(iEntry.metadataHash(), null, 0);
if (lurl == null) {
- unknownURLEntries.add(iEntry.metadataHash());
+ try {
+ unknownURLEntries.put(iEntry.metadataHash());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
urlIter.remove();
} else {
knownURLs.put(iEntry.metadataHash(), lurl);
@@ -270,7 +269,7 @@ public class IndexControlRWIs_p {
knownURLs,
"true".equalsIgnoreCase(gzipBody),
timeout);
- prop.put("result", (error == null) ? ("Successfully transferred " + knownURLs.size() + " words in " + ((System.currentTimeMillis() - starttime) / 1000) + " seconds, " + unknownURLEntries + " URL not found") : "error: " + error);
+ prop.put("result", (error == null) ? ("Successfully transferred " + knownURLs.size() + " words in " + ((System.currentTimeMillis() - starttime) / 1000) + " seconds, " + unknownURLEntries.size() + " URL not found") : "error: " + error);
index = null;
} catch (IOException e) {
Log.logException(e);
@@ -303,17 +302,21 @@ public class IndexControlRWIs_p {
if (post.containsKey("blacklist")) {
final String blacklist = post.get("blacklist", "");
- final Set<String> urlHashes = new HashSet<String>();
+ final HandleSet urlHashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, urlb.size());
if (post.containsKey("blacklisturls")) {
PrintWriter pw;
try {
final String[] supportedBlacklistTypes = env.getConfig("BlackLists.types", "").split(",");
pw = new PrintWriter(new FileWriter(new File(listManager.listsPath, blacklist), true));
DigestURI url;
- for (i = 0; i < urlx.length; i++) {
- urlHashes.add(urlx[i]);
- final URIMetadataRow e = segment.urlMetadata().load(urlx[i].getBytes(), null, 0);
- segment.urlMetadata().remove(urlx[i].getBytes());
+ for (byte[] b: urlb) {
+ try {
+ urlHashes.put(b);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
+ final URIMetadataRow e = segment.urlMetadata().load(b, null, 0);
+ segment.urlMetadata().remove(b);
if (e != null) {
url = e.metadata().url();
pw.println(url.getHost() + "/" + url.getFile());
@@ -339,10 +342,14 @@ public class IndexControlRWIs_p {
final String[] supportedBlacklistTypes = Blacklist.BLACKLIST_TYPES_STRING.split(",");
pw = new PrintWriter(new FileWriter(new File(listManager.listsPath, blacklist), true));
DigestURI url;
- for (i = 0; i<urlx.length; i++) {
- urlHashes.add(urlx[i]);
- final URIMetadataRow e = segment.urlMetadata().load(urlx[i].getBytes(), null, 0);
- segment.urlMetadata().remove(urlx[i].getBytes());
+ for (byte[] b: urlb) {
+ try {
+ urlHashes.put(b);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
+ final URIMetadataRow e = segment.urlMetadata().load(b, null, 0);
+ segment.urlMetadata().remove(b);
if (e != null) {
url = e.metadata().url();
pw.println(url.getHost() + "/.*");
@@ -437,7 +444,7 @@ public class IndexControlRWIs_p {
((entry.word().flags().get(WordReferenceRow.flag_app_dc_subject)) ? "appears in subject, " : "") +
((entry.word().flags().get(WordReferenceRow.flag_app_dc_description)) ? "appears in description, " : "") +
((entry.word().flags().get(WordReferenceRow.flag_app_emphasized)) ? "appears emphasized, " : "") +
- ((DigestURI.probablyRootURL(entry.word().metadataHash().getBytes())) ? "probably root url" : "")
+ ((DigestURI.probablyRootURL(entry.word().metadataHash())) ? "probably root url" : "")
);
if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_DHT, url)) {
prop.put("genUrlList_urlList_"+i+"_urlExists_urlhxChecked", "1");
@@ -445,12 +452,13 @@ public class IndexControlRWIs_p {
i++;
if ((maxlines >= 0) && (i >= maxlines)) break;
}
- final Iterator<String> iter = ranked.miss(); // iterates url hash strings
+ final Iterator<byte[]> iter = ranked.miss(); // iterates url hash strings
+ byte[] b;
while (iter.hasNext()) {
- us = iter.next();
- prop.put("genUrlList_urlList_"+i+"_urlExists", "0");
- prop.put("genUrlList_urlList_"+i+"_urlExists_urlhxCount", i);
- prop.putHTML("genUrlList_urlList_"+i+"_urlExists_urlhxValue", us);
+ b = iter.next();
+ prop.put("genUrlList_urlList_" + i + "_urlExists", "0");
+ prop.put("genUrlList_urlList_" + i + "_urlExists_urlhxCount", i);
+ prop.putHTML("genUrlList_urlList_" + i + "_urlExists_urlhxValue", b);
i++;
}
prop.put("genUrlList_urlList", i);
diff --git a/htroot/RSSLoader_p.java b/htroot/RSSLoader_p.java
index 0b673500f..4e8d473e7 100644
--- a/htroot/RSSLoader_p.java
+++ b/htroot/RSSLoader_p.java
@@ -26,8 +26,6 @@
//if the shell's current path is HTROOT
import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Map;
@@ -35,12 +33,9 @@ import net.yacy.document.Document;
import net.yacy.document.ParserException;
import net.yacy.document.parser.rssParser;
import net.yacy.kelondro.data.meta.DigestURI;
-import net.yacy.kelondro.logging.Log;
import de.anomic.crawler.retrieval.Response;
-import de.anomic.http.client.Cache;
import de.anomic.http.server.RequestHeader;
-import de.anomic.http.server.ResponseHeader;
import de.anomic.search.Segment;
import de.anomic.search.Segments;
import de.anomic.search.Switchboard;
diff --git a/htroot/api/timeline.java b/htroot/api/timeline.java
index cd83c520a..87c7ad96c 100644
--- a/htroot/api/timeline.java
+++ b/htroot/api/timeline.java
@@ -30,6 +30,7 @@ import java.util.TreeSet;
import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReference;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.rwi.ReferenceContainer;
@@ -75,7 +76,7 @@ public final class timeline {
if (language == null) language = "en";
}
final TreeSet<String>[] query = QueryParams.cleanQuery(querystring); // converts also umlaute
- TreeSet<byte[]> q = Word.words2hashes(query[0]);
+ HandleSet q = Word.words2hashesHandles(query[0]);
// tell all threads to do nothing for a specific time
sb.intermissionAllThreads(3000);
@@ -93,7 +94,7 @@ public final class timeline {
// get the index container with the result vector
TermSearch<WordReference> search = null;
try {
- search = segment.termIndex().query(q, Word.words2hashes(query[1]), null, Segment.wordReferenceFactory, maxdist);
+ search = segment.termIndex().query(q, Word.words2hashesHandles(query[1]), null, Segment.wordReferenceFactory, maxdist);
} catch (RowSpaceExceededException e) {
Log.logException(e);
}
diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java
index 850e72849..d026e24a8 100644
--- a/htroot/yacy/search.java
+++ b/htroot/yacy/search.java
@@ -39,7 +39,8 @@ import net.yacy.document.content.RSSMessage;
import net.yacy.document.parser.xml.RSSFeed;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.word.WordReference;
-import net.yacy.kelondro.order.Base64Order;
+import net.yacy.kelondro.data.word.WordReferenceRow;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.util.EventTracker;
@@ -164,7 +165,7 @@ public final class search {
// tell all threads to do nothing for a specific time
sb.intermissionAllThreads(3000);
- final TreeSet<byte[]> abstractSet = ((abstracts.length() == 0) || (abstracts.equals("auto"))) ? null : QueryParams.hashes2Set(abstracts);
+ final HandleSet abstractSet = ((abstracts.length() == 0) || (abstracts.equals("auto"))) ? null : QueryParams.hashes2Set(abstracts);
// store accessing peer
final yacySeed remoteSeed = yacySeed.genRemoteSeed(oseed, key, false);
@@ -175,8 +176,8 @@ public final class search {
}
// prepare search
- final TreeSet<byte[]> queryhashes = QueryParams.hashes2Set(query);
- final TreeSet<byte[]> excludehashes = (exclude.length() == 0) ? new TreeSet<byte[]>(Base64Order.enhancedCoder) : QueryParams.hashes2Set(exclude);
+ final HandleSet queryhashes = QueryParams.hashes2Set(query);
+ final HandleSet excludehashes = (exclude.length() == 0) ? new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0) : QueryParams.hashes2Set(exclude);
final long timestamp = System.currentTimeMillis();
// prepare a search profile
@@ -195,7 +196,7 @@ public final class search {
theQuery = new QueryParams(
null,
abstractSet,
- new TreeSet<byte[]>(Base64Order.enhancedCoder),
+ new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0),
null,
null,
maxdist,
@@ -223,7 +224,7 @@ public final class search {
final long timer = System.currentTimeMillis();
//final Map<byte[], ReferenceContainer<WordReference>>[] containers = sb.indexSegment.index().searchTerm(theQuery.queryHashes, theQuery.excludeHashes, plasmaSearchQuery.hashes2StringSet(urls));
- final HashMap<byte[], ReferenceContainer<WordReference>> incc = indexSegment.termIndex().searchConjunction(theQuery.queryHashes, QueryParams.hashes2StringSet(urls));
+ final HashMap<byte[], ReferenceContainer<WordReference>> incc = indexSegment.termIndex().searchConjunction(theQuery.queryHashes, QueryParams.hashes2Handles(urls));
EventTracker.update("SEARCH", new ProfilingGraph.searchEvent(theQuery.id(true), SearchEvent.COLLECTION, incc.size(), System.currentTimeMillis() - timer), false, 30000, ProfilingGraph.maxTime);
if (incc != null) {
diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.java
index d2927ecc0..341c876d6 100644
--- a/htroot/yacy/transferRWI.java
+++ b/htroot/yacy/transferRWI.java
@@ -28,12 +28,13 @@
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.Iterator;
import net.yacy.document.content.RSSMessage;
import net.yacy.document.parser.xml.RSSFeed;
+import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.WordReferenceRow;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.repository.Blacklist;
@@ -140,10 +141,10 @@ public final class transferRWI {
String estring;
int p;
String wordHash;
- String urlHash;
+ byte[] urlHash;
WordReferenceRow iEntry;
- final HashSet<String> unknownURL = new HashSet<String>();
- final HashSet<String> knownURL = new HashSet<String>();
+ final HandleSet unknownURL = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
+ final HandleSet knownURL = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
final ArrayList<String> wordhashes = new ArrayList<String>();
int received = 0;
int blocked = 0;
@@ -165,7 +166,7 @@ public final class transferRWI {
// block blacklisted entries
if ((blockBlacklist) && (Switchboard.urlBlacklist.hashInBlacklistedCache(Blacklist.BLACKLIST_DHT, urlHash))) {
- if (yacyCore.log.isFine()) yacyCore.log.logFine("transferRWI: blocked blacklisted URLHash '" + urlHash + "' from peer " + otherPeerName);
+ if (yacyCore.log.isFine()) yacyCore.log.logFine("transferRWI: blocked blacklisted URLHash '" + new String(urlHash) + "' from peer " + otherPeerName);
blocked++;
continue;
}
@@ -173,7 +174,7 @@ public final class transferRWI {
// check if the entry is in our network domain
final String urlRejectReason = sb.crawlStacker.urlInAcceptedDomainHash(urlHash);
if (urlRejectReason != null) {
- yacyCore.log.logWarning("transferRWI: blocked URL hash '" + urlHash + "' (" + urlRejectReason + ") from peer " + otherPeerName + "; peer is suspected to be a spam-peer (or something is wrong)");
+ yacyCore.log.logWarning("transferRWI: blocked URL hash '" + new String(urlHash) + "' (" + urlRejectReason + ") from peer " + otherPeerName + "; peer is suspected to be a spam-peer (or something is wrong)");
//if (yacyCore.log.isFine()) yacyCore.log.logFine("transferRWI: blocked URL hash '" + urlHash + "' (" + urlRejectReason + ") from peer " + otherPeerName);
blocked++;
continue;
@@ -188,27 +189,27 @@ public final class transferRWI {
serverCore.checkInterruption();
// check if we need to ask for the corresponding URL
- if (!(knownURL.contains(urlHash)||unknownURL.contains(urlHash))) try {
- if (sb.indexSegments.urlMetadata(Segments.Process.DHTIN).exists(urlHash.getBytes())) {
- knownURL.add(urlHash);
+ if (!(knownURL.has(urlHash) || unknownURL.has(urlHash))) try {
+ if (sb.indexSegments.urlMetadata(Segments.Process.DHTIN).exists(urlHash)) {
+ knownURL.put(urlHash);
} else {
- unknownURL.add(urlHash);
+ unknownURL.put(urlHash);
}
receivedURL++;
} catch (final Exception ex) {
sb.getLog().logWarning(
"transferRWI: DB-Error while trying to determine if URL with hash '" +
- urlHash + "' is known.", ex);
+ new String(urlHash) + "' is known.", ex);
}
received++;
}
sb.peers.mySeed().incRI(received);
// finally compose the unknownURL hash list
- it = unknownURL.iterator();
+ Iterator<byte[]> bit = unknownURL.iterator();
unknownURLs.ensureCapacity(unknownURL.size() * 25);
- while (it.hasNext()) {
- unknownURLs.append(",").append(it.next());
+ while (bit.hasNext()) {
+ unknownURLs.append(",").append(new String(bit.next()));
}
if (unknownURLs.length() > 0) { unknownURLs.delete(0, 1); }
if (wordhashes.isEmpty() || received == 0) {
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 011d492fd..d0a6260a5 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -41,6 +41,7 @@ import net.yacy.document.parser.xml.RSSFeed;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.Word;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.util.Domains;
@@ -406,7 +407,7 @@ public class yacysearch {
// delete the index entry locally
final String delHash = post.get("deleteref", ""); // urlhash
- indexSegment.termIndex().remove(Word.words2hashes(query[0]), delHash.getBytes());
+ indexSegment.termIndex().remove(Word.words2hashesHandles(query[0]), delHash.getBytes());
// make new news message with negative voting
final HashMap<String, String> map = new HashMap<String, String>();
@@ -449,12 +450,12 @@ public class yacysearch {
final boolean globalsearch = (global) && indexReceiveGranted; /* && (yacyonline)*/
// do the search
- final TreeSet<byte[]> queryHashes = Word.words2hashes(query[0]);
+ final HandleSet queryHashes = Word.words2hashesHandles(query[0]);
final QueryParams theQuery = new QueryParams(
originalquerystring,
queryHashes,
- Word.words2hashes(query[1]),
- Word.words2hashes(query[2]),
+ Word.words2hashesHandles(query[1]),
+ Word.words2hashesHandles(query[2]),
tenant,
maxDistance,
prefermask,
diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java
index 68f8a868f..b7ac00dd9 100644
--- a/htroot/yacysearchitem.java
+++ b/htroot/yacysearchitem.java
@@ -145,9 +145,6 @@ public class yacysearchitem {
prop.putHTML("content_words", URLEncoder.encode(query[0].toString(),"UTF-8"));
} catch (final UnsupportedEncodingException e) {}
prop.putHTML("content_former", theQuery.queryString);
- prop.put("content_rankingprops", result.word().toPropertyForm() + ", domLengthEstimated=" + DigestURI.domLengthEstimation(result.hash()) +
- ((DigestURI.probablyRootURL(result.hash())) ? ", probablyRootURL" : "") +
- (((wordURL = DigestURI.probablyWordURL(result.hash(), query[0])) != null) ? ", probablyWordURL=" + wordURL.toNormalform(false, true) : ""));
final TextSnippet snippet = result.textSnippet();
final String desc = (snippet == null) ? "" : snippet.getLineMarked(theQuery.fullqueryHashes);
prop.put("content_description", desc);
diff --git a/source/de/anomic/crawler/AbstractImporter.java b/source/de/anomic/crawler/AbstractImporter.java
index a0c96c6c7..16f7f2a53 100644
--- a/source/de/anomic/crawler/AbstractImporter.java
+++ b/source/de/anomic/crawler/AbstractImporter.java
@@ -4,16 +4,16 @@ import net.yacy.kelondro.logging.Log;
public abstract class AbstractImporter extends Thread implements Importer {
- protected int jobID = -1;
- protected String jobType;
- protected Log log;
- protected boolean stopped = false;
- protected boolean paused = false;
- protected long globalStart = System.currentTimeMillis();
+ private int jobID = -1;
+ private String jobType;
+ private Log log;
+ private boolean stopped = false;
+ private boolean paused = false;
+ private long globalStart = System.currentTimeMillis();
protected long globalEnd;
- protected long globalPauseLast;
- protected long globalPauseDuration;
- protected String error;
+ private long globalPauseLast;
+ private long globalPauseDuration;
+ private String error;
public AbstractImporter(final String theJobType) {
this.jobType = theJobType;
diff --git a/source/de/anomic/crawler/Balancer.java b/source/de/anomic/crawler/Balancer.java
index e656d60d2..e2aedb241 100644
--- a/source/de/anomic/crawler/Balancer.java
+++ b/source/de/anomic/crawler/Balancer.java
@@ -52,14 +52,14 @@ public class Balancer {
// class variables
private final ConcurrentHashMap<String, LinkedList<byte[]>> domainStacks; // a map from domain name part to Lists with url hashs
- private final ConcurrentLinkedQueue<byte[]> top;
- private final TreeMap<Long, byte[]> delayed;
- protected ObjectIndex urlFileIndex;
- private final File cacheStacksPath;
- private long minimumLocalDelta;
- private long minimumGlobalDelta;
- private long lastDomainStackFill;
- private int domStackInitSize;
+ private final ConcurrentLinkedQueue<byte[]> top;
+ private final TreeMap<Long, byte[]> delayed;
+ private ObjectIndex urlFileIndex;
+ private final File cacheStacksPath;
+ private long minimumLocalDelta;
+ private long minimumGlobalDelta;
+ private long lastDomainStackFill;
+ private int domStackInitSize;
public Balancer(
final File cachePath,
@@ -339,29 +339,29 @@ public class Balancer {
long sleeptime = 0;
Request crawlEntry = null;
synchronized (this) {
- byte[] failhashb = null;
+ byte[] failhash = null;
while (!this.urlFileIndex.isEmpty()) {
// first simply take one of the entries in the top list, that should be one without any delay
- byte[] nexthashb = nextFromDelayed();
+ byte[] nexthash = nextFromDelayed();
//System.out.println("*** nextFromDelayed=" + nexthash);
- if (nexthashb == null && !this.top.isEmpty()) {
- nexthashb = top.remove();
+ if (nexthash == null && !this.top.isEmpty()) {
+ nexthash = top.remove();
//System.out.println("*** top.remove()=" + nexthash);
}
- if (nexthashb == null) {
- nexthashb = anyFromDelayed();
+ if (nexthash == null) {
+ nexthash = anyFromDelayed();
}
// check minimumDelta and if necessary force a sleep
//final int s = urlFileIndex.size();
- Row.Entry rowEntry = (nexthashb == null) ? null : urlFileIndex.remove(nexthashb);
+ Row.Entry rowEntry = (nexthash == null) ? null : urlFileIndex.remove(nexthash);
if (rowEntry == null) {
//System.out.println("*** rowEntry=null, nexthash=" + nexthash);
rowEntry = urlFileIndex.removeOne();
if (rowEntry == null) {
- nexthashb = null;
+ nexthash = null;
} else {
- nexthashb = rowEntry.getPrimaryKeyBytes();
+ nexthash = rowEntry.getPrimaryKeyBytes();
//System.out.println("*** rowEntry.getPrimaryKeyBytes()=" + nexthash);
}
@@ -388,22 +388,22 @@ public class Balancer {
(profileEntry.cacheStrategy() == CrawlProfile.CACHE_STRATEGY_IFEXIST && Cache.has(crawlEntry.url()))
) ? 0 : Latency.waitingRemaining(crawlEntry.url(), minimumLocalDelta, minimumGlobalDelta); // this uses the robots.txt database and may cause a loading of robots.txt from the server
- assert Base64Order.enhancedCoder.equal(nexthashb, rowEntry.getPrimaryKeyBytes()) : "result = " + new String(nexthashb) + ", rowEntry.getPrimaryKeyBytes() = " + new String(rowEntry.getPrimaryKeyBytes());
- assert Base64Order.enhancedCoder.equal(nexthashb, crawlEntry.url().hash()) : "result = " + new String(nexthashb) + ", crawlEntry.url().hash() = " + new String(crawlEntry.url().hash());
+ assert Base64Order.enhancedCoder.equal(nexthash, rowEntry.getPrimaryKeyBytes()) : "result = " + new String(nexthash) + ", rowEntry.getPrimaryKeyBytes() = " + new String(rowEntry.getPrimaryKeyBytes());
+ assert Base64Order.enhancedCoder.equal(nexthash, crawlEntry.url().hash()) : "result = " + new String(nexthash) + ", crawlEntry.url().hash() = " + new String(crawlEntry.url().hash());
- if (failhashb != null && Base64Order.enhancedCoder.equal(failhashb, nexthashb)) break; // prevent endless loops
+ if (failhash != null && Base64Order.enhancedCoder.equal(failhash, nexthash)) break; // prevent endless loops
if (delay && sleeptime > 0 && this.domStackInitSize > 1) {
//System.out.println("*** putback: nexthash=" + nexthash + ", failhash="+failhash);
// put that thing back to omit a delay here
- if (!ByteBuffer.contains(delayed.values(), nexthashb)) {
+ if (!ByteBuffer.contains(delayed.values(), nexthash)) {
//System.out.println("*** delayed +=" + nexthash);
- this.delayed.put(Long.valueOf(System.currentTimeMillis() + sleeptime + 1), nexthashb);
+ this.delayed.put(Long.valueOf(System.currentTimeMillis() + sleeptime + 1), nexthash);
}
try {
this.urlFileIndex.put(rowEntry);
- this.domainStacks.remove(new String(nexthashb).substring(6));
- failhashb = nexthashb;
+ this.domainStacks.remove(new String(nexthash).substring(6));
+ failhash = nexthash;
} catch (RowSpaceExceededException e) {
Log.logException(e);
}
@@ -452,7 +452,7 @@ public class Balancer {
final Iterator<Map.Entry<String, LinkedList<byte[]>>> i = this.domainStacks.entrySet().iterator();
Map.Entry<String, LinkedList<byte[]>> entry;
long smallestWaiting = Long.MAX_VALUE;
- byte[] besthashb = null;
+ byte[] besthash = null;
while (i.hasNext()) {
entry = i.next();
@@ -468,7 +468,7 @@ public class Balancer {
if (w > maximumwaiting) {
if (w < smallestWaiting) {
smallestWaiting = w;
- besthashb = n;
+ besthash = n;
}
continue;
}
@@ -480,9 +480,9 @@ public class Balancer {
}
// if we could not find any entry, then take the best we have seen so far
- if (acceptonebest && !this.top.isEmpty() && besthashb != null) {
- removeHashFromDomainStacks(besthashb);
- this.top.add(besthashb);
+ if (acceptonebest && !this.top.isEmpty() && besthash != null) {
+ removeHashFromDomainStacks(besthash);
+ this.top.add(besthash);
}
}
diff --git a/source/de/anomic/crawler/CrawlStacker.java b/source/de/anomic/crawler/CrawlStacker.java
index 06426ff12..60b919404 100644
--- a/source/de/anomic/crawler/CrawlStacker.java
+++ b/source/de/anomic/crawler/CrawlStacker.java
@@ -366,18 +366,18 @@ public final class CrawlStacker {
("the host '" + host + "' is global, but global addresses are not accepted");
}
- public String urlInAcceptedDomainHash(final String urlhash) {
+ public String urlInAcceptedDomainHash(final byte[] urlhash) {
// returns true if the url can be accepted accoring to network.unit.domain
if (urlhash == null) return "url is null";
if (this.acceptGlobalURLs && this.acceptLocalURLs) return null; // fast shortcut to avoid dnsResolve
// check if this is a local address and we are allowed to index local pages:
//boolean local = hostAddress.isSiteLocalAddress() || hostAddress.isLoopbackAddress();
- final boolean local = DigestURI.isLocal(urlhash.getBytes());
+ final boolean local = DigestURI.isLocal(urlhash);
//assert local == yacyURL.isLocalDomain(url.hash()); // TODO: remove the dnsResolve above!
if ((this.acceptGlobalURLs && !local) || (this.acceptLocalURLs && local)) return null;
return (local) ?
- ("the urlhash '" + urlhash + "' is local, but local addresses are not accepted") :
- ("the urlhash '" + urlhash + "' is global, but global addresses are not accepted");
+ ("the urlhash '" + new String(urlhash) + "' is local, but local addresses are not accepted") :
+ ("the urlhash '" + new String(urlhash) + "' is global, but global addresses are not accepted");
}
public boolean acceptLocalURLs() {
diff --git a/source/de/anomic/crawler/NoticedURL.java b/source/de/anomic/crawler/NoticedURL.java
index 41a023348..c2a6b285c 100755
--- a/source/de/anomic/crawler/NoticedURL.java
+++ b/source/de/anomic/crawler/NoticedURL.java
@@ -193,8 +193,6 @@ public class NoticedURL {
return false;
} catch (RowSpaceExceededException e) {
return false;
- } catch (IOException e) {
- return false;
}
}
diff --git a/source/de/anomic/crawler/ResultURLs.java b/source/de/anomic/crawler/ResultURLs.java
index 47fd2fa5e..5ffc532d1 100644
--- a/source/de/anomic/crawler/ResultURLs.java
+++ b/source/de/anomic/crawler/ResultURLs.java
@@ -47,10 +47,10 @@ public final class ResultURLs {
private final Map<EventOrigin, ScoreCluster<String>> resultDomains;
public class InitExecEntry {
- public byte[] initiatorHashb, executorHashb;
+ public byte[] initiatorHash, executorHash;
public InitExecEntry(final byte[] initiatorHash, final byte[] executorHash) {
- this.initiatorHashb = initiatorHash;
- this.executorHashb = executorHash;
+ this.initiatorHash = initiatorHash;
+ this.executorHash = executorHash;
}
}
diff --git a/source/de/anomic/crawler/ZURL.java b/source/de/anomic/crawler/ZURL.java
index 72875f4e6..e47232d32 100755
--- a/source/de/anomic/crawler/ZURL.java
+++ b/source/de/anomic/crawler/ZURL.java
@@ -109,11 +109,11 @@ public class ZURL implements Iterable<ZURL.Entry> {
if (urlIndex != null) urlIndex.close();
}
- public boolean remove(final byte[] hashbytes) {
- if (hashbytes == null) return false;
+ public boolean remove(final byte[] hash) {
+ if (hash == null) return false;
//System.out.println("*** DEBUG ZURL " + this.urlIndex.filename() + " remove " + hash);
try {
- urlIndex.remove(hashbytes);
+ urlIndex.remove(hash);
return true;
} catch (final IOException e) {
return false;
@@ -131,7 +131,7 @@ public class ZURL implements Iterable<ZURL.Entry> {
if (anycause == null) anycause = "unknown";
Entry entry = new Entry(bentry, executor, workdate, workcount, anycause);
put(entry);
- stack.add(entry.hashb());
+ stack.add(entry.hash());
while (stack.size() > maxStackSize) stack.poll();
}
@@ -261,7 +261,7 @@ public class ZURL implements Iterable<ZURL.Entry> {
return this.bentry.initiator();
}
- public byte[] hashb() {
+ public byte[] hash() {
// return a url-hash, based on the md5 algorithm
// the result is a String of 12 bytes within a 72-bit space
// (each byte has an 6-bit range)
diff --git a/source/de/anomic/search/MediaSnippet.java b/source/de/anomic/search/MediaSnippet.java
index 093b34662..fa33ad740 100644
--- a/source/de/anomic/search/MediaSnippet.java
+++ b/source/de/anomic/search/MediaSnippet.java
@@ -35,6 +35,7 @@ import de.anomic.data.MimeTable;
import net.yacy.document.Document;
import net.yacy.document.parser.html.ImageEntry;
import net.yacy.kelondro.data.meta.DigestURI;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.repository.LoaderDispatcher;
@@ -108,7 +109,7 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
return o1.compareTo(o2);
}
- public static ArrayList<MediaSnippet> retrieveMediaSnippets(final DigestURI url, final TreeSet<byte[]> queryhashes, final ContentDomain mediatype, final boolean fetchOnline, final int timeout, final boolean reindexing) {
+ public static ArrayList<MediaSnippet> retrieveMediaSnippets(final DigestURI url, final HandleSet queryhashes, final ContentDomain mediatype, final boolean fetchOnline, final int timeout, final boolean reindexing) {
if (queryhashes.isEmpty()) {
Log.logFine("snippet fetch", "no query hashes given for url " + url);
return new ArrayList<MediaSnippet>();
@@ -125,7 +126,7 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
return a;
}
- public static ArrayList<MediaSnippet> computeMediaSnippets(final Document document, final TreeSet<byte[]> queryhashes, final ContentDomain mediatype) {
+ public static ArrayList<MediaSnippet> computeMediaSnippets(final Document document, final HandleSet queryhashes, final ContentDomain mediatype) {
if (document == null) return new ArrayList<MediaSnippet>();
Map<DigestURI, String> media = null;
@@ -152,7 +153,7 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
return result;
}
- public static ArrayList<MediaSnippet> computeImageSnippets(final Document document, final TreeSet<byte[]> queryhashes) {
+ public static ArrayList<MediaSnippet> computeImageSnippets(final Document document, final HandleSet queryhashes) {
final TreeSet<ImageEntry> images = new TreeSet<ImageEntry>();
images.addAll(document.getImages().values()); // iterates images in descending size order!
diff --git a/source/de/anomic/search/QueryParams.java b/source/de/anomic/search/QueryParams.java
index 116dfdde6..ddd8cca89 100644
--- a/source/de/anomic/search/QueryParams.java
+++ b/source/de/anomic/search/QueryParams.java
@@ -36,6 +36,10 @@ import net.yacy.document.parser.html.AbstractScraper;
import net.yacy.document.parser.html.CharacterCoding;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.word.Word;
+import net.yacy.kelondro.data.word.WordReferenceRow;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
+import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.order.NaturalOrder;
@@ -63,7 +67,7 @@ public final class QueryParams {
public static final Pattern matchnothing_pattern = Pattern.compile("");
public final String queryString;
- public TreeSet<byte[]> fullqueryHashes, queryHashes, excludeHashes;
+ public HandleSet fullqueryHashes, queryHashes, excludeHashes;
public final int itemsPerPage;
public int offset;
public final Pattern urlMask, prefer;
@@ -98,15 +102,19 @@ public final class QueryParams {
final RankingProfile ranking) {
if ((queryString.length() == 12) && (Base64Order.enhancedCoder.wellformed(queryString.getBytes()))) {
this.queryString = null;
- this.queryHashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
- this.excludeHashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
- this.queryHashes.add(queryString.getBytes());
+ this.queryHashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);
+ this.excludeHashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);
+ try {
+ this.queryHashes.put(queryString.getBytes());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
} else {
this.queryString = queryString;
final TreeSet<String>[] cq = cleanQuery(queryString);
- this.queryHashes = Word.words2hashes(cq[0]);
- this.excludeHashes = Word.words2hashes(cq[1]);
- this.fullqueryHashes = Word.words2hashes(cq[2]);
+ this.queryHashes = Word.words2hashesHandles(cq[0]);
+ this.excludeHashes = Word.words2hashesHandles(cq[1]);
+ this.fullqueryHashes = Word.words2hashesHandles(cq[2]);
}
this.ranking = ranking;
this.tenant = null;
@@ -136,9 +144,9 @@ public final class QueryParams {
}
public QueryParams(
- final String queryString, final TreeSet<byte[]> queryHashes,
- final TreeSet<byte[]> excludeHashes,
- final TreeSet<byte[]> fullqueryHashes,
+ final String queryString, final HandleSet queryHashes,
+ final HandleSet excludeHashes,
+ final HandleSet fullqueryHashes,
final String tenant,
final int maxDistance, final String prefer, final ContentDomain contentdom,
final String language,
@@ -216,11 +224,13 @@ public final class QueryParams {
return this.domType == SEARCHDOM_LOCAL;
}
- public static TreeSet<byte[]> hashes2Set(final String query) {
- if (query == null) return new TreeSet<byte[]>(Base64Order.enhancedCoder);
- final TreeSet<byte[]> keyhashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
- for (int i = 0; i < (query.length() / Word.commonHashLength); i++) {
- keyhashes.add(query.substring(i * Word.commonHashLength, (i + 1) * Word.commonHashLength).getBytes());
+ public static HandleSet hashes2Set(final String query) {
+ final HandleSet keyhashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);
+ if (query == null) return keyhashes;
+ for (int i = 0; i < (query.length() / Word.commonHashLength); i++) try {
+ keyhashes.put(query.substring(i * Word.commonHashLength, (i + 1) * Word.commonHashLength).getBytes());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
}
return keyhashes;
}
@@ -234,18 +244,40 @@ public final class QueryParams {
return keyhashes;
}
+ public static HandleSet hashes2Handles(final String query) {
+ final HandleSet keyhashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);
+ if (query == null) return keyhashes;
+ for (int i = 0; i < (query.length() / Word.commonHashLength); i++) try {
+ keyhashes.put(query.substring(i * Word.commonHashLength, (i + 1) * Word.commonHashLength).getBytes());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
+ return keyhashes;
+ }
+ /*
public static String hashSet2hashString(final TreeSet<byte[]> hashes) {
final byte[] bb = new byte[hashes.size() * Word.commonHashLength];
int p = 0;
for (byte[] b : hashes) {
- assert b.length == Word.commonHashLength : "hash = " + new String(b);
- System.arraycopy(b, 0, bb, p, Word.commonHashLength);
- p += Word.commonHashLength;
+ assert b.length == Word.commonHashLength : "hash = " + new String(b);
+ System.arraycopy(b, 0, bb, p, Word.commonHashLength);
+ p += Word.commonHashLength;
+ }
+ return new String(bb);
+ }
+ */
+ public static String hashSet2hashString(final HandleSet hashes) {
+ final byte[] bb = new byte[hashes.size() * Word.commonHashLength];
+ int p = 0;
+ for (byte[] b : hashes) {
+ assert b.length == Word.commonHashLength : "hash = " + new String(b);
+ System.arraycopy(b, 0, bb, p, Word.commonHashLength);
+ p += Word.commonHashLength;
}
return new String(bb);
}
- public static String anonymizedQueryHashes(final TreeSet<byte[]> hashes) {
+ public static String anonymizedQueryHashes(final HandleSet hashes) {
// create a more anonymized representation of a query hashes for logging
final Iterator<byte[]> i = hashes.iterator();
final StringBuilder sb = new StringBuilder(hashes.size() * (Word.commonHashLength + 2) + 2);
@@ -263,10 +295,10 @@ public final class QueryParams {
return new String(sb);
}
- public static final boolean matches(final String text, final TreeSet<byte[]> keyhashes) {
+ public static final boolean matches(final String text, final HandleSet keyhashes) {
// returns true if any of the word hashes in keyhashes appear in the String text
// to do this, all words in the string must be recognized and transcoded to word hashes
- final TreeSet<byte[]> wordhashes = Word.words2hashes(Condenser.getWords(text).keySet());
+ final HandleSet wordhashes = Word.words2hashesHandles(Condenser.getWords(text).keySet());
return SetTools.anymatch(wordhashes, keyhashes);
}
@@ -325,8 +357,8 @@ public final class QueryParams {
public void filterOut(final TreeSet<String> blueList) {
// filter out words that appear in this set
// this is applied to the queryHashes
- final TreeSet<byte[]> blues = Word.words2hashes(blueList);
- SetTools.excludeDestructive(queryHashes, blues);
+ final HandleSet blues = Word.words2hashesHandles(blueList);
+ for (byte[] b: blues) queryHashes.remove(b);
}
public String id(final boolean anonymized) {
diff --git a/source/de/anomic/search/RankingProcess.java b/source/de/anomic/search/RankingProcess.java
index 613c42852..6dd66cf10 100644
--- a/source/de/anomic/search/RankingProcess.java
+++ b/source/de/anomic/search/RankingProcess.java
@@ -36,7 +36,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@@ -49,6 +48,8 @@ import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.data.word.WordReferenceVars;
import net.yacy.kelondro.index.BinSearch;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.rwi.ReferenceContainer;
@@ -68,9 +69,9 @@ public final class RankingProcess extends Thread {
private final QueryParams query;
private final int maxentries;
- private final ConcurrentHashMap<String, Long> urlhashes; // map for double-check; String/Long relation, addresses ranking number (backreference for deletion)
+ private final HandleSet urlhashes; // map for double-check; String/Long relation, addresses ranking number (backreference for deletion)
private final int[] flagcount; // flag counter
- private final TreeSet<String> misses; // contains url-hashes that could not been found in the LURL-DB
+ private final HandleSet misses; // contains url-hashes that could not been found in the LURL-DB
//private final int[] domZones;
private HashMap<byte[], ReferenceContainer<WordReference>> localSearchInclusion;
@@ -103,8 +104,8 @@ public final class RankingProcess extends Thread {
this.remote_indexCount = 0;
this.local_resourceSize = 0;
this.local_indexCount = 0;
- this.urlhashes = new ConcurrentHashMap<String, Long>(0, 0.75f, concurrency);
- this.misses = new TreeSet<String>();
+ this.urlhashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
+ this.misses = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
this.flagcount = new int[32];
for (int i = 0; i < 32; i++) {this.flagcount[i] = 0;}
this.hostNavigator = new Navigator();
@@ -185,7 +186,7 @@ public final class RankingProcess extends Thread {
while (true) {
iEntry = decodedEntries.poll(1, TimeUnit.SECONDS);
if (iEntry == null || iEntry == WordReferenceVars.poison) break;
- assert (iEntry.metadataHash().length() == index.row().primaryKeyLength);
+ assert (iEntry.metadataHash().length == index.row().primaryKeyLength);
//if (iEntry.urlHash().length() != index.row().primaryKeyLength) continue;
// increase flag counts
@@ -205,13 +206,13 @@ public final class RankingProcess extends Thread {
}
// check tld domain
- if (!DigestURI.matchesAnyDomDomain(iEntry.metadataHash().getBytes(), this.query.zonecode)) {
+ if (!DigestURI.matchesAnyDomDomain(iEntry.metadataHash(), this.query.zonecode)) {
// filter out all tld that do not match with wanted tld domain
continue;
}
// check site constraints
- if (query.sitehash != null && !iEntry.metadataHash().substring(6).equals(query.sitehash)) {
+ if (query.sitehash != null && !new String(iEntry.metadataHash()).substring(6).equals(query.sitehash)) {
// filter out all domains that do not match with the site constraint
continue;
}
@@ -221,8 +222,9 @@ public final class RankingProcess extends Thread {
// get statistics for host navigator
if (nav_hosts && query.urlMask_isCatchall) {
- domhash = iEntry.urlHash.substring(6);
- this.hostNavigator.inc(domhash, iEntry.urlHash);
+ String uhb = new String(iEntry.urlHash);
+ domhash = uhb.substring(6);
+ this.hostNavigator.inc(domhash, uhb);
}
// accept
@@ -240,7 +242,7 @@ public final class RankingProcess extends Thread {
assert maxentries != 0;
// double-check
- if (urlhashes.containsKey(fEntry.metadataHash())) continue;
+ if (urlhashes.has(fEntry.metadataHash())) continue;
// insert
if (maxentries < 0 || stack.size() < maxentries) {
@@ -254,7 +256,11 @@ public final class RankingProcess extends Thread {
// to the maximum size by deletion of elements at the bottom
stack.push(fEntry, r);
}
- urlhashes.put(fEntry.metadataHash(), r);
+ try {
+ urlhashes.put(fEntry.metadataHash());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
}
} catch (InterruptedException e) {}
@@ -317,7 +323,7 @@ public final class RankingProcess extends Thread {
if (rwi == null) continue; // in case that a synchronization problem occurred just go lazy over it
if (!skipDoubleDom) return rwi;
// check doubledom
- final String domhash = rwi.element.metadataHash().substring(6);
+ final String domhash = new String(rwi.element.metadataHash()).substring(6);
m = this.doubleDomCache.get(domhash);
if (m == null) {
// first appearance of dom
@@ -355,7 +361,7 @@ public final class RankingProcess extends Thread {
}
if (bestEntry == null) return null;
// finally remove the best entry from the doubledom cache
- m = this.doubleDomCache.get(bestEntry.element.metadataHash().substring(6));
+ m = this.doubleDomCache.get(new String(bestEntry.element.metadataHash()).substring(6));
o = m.pop();
//assert o == null || o.element.metadataHash().equals(bestEntry.element.metadataHash()) : "bestEntry.element.metadataHash() = " + bestEntry.element.metadataHash() + ", o.element.metadataHash() = " + o.element.metadataHash();
return bestEntry;
@@ -374,7 +380,7 @@ public final class RankingProcess extends Thread {
// returns from the current RWI list the best URL entry and removes this entry from the list
long timeLimit = System.currentTimeMillis() + timeout;
int p = -1;
- String urlhash;
+ byte[] urlhash;
while (System.currentTimeMillis() < timeLimit) {
final SortStack<WordReferenceVars>.stackElement obrwi = takeRWI(skipDoubleDom);
if (obrwi == null) {
@@ -383,9 +389,13 @@ public final class RankingProcess extends Thread {
continue;
}
urlhash = obrwi.element.metadataHash();
- final URIMetadataRow page = this.query.getSegment().urlMetadata().load(urlhash.getBytes(), obrwi.element, obrwi.weight.longValue());
+ final URIMetadataRow page = this.query.getSegment().urlMetadata().load(urlhash, obrwi.element, obrwi.weight.longValue());
if (page == null) {
- misses.add(obrwi.element.metadataHash());
+ try {
+ misses.put(obrwi.element.metadataHash());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
continue;
}
@@ -405,7 +415,7 @@ public final class RankingProcess extends Thread {
// in case that we do not have e catchall filter for urls
// we must also construct the domain navigator here
- this.hostNavigator.inc(urlhash.substring(6), urlhash);
+ this.hostNavigator.inc(new String(urlhash).substring(6), new String(urlhash));
}
// check for more errors
@@ -536,7 +546,7 @@ public final class RankingProcess extends Thread {
urlhashes.remove(reference.urlHash);
}
- public Iterator<String> miss() {
+ public Iterator<byte[]> miss() {
return this.misses.iterator();
}
@@ -605,7 +615,7 @@ public final class RankingProcess extends Thread {
word = words[i].toLowerCase();
if (word.length() > 2 &&
"http_html_php_ftp_www_com_org_net_gov_edu_index_home_page_for_usage_the_and_".indexOf(word) < 0 &&
- !query.queryHashes.contains(Word.word2hash(word)) &&
+ !query.queryHashes.has(Word.word2hash(word)) &&
word.matches("[a-z]+") &&
!Switchboard.badwords.contains(word) &&
!Switchboard.stopwords.contains(word)) {
diff --git a/source/de/anomic/search/ReferenceOrder.java b/source/de/anomic/search/ReferenceOrder.java
index 6f1c9cd21..a6603e81b 100644
--- a/source/de/anomic/search/ReferenceOrder.java
+++ b/source/de/anomic/search/ReferenceOrder.java
@@ -146,7 +146,7 @@ public class ReferenceOrder {
if (min == null) min = iEntry.clone(); else min.min(iEntry);
if (max == null) max = iEntry.clone(); else max.max(iEntry);
// update domcount
- dom = iEntry.metadataHash().substring(6);
+ dom = new String(iEntry.metadataHash()).substring(6);
count = doms0.get(dom);
if (count == null) {
doms0.put(dom, int1);
@@ -193,9 +193,10 @@ public class ReferenceOrder {
//System.out.println("tf(" + t.urlHash + ") = " + Math.floor(1000 * t.termFrequency()) + ", min = " + Math.floor(1000 * min.termFrequency()) + ", max = " + Math.floor(1000 * max.termFrequency()) + ", tf-normed = " + tf);
int maxmaxpos = max.maxposition();
int minminpos = min.minposition();
+ String mdhb = new String(t.metadataHash());
final long r =
- ((256 - DigestURI.domLengthNormalized(t.metadataHash().getBytes())) << ranking.coeff_domlength)
- + ((ranking.coeff_ybr > 12) ? ((256 - (RankingProcess.ybr(t.metadataHash()) << 4)) << ranking.coeff_ybr) : 0)
+ ((256 - DigestURI.domLengthNormalized(t.metadataHash())) << ranking.coeff_domlength)
+ + ((ranking.coeff_ybr > 12) ? ((256 - (RankingProcess.ybr(mdhb) << 4)) << ranking.coeff_ybr) : 0)
+ ((max.urlcomps() == min.urlcomps() ) ? 0 : (256 - (((t.urlcomps() - min.urlcomps() ) << 8) / (max.urlcomps() - min.urlcomps()) )) << ranking.coeff_urlcomps)
+ ((max.urllength() == min.urllength() ) ? 0 : (256 - (((t.urllength() - min.urllength() ) << 8) / (max.urllength() - min.urllength()) )) << ranking.coeff_urllength)
+ ((maxmaxpos == minminpos ) ? 0 : (256 - (((t.minposition() - minminpos ) << 8) / (maxmaxpos - minminpos) )) << ranking.coeff_posintext)
@@ -210,7 +211,7 @@ public class ReferenceOrder {
+ ((max.lother() == min.lother()) ? 0 : (((t.lother() - min.lother() ) << 8) / (max.lother() - min.lother()) ) << ranking.coeff_lother)
+ ((max.hitcount() == min.hitcount()) ? 0 : (((t.hitcount() - min.hitcount() ) << 8) / (max.hitcount() - min.hitcount()) ) << ranking.coeff_hitcount)
+ tf
- + ((ranking.coeff_authority > 12) ? (authority(t.metadataHash()) << ranking.coeff_authority) : 0)
+ + ((ranking.coeff_authority > 12) ? (authority(mdhb) << ranking.coeff_authority) : 0)
+ ((flags.get(WordReferenceRow.flag_app_dc_identifier)) ? 255 << ranking.coeff_appurl : 0)
+ ((flags.get(WordReferenceRow.flag_app_dc_title)) ? 255 << ranking.coeff_app_dc_title : 0)
+ ((flags.get(WordReferenceRow.flag_app_dc_creator)) ? 255 << ranking.coeff_app_dc_creator : 0)
@@ -224,6 +225,7 @@ public class ReferenceOrder {
+ ((flags.get(Condenser.flag_cat_hasapp)) ? 255 << ranking.coeff_cathasapp : 0)
+ ((patchUK(t.language).equals(this.language)) ? 255 << ranking.coeff_language : 0)
+ ((DigestURI.probablyRootURL(t.metadataHash())) ? 15 << ranking.coeff_urllength : 0);
+
//if (searchWords != null) r += (yacyURL.probablyWordURL(t.urlHash(), searchWords) != null) ? 256 << ranking.coeff_appurl : 0;
return Long.MAX_VALUE - r; // returns a reversed number: the lower the number the better the ranking. This is used for simple sorting with a TreeMap
diff --git a/source/de/anomic/search/ResultEntry.java b/source/de/anomic/search/ResultEntry.java
index e4dc52f3f..c563de4de 100644
--- a/source/de/anomic/search/ResultEntry.java
+++ b/source/de/anomic/search/ResultEntry.java
@@ -83,7 +83,7 @@ public class ResultEntry implements Comparable<ResultEntry>, Comparator<ResultEn
// seed is not known from here
try {
indexSegment.termIndex().remove(
- Word.words2hashes(Condenser.getWords(
+ Word.words2hashesHandles(Condenser.getWords(
("yacyshare " +
filename.replace('?', ' ') +
" " +
diff --git a/source/de/anomic/search/ResultFetcher.java b/source/de/anomic/search/ResultFetcher.java
index a053a04cf..4ec99b0e3 100644
--- a/source/de/anomic/search/ResultFetcher.java
+++ b/source/de/anomic/search/ResultFetcher.java
@@ -32,15 +32,15 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
import net.yacy.document.Condenser;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.Word;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.EventTracker;
-import net.yacy.kelondro.util.SetTools;
import net.yacy.kelondro.util.SortStack;
import net.yacy.kelondro.util.SortStore;
import net.yacy.repository.LoaderDispatcher;
@@ -62,12 +62,11 @@ public class ResultFetcher {
protected final SortStore<ResultEntry> result;
protected final SortStore<MediaSnippet> images; // container to sort images by size
protected final HashMap<String, String> failedURLs; // a mapping from a urlhash to a fail reason string
- protected final TreeSet<byte[]> snippetFetchWordHashes; // a set of word hashes that are used to match with the snippets
+ protected final HandleSet snippetFetchWordHashes; // a set of word hashes that are used to match with the snippets
long urlRetrievalAllTime;
long snippetComputationAllTime;
int taketimeout;
- @SuppressWarnings("unchecked")
public ResultFetcher(
final LoaderDispatcher loader,
RankingProcess rankedCache,
@@ -89,10 +88,16 @@ public class ResultFetcher {
// snippets do not need to match with the complete query hashes,
// only with the query minus the stopwords which had not been used for the search
- final TreeSet<byte[]> filtered = SetTools.joinConstructive(query.queryHashes, Switchboard.stopwordHashes);
- this.snippetFetchWordHashes = (TreeSet<byte[]>) query.queryHashes.clone();
+ HandleSet filtered;
+ try {
+ filtered = HandleSet.joinConstructive(query.queryHashes, Switchboard.stopwordHashes);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ filtered = new HandleSet(query.queryHashes.row().primaryKeyLength, query.queryHashes.comparator(), 0);
+ }
+ this.snippetFetchWordHashes = query.queryHashes.clone();
if (filtered != null && !filtered.isEmpty()) {
- SetTools.excludeDestructive(this.snippetFetchWordHashes, Switchboard.stopwordHashes);
+ this.snippetFetchWordHashes.excludeDestructive(Switchboard.stopwordHashes);
}
// start worker threads to fetch urls and snippets
@@ -383,14 +388,14 @@ public class ResultFetcher {
}
// apply query-in-result matching
- final Set<byte[]> urlcomph = Word.words2hashSet(urlcomps);
- final Set<byte[]> descrcomph = Word.words2hashSet(descrcomps);
+ final HandleSet urlcomph = Word.words2hashesHandles(urlcomps);
+ final HandleSet descrcomph = Word.words2hashesHandles(descrcomps);
final Iterator<byte[]> shi = query.queryHashes.iterator();
byte[] queryhash;
while (shi.hasNext()) {
queryhash = shi.next();
- if (urlcomph.contains(queryhash)) r += 256 << query.ranking.coeff_appurl;
- if (descrcomph.contains(queryhash)) r += 256 << query.ranking.coeff_app_dc_title;
+ if (urlcomph.has(queryhash)) r += 256 << query.ranking.coeff_appurl;
+ if (descrcomph.has(queryhash)) r += 256 << query.ranking.coeff_app_dc_title;
}
return r;
diff --git a/source/de/anomic/search/SearchEvent.java b/source/de/anomic/search/SearchEvent.java
index 6c659b5d9..16c2f82ae 100644
--- a/source/de/anomic/search/SearchEvent.java
+++ b/source/de/anomic/search/SearchEvent.java
@@ -32,10 +32,11 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import java.util.TreeSet;
import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.data.word.WordReferenceVars;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.rwi.ReferenceContainer;
@@ -222,8 +223,12 @@ public final class SearchEvent {
// execute deletion of failed words
int rw = this.results.failedURLs.size();
if (rw > 0) {
- final TreeSet<byte[]> removeWords = query.queryHashes;
- removeWords.addAll(query.excludeHashes);
+ final HandleSet removeWords = query.queryHashes;
+ try {
+ removeWords.putAll(query.excludeHashes);
+ } catch (RowSpaceExceededException e1) {
+ Log.logException(e1);
+ }
try {
final Iterator<byte[]> j = removeWords.iterator();
// remove the same url hashes for multiple words
diff --git a/source/de/anomic/search/Segment.java b/source/de/anomic/search/Segment.java
index c21838b36..03abc651e 100644
--- a/source/de/anomic/search/Segment.java
+++ b/source/de/anomic/search/Segment.java
@@ -32,7 +32,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -50,6 +49,7 @@ import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.data.word.WordReferenceFactory;
import net.yacy.kelondro.data.word.WordReferenceRow;
import net.yacy.kelondro.data.word.WordReferenceVars;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.ByteOrder;
@@ -362,6 +362,10 @@ public class Segment {
return removeAllUrlReferences(url.hash(), loader, fetchOnline);
}
+ public void removeAllUrlReferences(final HandleSet urls, LoaderDispatcher loader, final boolean fetchOnline) {
+ for (byte[] urlhash: urls) removeAllUrlReferences(urlhash, loader, fetchOnline);
+ }
+
public int removeAllUrlReferences(final byte[] urlhash, LoaderDispatcher loader, final boolean fetchOnline) {
// find all the words in a specific resource and remove the url reference from every word index
// finally, delete the url entry
@@ -403,7 +407,7 @@ public class Segment {
// delete all word references
int count = 0;
- if (words != null) count = termIndex().remove(Word.words2hashes(words), urlhash);
+ if (words != null) count = termIndex().remove(Word.words2hashesHandles(words), urlhash);
// finally delete the url entry itself
urlMetadata().remove(urlhash);
@@ -445,7 +449,7 @@ public class Segment {
ReferenceContainer<WordReference> container = null;
WordReferenceVars entry = null;
DigestURI url = null;
- final HashSet<String> urlHashs = new HashSet<String>();
+ final HandleSet urlHashs = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
try {
Iterator<ReferenceContainer<WordReference>> indexContainerIterator = termIndex.references(startHash, false, 100, false).iterator();
while (indexContainerIterator.hasNext() && run) {
@@ -458,19 +462,19 @@ public class Segment {
entry = new WordReferenceVars(containerIterator.next());
// System.out.println("Wordhash: "+wordHash+" UrlHash:
// "+entry.getUrlHash());
- final URIMetadataRow ue = urlMetadata.load(entry.metadataHash().getBytes(), entry, 0);
+ final URIMetadataRow ue = urlMetadata.load(entry.metadataHash(), entry, 0);
if (ue == null) {
- urlHashs.add(entry.metadataHash());
+ urlHashs.put(entry.metadataHash());
} else {
url = ue.metadata().url();
if (url == null || Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_CRAWLER, url)) {
- urlHashs.add(entry.metadataHash());
+ urlHashs.put(entry.metadataHash());
}
}
}
if (!urlHashs.isEmpty()) try {
final int removed = termIndex.remove(container.getTermHash(), urlHashs);
- Log.logFine("INDEXCLEANER", container.getTermHashAsString() + ": " + removed + " of " + container.size() + " URL-entries deleted");
+ Log.logFine("INDEXCLEANER", new String(container.getTermHash()) + ": " + removed + " of " + container.size() + " URL-entries deleted");
lastWordHash = container.getTermHash();
lastDeletionCounter = urlHashs.size();
urlHashs.clear();
diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java
index c85a3d706..971fc15e0 100644
--- a/source/de/anomic/search/Switchboard.java
+++ b/source/de/anomic/search/Switchboard.java
@@ -74,6 +74,7 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.meta.URIMetadataRow.Components;
import net.yacy.kelondro.data.word.Word;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
@@ -162,9 +163,9 @@ public final class Switchboard extends serverSwitch {
public static TreeSet<String> badwords = new TreeSet<String>(NaturalOrder.naturalComparator);
public static TreeSet<String> stopwords = new TreeSet<String>(NaturalOrder.naturalComparator);
public static TreeSet<String> blueList = null;
- public static TreeSet<byte[]> badwordHashes = null;
- public static TreeSet<byte[]> blueListHashes = null;
- public static TreeSet<byte[]> stopwordHashes = null;
+ public static HandleSet badwordHashes = null;
+ public static HandleSet blueListHashes = null;
+ public static HandleSet stopwordHashes = null;
public static Blacklist urlBlacklist = null;
public static wikiParser wikiParser = null;
@@ -376,7 +377,7 @@ public final class Switchboard extends serverSwitch {
final String f = getConfig(SwitchboardConstants.LIST_BLUE, SwitchboardConstants.LIST_BLUE_DEFAULT);
final File plasmaBlueListFile = new File(f);
if (f != null) blueList = SetTools.loadList(plasmaBlueListFile, NaturalOrder.naturalComparator); else blueList= new TreeSet<String>();
- blueListHashes = Word.words2hashes(blueList);
+ blueListHashes = Word.words2hashesHandles(blueList);
this.log.logConfig("loaded blue-list from file " + plasmaBlueListFile.getName() + ", " +
blueList.size() + " entries, " +
ppRamString(plasmaBlueListFile.length()/1024));
@@ -394,7 +395,7 @@ public final class Switchboard extends serverSwitch {
if (badwords == null || badwords.isEmpty()) {
final File badwordsFile = new File(rootPath, SwitchboardConstants.LIST_BADWORDS_DEFAULT);
badwords = SetTools.loadList(badwordsFile, NaturalOrder.naturalComparator);
- badwordHashes = Word.words2hashes(badwords);
+ badwordHashes = Word.words2hashesHandles(badwords);
this.log.logConfig("loaded badwords from file " + badwordsFile.getName() +
", " + badwords.size() + " entries, " +
ppRamString(badwordsFile.length()/1024));
@@ -404,7 +405,7 @@ public final class Switchboard extends serverSwitch {
if (stopwords == null || stopwords.isEmpty()) {
final File stopwordsFile = new File(rootPath, SwitchboardConstants.LIST_STOPWORDS_DEFAULT);
stopwords = SetTools.loadList(stopwordsFile, NaturalOrder.naturalComparator);
- stopwordHashes = Word.words2hashes(stopwords);
+ stopwordHashes = Word.words2hashesHandles(stopwords);
this.log.logConfig("loaded stopwords from file " + stopwordsFile.getName() + ", " +
stopwords.size() + " entries, " +
ppRamString(stopwordsFile.length()/1024));
diff --git a/source/de/anomic/search/TextSnippet.java b/source/de/anomic/search/TextSnippet.java
index 97369cbed..b0cda4c21 100644
--- a/source/de/anomic/search/TextSnippet.java
+++ b/source/de/anomic/search/TextSnippet.java
@@ -29,9 +29,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
-import java.util.Set;
import java.util.TreeMap;
-import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -45,6 +43,8 @@ import net.yacy.kelondro.data.word.Word;
import net.yacy.kelondro.data.word.WordReferenceVars;
import net.yacy.kelondro.index.ARC;
import net.yacy.kelondro.index.ConcurrentARC;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.util.SetTools;
@@ -78,10 +78,10 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
private String line;
private final String error;
private final int errorCode;
- private TreeSet<byte[]> remaingHashes;
+ private HandleSet remaingHashes;
private final DigestURI favicon;
- public static boolean existsInCache(final DigestURI url, final TreeSet<byte[]> queryhashes) {
+ public static boolean existsInCache(final DigestURI url, final HandleSet queryhashes) {
final String hashes = yacySearch.set2string(queryhashes);
return retrieveFromCache(hashes, new String(url.hash())) != null;
}
@@ -109,19 +109,23 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
* @param queryhashes
* @return the given hash set minus the hashes from the tokenization of the given sentence
*/
- public static TreeSet<byte[]> removeAppearanceHashes(final String sentence, final TreeSet<byte[]> queryhashes) {
+ public static HandleSet removeAppearanceHashes(final String sentence, final HandleSet queryhashes) {
// remove all hashes that appear in the sentence
if (sentence == null) return queryhashes;
final TreeMap<byte[], Integer> hs = Condenser.hashSentence(sentence);
final Iterator<byte[]> j = queryhashes.iterator();
byte[] hash;
Integer pos;
- final TreeSet<byte[]> remaininghashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
+ final HandleSet remaininghashes = new HandleSet(queryhashes.row().primaryKeyLength, queryhashes.comparator(), queryhashes.size());
while (j.hasNext()) {
hash = j.next();
pos = hs.get(hash);
if (pos == null) {
- remaininghashes.add(hash);
+ try {
+ remaininghashes.put(hash);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
}
}
return remaininghashes;
@@ -148,11 +152,11 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
*/
private final static Pattern p01 = Pattern.compile("(.*?)(\\<b\\>.+?\\</b\\>)(.*)"); // marked words are in <b>-tags
- public TextSnippet(final DigestURI url, final String line, final int errorCode, final TreeSet<byte[]> remaingHashes, final String errortext) {
- this(url,line,errorCode,remaingHashes,errortext,null);
+ public TextSnippet(final DigestURI url, final String line, final int errorCode, final HandleSet remaingHashes, final String errortext) {
+ this(url, line, errorCode, remaingHashes, errortext, null);
}
- public TextSnippet(final DigestURI url, final String line, final int errorCode, final TreeSet<byte[]> remaingHashes, final String errortext, final DigestURI favicon) {
+ public TextSnippet(final DigestURI url, final String line, final int errorCode, final HandleSet remaingHashes, final String errortext, final DigestURI favicon) {
this.url = url;
this.line = line;
this.errorCode = errorCode;
@@ -192,12 +196,12 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
public int getErrorCode() {
return errorCode;
}
- public TreeSet<byte[]> getRemainingHashes() {
+ public HandleSet getRemainingHashes() {
return this.remaingHashes;
}
- public String getLineMarked(final TreeSet<byte[]> queryHashes) {
+ public String getLineMarked(final HandleSet queryHashes) {
if (line == null) return "";
- if ((queryHashes == null) || (queryHashes.isEmpty())) return line.trim();
+ if (queryHashes == null || queryHashes.isEmpty()) return line.trim();
if (line.endsWith(".")) line = line.substring(0, line.length() - 1);
final Iterator<byte[]> i = queryHashes.iterator();
byte[] h;
@@ -306,8 +310,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
return al;
}
- @SuppressWarnings("unchecked")
- public static TextSnippet retrieveTextSnippet(final LoaderDispatcher loader, final URIMetadataRow.Components comp, final TreeSet<byte[]> queryhashes, final boolean fetchOnline, final boolean pre, final int snippetMaxLength, final int maxDocLen, final boolean reindexing) {
+ public static TextSnippet retrieveTextSnippet(final LoaderDispatcher loader, final URIMetadataRow.Components comp, final HandleSet queryhashes, final boolean fetchOnline, final boolean pre, final int snippetMaxLength, final int maxDocLen, final boolean reindexing) {
// heise = "0OQUNU3JSs05"
final DigestURI url = comp.url();
if (queryhashes.isEmpty()) {
@@ -413,7 +416,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
if (sentences == null) return new TextSnippet(url, null, ERROR_PARSER_NO_LINES, queryhashes, "parser returned no sentences",resFavicon);
final Object[] tsr = computeTextSnippet(sentences, queryhashes, snippetMaxLength);
final String textline = (tsr == null) ? null : (String) tsr[0];
- final TreeSet<byte[]> remainingHashes = (tsr == null) ? queryhashes : (TreeSet<byte[]>) tsr[1];
+ final HandleSet remainingHashes = (tsr == null) ? queryhashes : (HandleSet) tsr[1];
// compute snippet from media
//String audioline = computeMediaSnippet(document.getAudiolinks(), queryhashes);
@@ -439,18 +442,16 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
return new TextSnippet(url, line, source, null, null, resFavicon);
}
- private static boolean containsAllHashes(final String sentence, final Set<byte[]> queryhashes) {
+ private static boolean containsAllHashes(final String sentence, final HandleSet queryhashes) {
final TreeMap<byte[], Integer> m = Condenser.hashSentence(sentence);
- final Iterator<byte[]> i = queryhashes.iterator();
- while (i.hasNext()) {
- if (!(m.containsKey(i.next()))) return false;
+ for (byte[] b: queryhashes) {
+ if (!(m.containsKey(b))) return false;
}
return true;
}
- @SuppressWarnings("unchecked")
- private static Object[] /*{String - the snippet, Set - remaining hashes}*/
- computeTextSnippet(final Iterator<StringBuilder> sentences, final TreeSet<byte[]> queryhashes, int maxLength) {
+ private static Object[] /*{String - the snippet, HandleSet - remaining hashes}*/
+ computeTextSnippet(final Iterator<StringBuilder> sentences, final HandleSet queryhashes, int maxLength) {
try {
if (sentences == null) return null;
if ((queryhashes == null) || (queryhashes.isEmpty())) return null;
@@ -472,14 +473,14 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
}
String result;
- TreeSet<byte[]> remaininghashes;
+ HandleSet remaininghashes;
while (!os.isEmpty()) {
sentence = os.remove(os.lastKey()); // sentence with the biggest score
Object[] tsr = computeTextSnippet(sentence.toString(), queryhashes, maxLength);
if (tsr == null) continue;
result = (String) tsr[0];
if ((result != null) && (result.length() > 0)) {
- remaininghashes = (TreeSet<byte[]>) tsr[1];
+ remaininghashes = (HandleSet) tsr[1];
if (remaininghashes.isEmpty()) {
// we have found the snippet
return new Object[]{result, remaininghashes};
@@ -508,8 +509,8 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
}
}
- private static Object[] /*{String - the snippet, Set - remaining hashes}*/
- computeTextSnippet(String sentence, final TreeSet<byte[]> queryhashes, final int maxLength) {
+ private static Object[] /*{String - the snippet, HandleSet - remaining hashes}*/
+ computeTextSnippet(String sentence, final HandleSet queryhashes, final int maxLength) {
try {
if (sentence == null) return null;
if ((queryhashes == null) || (queryhashes.isEmpty())) return null;
@@ -520,12 +521,16 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
final Iterator<byte[]> j = queryhashes.iterator();
Integer pos;
int p, minpos = sentence.length(), maxpos = -1;
- final TreeSet<byte[]> remainingHashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
+ final HandleSet remainingHashes = new HandleSet(queryhashes.row().primaryKeyLength, queryhashes.comparator(), 0);
while (j.hasNext()) {
hash = j.next();
pos = hs.get(hash);
if (pos == null) {
- remainingHashes.add(hash);
+ try {
+ remainingHashes.put(hash);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
} else {
p = pos.intValue();
if (p > maxpos) maxpos = p;
diff --git a/source/de/anomic/search/blockrank/CRProcess.java b/source/de/anomic/search/blockrank/CRProcess.java
index fe02dd917..8ae828307 100644
--- a/source/de/anomic/search/blockrank/CRProcess.java
+++ b/source/de/anomic/search/blockrank/CRProcess.java
@@ -433,7 +433,7 @@ public class CRProcess {
CloneableIterator<Row.Entry> cr_entry;
while (i.hasNext()) {
keycollection = i.next();
- referee = keycollection.getTermHashAsString();
+ referee = new String(keycollection.getTermHash());
if (referee.length() == 6) refereeDom = referee; else refereeDom = referee.substring(6);
cr_entry = keycollection.rows();
diff --git a/source/de/anomic/yacy/dht/Dispatcher.java b/source/de/anomic/yacy/dht/Dispatcher.java
index 6571260b1..2d81f6fb9 100755
--- a/source/de/anomic/yacy/dht/Dispatcher.java
+++ b/source/de/anomic/yacy/dht/Dispatcher.java
@@ -27,13 +27,14 @@ package de.anomic.yacy.dht;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
+import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.WordReference;
import net.yacy.kelondro.data.word.WordReferenceRow;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
@@ -193,15 +194,13 @@ public class Dispatcher {
final ArrayList<ReferenceContainer<WordReference>> rc;
if (ram) {
// selection was only from ram, so we have to carefully remove only the selected entries
- HashSet<String> urlHashes = new HashSet<String>();
+ HandleSet urlHashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
Iterator<WordReference> it;
for (ReferenceContainer<WordReference> c: containers) {
urlHashes.clear();
it = c.entries();
- while (it.hasNext()) {
- urlHashes.add(it.next().metadataHash());
- }
- if (this.log.isFine()) this.log.logFine("selected " + urlHashes.size() + " urls for word '" + c.getTermHashAsString() + "'");
+ while (it.hasNext()) try { urlHashes.put(it.next().metadataHash()); } catch (RowSpaceExceededException e) { Log.logException(e); }
+ if (this.log.isFine()) this.log.logFine("selected " + urlHashes.size() + " urls for word '" + new String(c.getTermHash()) + "'");
if (!urlHashes.isEmpty()) this.segment.termIndex().remove(c.getTermHash(), urlHashes);
}
rc = containers;
@@ -212,7 +211,7 @@ public class Dispatcher {
for (ReferenceContainer<WordReference> c: containers) {
container = this.segment.termIndex().delete(c.getTermHash()); // be aware this might be null!
if (container != null && !container.isEmpty()) {
- if (this.log.isFine()) this.log.logFine("selected " + container.size() + " urls for word '" + c.getTermHashAsString() + "'");
+ if (this.log.isFine()) this.log.logFine("selected " + container.size() + " urls for word '" + new String(c.getTermHash()) + "'");
rc.add(container);
}
}
diff --git a/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java b/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java
index 0d76ee975..3b4720bf1 100755
--- a/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java
+++ b/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java
@@ -83,7 +83,7 @@ public class FlatWordPartitionScheme implements PartitionScheme {
return l;
}
- public int verticalPosition(String urlHash) {
+ public int verticalPosition(byte[] urlHash) {
return 0; // this is not a method stub, this is actually true for all FlatWordPartitionScheme
}
diff --git a/source/de/anomic/yacy/dht/PartitionScheme.java b/source/de/anomic/yacy/dht/PartitionScheme.java
index 212bcaa20..c897f41b0 100755
--- a/source/de/anomic/yacy/dht/PartitionScheme.java
+++ b/source/de/anomic/yacy/dht/PartitionScheme.java
@@ -64,7 +64,7 @@ public interface PartitionScheme {
public long dhtPosition(final byte[] wordHash, final int verticalPosition);
- public int verticalPosition(final String urlHash);
+ public int verticalPosition(final byte[] urlHash);
public long[] dhtPositions(final byte[] wordHash);
diff --git a/source/de/anomic/yacy/dht/Transmission.java b/source/de/anomic/yacy/dht/Transmission.java
index 5ba51d695..45174813a 100644
--- a/source/de/anomic/yacy/dht/Transmission.java
+++ b/source/de/anomic/yacy/dht/Transmission.java
@@ -25,15 +25,17 @@
package de.anomic.yacy.dht;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
+import java.util.TreeMap;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.WordReference;
+import net.yacy.kelondro.data.word.WordReferenceRow;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
+import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.rwi.ReferenceContainerCache;
import net.yacy.kelondro.workflow.WorkflowJob;
@@ -84,8 +86,8 @@ public class Transmission {
*/
private final byte[] primaryTarget;
private final ReferenceContainerCache<WordReference> containers;
- private final HashMap<String, URIMetadataRow> references;
- private final HashSet<String> badReferences;
+ private final TreeMap<byte[], URIMetadataRow> references;
+ private final HandleSet badReferences;
private final ArrayList<yacySeed> targets;
private int hit, miss;
@@ -104,8 +106,8 @@ public class Transmission {
super();
this.primaryTarget = primaryTarget;
this.containers = new ReferenceContainerCache<WordReference>(Segment.wordReferenceFactory, payloadrow, Segment.wordOrder);
- this.references = new HashMap<String, URIMetadataRow>();
- this.badReferences = new HashSet<String>();
+ this.references = new TreeMap<byte[], URIMetadataRow>(Base64Order.enhancedCoder);
+ this.badReferences = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, 0);
this.targets = targets;
this.hit = 0;
this.miss = 0;
@@ -120,24 +122,24 @@ public class Transmission {
public void add(ReferenceContainer<WordReference> container) throws RowSpaceExceededException {
// iterate through the entries in the container and check if the reference is in the repository
Iterator<WordReference> i = container.entries();
- ArrayList<String> notFound = new ArrayList<String>();
+ ArrayList<byte[]> notFoundx = new ArrayList<byte[]>();
while (i.hasNext()) {
WordReference e = i.next();
if (references.containsKey(e.metadataHash())) continue;
- if (badReferences.contains(e.metadataHash())) {
- notFound.add(e.metadataHash());
+ if (badReferences.has(e.metadataHash())) {
+ notFoundx.add(e.metadataHash());
continue;
}
- URIMetadataRow r = segment.urlMetadata().load(e.metadataHash().getBytes(), null, 0);
+ URIMetadataRow r = segment.urlMetadata().load(e.metadataHash(), null, 0);
if (r == null) {
- notFound.add(e.metadataHash());
- badReferences.add(e.metadataHash());
+ notFoundx.add(e.metadataHash());
+ badReferences.put(e.metadataHash());
} else {
references.put(e.metadataHash(), r);
}
}
// now delete all references that were not found
- for (String s : notFound) container.remove(s);
+ for (byte[] b : notFoundx) container.removeReference(b);
// finally add the remaining container to the cache
containers.add(container);
}
@@ -204,7 +206,7 @@ public class Transmission {
Iterator<ReferenceContainer<WordReference>> i = this.containers.iterator();
ReferenceContainer<WordReference> firstContainer = (i == null) ? null : i.next();
log.logInfo("Index transfer of " + this.containers.size() +
- " words [" + ((firstContainer == null) ? null : firstContainer.getTermHashAsString()) + " .. " + new String(this.primaryTarget) + "]" +
+ " words [" + ((firstContainer == null) ? null : new String(firstContainer.getTermHash())) + " .. " + new String(this.primaryTarget) + "]" +
" and " + this.references.size() + " URLs" +
" to peer " + target.getName() + ":" + target.hash +
" in " + (transferTime / 1000) +
diff --git a/source/de/anomic/yacy/dht/VerticalWordPartitionScheme.java b/source/de/anomic/yacy/dht/VerticalWordPartitionScheme.java
index 92b94f7f9..e089da43a 100755
--- a/source/de/anomic/yacy/dht/VerticalWordPartitionScheme.java
+++ b/source/de/anomic/yacy/dht/VerticalWordPartitionScheme.java
@@ -80,11 +80,11 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
return (FlatWordPartitionScheme.std.dhtPosition(wordHash, null) & partitionMask) | verticalMask;
}
- public final int verticalPosition(final String urlHash) {
+ public final int verticalPosition(final byte[] urlHash) {
assert urlHash != null;
if (urlHash == null || partitionExponent < 1) return 0;
assert partitionExponent > 0;
- return (int) (FlatWordPartitionScheme.std.dhtPosition(urlHash.getBytes(), null) >> (Long.SIZE - 1 - partitionExponent)); // take only the top-<partitionExponent> bits
+ return (int) (FlatWordPartitionScheme.std.dhtPosition(urlHash, null) >> (Long.SIZE - 1 - partitionExponent)); // take only the top-<partitionExponent> bits
}
/**
diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java
index 23a6d3f11..759977ef2 100644
--- a/source/de/anomic/yacy/yacyClient.java
+++ b/source/de/anomic/yacy/yacyClient.java
@@ -578,8 +578,8 @@ public final class yacyClient {
// the search-result-url transports all the attributes of word indexes
entry = urlEntry.word();
- if (!Base64Order.enhancedCoder.equal(entry.metadataHash().getBytes(), urlEntry.hash())) {
- if (yacyCore.log.isInfo()) yacyCore.log.logInfo("remote search (client): url-hash " + new String(urlEntry.hash()) + " does not belong to word-attached-hash " + entry.metadataHash() + "; url = " + metadata.url() + " from peer " + target.getName());
+ if (!Base64Order.enhancedCoder.equal(entry.metadataHash(), urlEntry.hash())) {
+ if (yacyCore.log.isInfo()) yacyCore.log.logInfo("remote search (client): url-hash " + new String(urlEntry.hash()) + " does not belong to word-attached-hash " + new String(entry.metadataHash()) + "; url = " + metadata.url() + " from peer " + target.getName());
continue; // spammed
}
@@ -880,7 +880,7 @@ public final class yacyClient {
public static String transferIndex(
final yacySeed targetSeed,
final ReferenceContainerCache<WordReference> indexes,
- final HashMap<String, URIMetadataRow> urlCache,
+ final TreeMap<byte[], URIMetadataRow> urlCache,
final boolean gzipBody,
final int timeout) {
@@ -896,7 +896,7 @@ public final class yacyClient {
while (eenum.hasNext()) {
entry = eenum.next();
if (urlCache.get(entry.metadataHash()) == null) {
- if (yacyCore.log.isFine()) yacyCore.log.logFine("DEBUG transferIndex: to-send url hash '" + entry.metadataHash() + "' is not contained in urlCache");
+ if (yacyCore.log.isFine()) yacyCore.log.logFine("DEBUG transferIndex: to-send url hash '" + new String(entry.metadataHash()) + "' is not contained in urlCache");
}
}
}
@@ -934,7 +934,7 @@ public final class yacyClient {
// extract the urlCache from the result
final URIMetadataRow[] urls = new URIMetadataRow[uhs.length];
for (int i = 0; i < uhs.length; i++) {
- urls[i] = urlCache.get(uhs[i]);
+ urls[i] = urlCache.get(uhs[i].getBytes());
if (urls[i] == null) {
if (yacyCore.log.isFine()) yacyCore.log.logFine("DEBUG transferIndex: requested url hash '" + uhs[i] + "', unknownURL='" + uhss + "'");
}
@@ -990,7 +990,7 @@ public final class yacyClient {
eenum = ic.entries();
while (eenum.hasNext()) {
entry = eenum.next();
- entrypost.append(ic.getTermHashAsString())
+ entrypost.append(new String(ic.getTermHash()))
.append(entry.toPropertyForm())
.append(serverCore.CRLF_STRING);
indexcount++;
diff --git a/source/de/anomic/yacy/yacySearch.java b/source/de/anomic/yacy/yacySearch.java
index 3a85b8a13..6f0e2bf9d 100644
--- a/source/de/anomic/yacy/yacySearch.java
+++ b/source/de/anomic/yacy/yacySearch.java
@@ -29,9 +29,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
-import java.util.TreeSet;
import java.util.regex.Pattern;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.util.ScoreCluster;
@@ -135,13 +135,20 @@ public class yacySearch extends Thread {
containerCache.oneFeederTerminated();
}
}
-
+ /*
public static String set2string(final TreeSet<byte[]> hashes) {
String wh = "";
final Iterator<byte[]> iter = hashes.iterator();
while (iter.hasNext()) { wh = wh + new String(iter.next()); }
return wh;
}
+ */
+ public static String set2string(final HandleSet hashes) {
+ String wh = "";
+ final Iterator<byte[]> iter = hashes.iterator();
+ while (iter.hasNext()) { wh = wh + new String(iter.next()); }
+ return wh;
+ }
public int links() {
return this.urls.length;
@@ -176,7 +183,7 @@ public class yacySearch extends Thread {
//return (yacySeed[]) l.toArray();
}
- private static yacySeed[] selectSearchTargets(final yacySeedDB seedDB, final TreeSet<byte[]> wordhashes, int seedcount, int redundancy) {
+ private static yacySeed[] selectSearchTargets(final yacySeedDB seedDB, final HandleSet wordhashes, int seedcount, int redundancy) {
// find out a specific number of seeds, that would be relevant for the given word hash(es)
// the result is ordered by relevance: [0] is most relevant
// the seedcount is the maximum number of wanted results
diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java
index 55bff6454..791c6c866 100644
--- a/source/de/anomic/yacy/yacySeed.java
+++ b/source/de/anomic/yacy/yacySeed.java
@@ -54,10 +54,10 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
-import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.kelondro.data.word.Word;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.DateFormatter;
@@ -574,13 +574,13 @@ public class yacySeed implements Cloneable {
return MapTools.string2set(get(PEERTAGS, "*"), "|");
}
- public boolean matchPeerTags(final TreeSet<byte[]> searchHashes) {
+ public boolean matchPeerTags(final HandleSet searchHashes) {
final String peertags = get(PEERTAGS, "");
if (peertags.equals("*")) return true;
final Set<String> tags = MapTools.string2set(peertags, "|");
final Iterator<String> i = tags.iterator();
while (i.hasNext()) {
- if (searchHashes.contains(Word.word2hash(i.next()))) return true;
+ if (searchHashes.has(Word.word2hash(i.next()))) return true;
}
return false;
}
@@ -836,7 +836,7 @@ public class yacySeed implements Cloneable {
}
public static final String isProperIP(final String ipString) {
- // returns null if ipString is proper, a string with the cause otervise
+ // returns null if ipString is proper, a string with the cause otherwise
if (ipString == null) return "IP is null";
if (ipString.length() > 0 && ipString.length() < 8) return "IP is too short: " + ipString;
if (!natLib.isProper(ipString)) return "IP is not proper: " + ipString; //this does not work with staticIP
diff --git a/source/net/yacy/document/Condenser.java b/source/net/yacy/document/Condenser.java
index cb10d58e4..830a1178c 100644
--- a/source/net/yacy/document/Condenser.java
+++ b/source/net/yacy/document/Condenser.java
@@ -234,7 +234,7 @@ public final class Condenser {
}
int pip = 0;
while (wordenum.hasMoreElements()) {
- word = (new String(wordenum.nextElement())).toLowerCase(Locale.ENGLISH);
+ word = (wordenum.nextElement().toString()).toLowerCase(Locale.ENGLISH);
if (useForLanguageIdentification) languageIdentificator.add(word);
if (word.length() < 3) continue;
wprop = words.get(word);
@@ -305,7 +305,7 @@ public final class Condenser {
// read source
final sievedWordsEnum wordenum = new sievedWordsEnum(is);
while (wordenum.hasMoreElements()) {
- word = (new String(wordenum.nextElement())).toLowerCase(Locale.ENGLISH); // TODO: does toLowerCase work for non ISO-8859-1 chars?
+ word = (wordenum.nextElement().toString()).toLowerCase(Locale.ENGLISH); // TODO: does toLowerCase work for non ISO-8859-1 chars?
if (languageIdentificator != null) languageIdentificator.add(word);
if (word.length() < wordminsize) continue;
@@ -485,7 +485,7 @@ public final class Condenser {
byte[] hash;
while (words.hasMoreElements()) {
word = words.nextElement();
- hash = Word.word2hash(new String(word));
+ hash = Word.word2hash(word.toString());
if (!map.containsKey(hash)) map.put(hash, Integer.valueOf(pos)); // don't overwrite old values, that leads to too far word distances
pos += word.length() + 1;
}
diff --git a/source/net/yacy/kelondro/blob/Compressor.java b/source/net/yacy/kelondro/blob/Compressor.java
index 8a7fbe1a0..925f5c60d 100644
--- a/source/net/yacy/kelondro/blob/Compressor.java
+++ b/source/net/yacy/kelondro/blob/Compressor.java
@@ -77,17 +77,14 @@ public class Compressor implements BLOB {
this.key = key;
this.payload = payload;
}
- @Override
public String getKey() {
return this.key;
}
- @Override
public byte[] getValue() {
return this.payload;
}
- @Override
public byte[] setValue(byte[] payload) {
byte[] payload0 = payload;
this.payload = payload;
@@ -141,11 +138,7 @@ public class Compressor implements BLOB {
public synchronized void close(boolean writeIDX) {
// no more thread is running, flush all queues
- try {
- flushAll();
- } catch (IOException e) {
- Log.logSevere("Compressor", "", e);
- }
+ flushAll();
for (int i = 0; i < this.worker.length; i++) try {
this.writeQueue.put(poisonWorkerEntry);
} catch (InterruptedException e) {
@@ -294,13 +287,8 @@ public class Compressor implements BLOB {
if (this.bufferlength + b.length * 2 > this.maxbufferlength) synchronized (this) {
// in case that we compress, just compress as much as is necessary to get enough room
while (this.bufferlength + b.length * 2 > this.maxbufferlength) {
- try {
- if (this.buffer.isEmpty()) break;
- flushOne();
- } catch (RowSpaceExceededException e) {
- Log.logException(e);
- break;
- }
+ if (this.buffer.isEmpty()) break;
+ flushOne();
}
// in case that this was not enough, just flush all
if (this.bufferlength + b.length * 2 > this.maxbufferlength) flushAll();
@@ -341,7 +329,7 @@ public class Compressor implements BLOB {
return this.backend.keys(up, firstKey);
}
- private boolean flushOne() throws IOException, RowSpaceExceededException {
+ private boolean flushOne() {
if (this.buffer.isEmpty()) return false;
// depending on process case, write it to the file or compress it to the other queue
Map.Entry<String, byte[]> entry = this.buffer.entrySet().iterator().next();
@@ -356,14 +344,9 @@ public class Compressor implements BLOB {
}
}
- private void flushAll() throws IOException {
+ private void flushAll() {
while (!this.buffer.isEmpty()) {
- try {
- if (!flushOne()) break;
- } catch (RowSpaceExceededException e) {
- Log.logException(e);
- break;
- }
+ if (!flushOne()) break;
}
assert this.bufferlength == 0;
}
diff --git a/source/net/yacy/kelondro/blob/HeapReader.java b/source/net/yacy/kelondro/blob/HeapReader.java
index 16ab8152b..970137dfe 100644
--- a/source/net/yacy/kelondro/blob/HeapReader.java
+++ b/source/net/yacy/kelondro/blob/HeapReader.java
@@ -292,13 +292,17 @@ public class HeapReader {
* the number of BLOBs in the heap
* @return the number of BLOBs in the heap
*/
- public synchronized int size() {
- return (this.index == null) ? 0 : this.index.size();
+ public int size() {
+ synchronized (index) {
+ return (this.index == null) ? 0 : this.index.size();
+ }
}
- public synchronized boolean isEmpty() {
+ public boolean isEmpty() {
if (this.index == null) return true;
- return this.index.isEmpty();
+ synchronized (index) {
+ return this.index.isEmpty();
+ }
}
/**
@@ -310,7 +314,7 @@ public class HeapReader {
assert index != null;
key = normalizeKey(key);
- synchronized (this) {
+ synchronized (this.index) {
// check if the file index contains the key
return index.get(key) >= 0;
}
@@ -328,7 +332,9 @@ public class HeapReader {
* @throws IOException
*/
protected synchronized byte[] firstKey() throws IOException {
- return index.smallestKey();
+ synchronized (this.index) {
+ return index.smallestKey();
+ }
}
/**
@@ -338,10 +344,12 @@ public class HeapReader {
* @return the entry which key is the smallest in the heap
* @throws IOException
*/
- protected synchronized byte[] first() throws IOException {
- byte[] key = index.smallestKey();
- if (key == null) return null;
- return get(key);
+ protected byte[] first() throws IOException {
+ synchronized (this.index) {
+ byte[] key = index.smallestKey();
+ if (key == null) return null;
+ return get(key);
+ }
}
/**
@@ -351,8 +359,10 @@ public class HeapReader {
* @return the largest key in the heap
* @throws IOException
*/
- protected synchronized byte[] lastKey() throws IOException {
- return index.largestKey();
+ protected byte[] lastKey() throws IOException {
+ synchronized (this.index) {
+ return index.largestKey();
+ }
}
/**
@@ -362,10 +372,12 @@ public class HeapReader {
* @return the entry which key is the smallest in the heap
* @throws IOException
*/
- protected synchronized byte[] last() throws IOException {
- byte[] key = index.largestKey();
- if (key == null) return null;
- return get(key);
+ protected byte[] last() throws IOException {
+ synchronized (this.index) {
+ byte[] key = index.largestKey();
+ if (key == null) return null;
+ return get(key);
+ }
}
/**
@@ -377,7 +389,7 @@ public class HeapReader {
public byte[] get(byte[] key) throws IOException {
key = normalizeKey(key);
- synchronized (this) {
+ synchronized (this.index) {
// check if the index contains the key
final long pos = index.get(key);
if (pos < 0) return null;
@@ -429,7 +441,7 @@ public class HeapReader {
public long length(byte[] key) throws IOException {
key = normalizeKey(key);
- synchronized (this) {
+ synchronized (this.index) {
// check if the index contains the key
final long pos = index.get(key);
if (pos < 0) return -1;
@@ -443,42 +455,44 @@ public class HeapReader {
/**
* close the BLOB table
*/
- public synchronized void close(boolean writeIDX) {
- if (file != null)
- try {
- file.close();
- } catch (IOException e) {
- Log.logException(e);
- }
- file = null;
- if (writeIDX && index != null && free != null && (index.size() > 3 || free.size() > 3)) {
- // now we can create a dump of the index and the gap information
- // to speed up the next start
- try {
- long start = System.currentTimeMillis();
- String fingerprint = HeapWriter.fingerprintFileHash(this.heapFile);
- if (fingerprint == null) {
- Log.logSevere("kelondroBLOBHeap", "cannot write a dump for " + heapFile.getName()+ ": fingerprint is null");
- } else {
- free.dump(HeapWriter.fingerprintGapFile(this.heapFile, fingerprint));
+ public void close(boolean writeIDX) {
+ synchronized (this.index) {
+ if (file != null)
+ try {
+ file.close();
+ } catch (IOException e) {
+ Log.logException(e);
+ }
+ file = null;
+ if (writeIDX && index != null && free != null && (index.size() > 3 || free.size() > 3)) {
+ // now we can create a dump of the index and the gap information
+ // to speed up the next start
+ try {
+ long start = System.currentTimeMillis();
+ String fingerprint = HeapWriter.fingerprintFileHash(this.heapFile);
+ if (fingerprint == null) {
+ Log.logSevere("kelondroBLOBHeap", "cannot write a dump for " + heapFile.getName()+ ": fingerprint is null");
+ } else {
+ free.dump(HeapWriter.fingerprintGapFile(this.heapFile, fingerprint));
+ }
+ free.clear();
+ free = null;
+ if (fingerprint != null) {
+ index.dump(HeapWriter.fingerprintIndexFile(this.heapFile, fingerprint));
+ Log.logInfo("kelondroBLOBHeap", "wrote a dump for the " + this.index.size() + " index entries of " + heapFile.getName()+ " in " + (System.currentTimeMillis() - start) + " milliseconds.");
+ }
+ index.close();
+ index = null;
+ } catch (IOException e) {
+ Log.logException(e);
}
- free.clear();
+ } else {
+ // this is small.. just free resources, do not write index
+ if (free != null) free.clear();
free = null;
- if (fingerprint != null) {
- index.dump(HeapWriter.fingerprintIndexFile(this.heapFile, fingerprint));
- Log.logInfo("kelondroBLOBHeap", "wrote a dump for the " + this.index.size() + " index entries of " + heapFile.getName()+ " in " + (System.currentTimeMillis() - start) + " milliseconds.");
- }
- index.close();
+ if (index != null) index.close();
index = null;
- } catch (IOException e) {
- Log.logException(e);
}
- } else {
- // this is small.. just free resources, do not write index
- if (free != null) free.clear();
- free = null;
- if (index != null) index.close();
- index = null;
}
}
@@ -506,8 +520,10 @@ public class HeapReader {
* @return
* @throws IOException
*/
- public synchronized CloneableIterator<byte[]> keys(final boolean up, final boolean rotating) throws IOException {
- return new RotateIterator<byte[]>(this.index.keys(up, null), null, this.index.size());
+ public CloneableIterator<byte[]> keys(final boolean up, final boolean rotating) throws IOException {
+ synchronized (this.index) {
+ return new RotateIterator<byte[]>(this.index.keys(up, null), null, this.index.size());
+ }
}
/**
@@ -517,12 +533,16 @@ public class HeapReader {
* @return
* @throws IOException
*/
- public synchronized CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
- return this.index.keys(up, firstKey);
+ public CloneableIterator<byte[]> keys(final boolean up, final byte[] firstKey) throws IOException {
+ synchronized (this.index) {
+ return this.index.keys(up, firstKey);
+ }
}
public long length() {
- return this.heapFile.length();
+ synchronized (this.index) {
+ return this.heapFile.length();
+ }
}
/**
diff --git a/source/net/yacy/kelondro/blob/HeapWriter.java b/source/net/yacy/kelondro/blob/HeapWriter.java
index bf7fc81d7..1f9f90af8 100644
--- a/source/net/yacy/kelondro/blob/HeapWriter.java
+++ b/source/net/yacy/kelondro/blob/HeapWriter.java
@@ -96,7 +96,6 @@ public final class HeapWriter {
* @throws RowSpaceExceededException
*/
public synchronized void add(byte[] key, final byte[] blob) throws IOException, RowSpaceExceededException {
- //System.out.println("HeapWriter.add: " + new String(key));
assert blob.length > 0;
key = HeapReader.normalizeKey(key, this.keylength);
assert index.row().primaryKeyLength == this.keylength : index.row().primaryKeyLength + "!=" + key.length;
@@ -108,7 +107,6 @@ public final class HeapWriter {
os.writeInt(chunkl);
os.write(key);
os.write(blob);
- //assert (this.doublecheck.add(new String(key))) : "doublecheck failed for " + new String(key);
this.seek += chunkl + 4;
//os.flush(); // necessary? may cause bad IO performance :-(
}
diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.java
index 3d621ef4c..0b71083ab 100644
--- a/source/net/yacy/kelondro/blob/Tables.java
+++ b/source/net/yacy/kelondro/blob/Tables.java
@@ -347,7 +347,7 @@ public class Tables {
return new RowIterator(table, wherePattern);
}
- public Collection<Row> orderByPK(Iterator<Row> rowIterator, int maxcount) throws IOException {
+ public Collection<Row> orderByPK(Iterator<Row> rowIterator, int maxcount) {
TreeMap<String, Row> sortTree = new TreeMap<String, Row>();
Row row;
while ((maxcount < 0 || maxcount-- > 0) && rowIterator.hasNext()) {
@@ -357,7 +357,7 @@ public class Tables {
return sortTree.values();
}
- public Collection<Row> orderBy(Iterator<Row> rowIterator, int maxcount, String sortColumn) throws IOException {
+ public Collection<Row> orderBy(Iterator<Row> rowIterator, int maxcount, String sortColumn) {
TreeMap<String, Row> sortTree = new TreeMap<String, Row>();
Row row;
byte[] r;
diff --git a/source/net/yacy/kelondro/data/citation/CitationReferenceRow.java b/source/net/yacy/kelondro/data/citation/CitationReferenceRow.java
index 7cccd53c4..dd6b6dc42 100644
--- a/source/net/yacy/kelondro/data/citation/CitationReferenceRow.java
+++ b/source/net/yacy/kelondro/data/citation/CitationReferenceRow.java
@@ -132,8 +132,8 @@ public final class CitationReferenceRow implements Reference /*, Cloneable*/ {
return this.entry;
}
- public String metadataHash() {
- return this.entry.getColString(col_urlhash, null);
+ public byte[] metadataHash() {
+ return this.entry.getColBytes(col_urlhash, true);
}
public int virtualAge() {
@@ -181,7 +181,7 @@ public final class CitationReferenceRow implements Reference /*, Cloneable*/ {
@Override
public int hashCode() {
- return this.metadataHash().hashCode();
+ return new String(this.metadataHash()).hashCode();
}
@Override
@@ -190,7 +190,7 @@ public final class CitationReferenceRow implements Reference /*, Cloneable*/ {
if (obj == null) return false;
if (!(obj instanceof CitationReferenceRow)) return false;
CitationReferenceRow other = (CitationReferenceRow) obj;
- return this.metadataHash().equals(other.metadataHash());
+ return Base64Order.enhancedCoder.equal(this.metadataHash(), other.metadataHash());
}
public int distance() {
diff --git a/source/net/yacy/kelondro/data/image/ImageReferenceRow.java b/source/net/yacy/kelondro/data/image/ImageReferenceRow.java
index dda91c319..f701d2a96 100644
--- a/source/net/yacy/kelondro/data/image/ImageReferenceRow.java
+++ b/source/net/yacy/kelondro/data/image/ImageReferenceRow.java
@@ -104,7 +104,7 @@ public final class ImageReferenceRow extends AbstractReference implements /*Imag
private final Row.Entry entry;
- public ImageReferenceRow(final String urlHash,
+ public ImageReferenceRow(final byte[] urlHash,
final int urlLength, // byte-length of complete URL
final int urlComps, // number of path components
final int titleLength, // length of description/length (longer are better?)
@@ -123,11 +123,11 @@ public final class ImageReferenceRow extends AbstractReference implements /*Imag
final Bitfield flags // attributes to the url and to the word according the url
) {
- assert (urlHash.length() == 12) : "urlhash = " + urlHash;
+ assert (urlHash.length == 12) : "urlhash = " + urlHash;
this.entry = urlEntryRow.newEntry();
final int mddlm = MicroDate.microDateDays(lastmodified);
final int mddct = MicroDate.microDateDays(updatetime);
- this.entry.setCol(col_urlhash, urlHash, null);
+ this.entry.setCol(col_urlhash, urlHash);
this.entry.setCol(col_lastModified, mddlm);
this.entry.setCol(col_freshUntil, Math.max(0, mddlm + (mddct - mddlm) * 2)); // TTL computation
this.entry.setCol(col_doctype, new byte[]{(byte) doctype});
@@ -205,8 +205,8 @@ public final class ImageReferenceRow extends AbstractReference implements /*Imag
return this.entry;
}
- public String metadataHash() {
- return this.entry.getColString(col_urlhash, null);
+ public byte[] metadataHash() {
+ return this.entry.getColBytes(col_urlhash, true);
}
public int virtualAge() {
@@ -270,7 +270,7 @@ public final class ImageReferenceRow extends AbstractReference implements /*Imag
}
public int hashCode() {
- return this.metadataHash().hashCode();
+ return new String(this.metadataHash()).hashCode();
}
public void join(Reference oe) {
diff --git a/source/net/yacy/kelondro/data/image/ImageReferenceVars.java b/source/net/yacy/kelondro/data/image/ImageReferenceVars.java
index ce4212e7c..37897de65 100644
--- a/source/net/yacy/kelondro/data/image/ImageReferenceVars.java
+++ b/source/net/yacy/kelondro/data/image/ImageReferenceVars.java
@@ -45,7 +45,8 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere
public Bitfield flags;
public long lastModified;
- public String language, urlHash;
+ public byte[] urlHash;
+ public String language;
public char type;
public int hitcount, llocal, lother, phrasesintext,
posinphrase, posofphrase,
@@ -55,7 +56,7 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere
public double termFrequency;
public ImageReferenceVars(
- final String urlHash,
+ final byte[] urlHash,
final int urlLength, // byte-length of complete URL
final int urlComps, // number of path components
final int titleLength, // length of description/length (longer are better?)
@@ -267,7 +268,7 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere
return toRowEntry().toPropertyForm();
}
- public String metadataHash() {
+ public byte[] metadataHash() {
return urlHash;
}
@@ -355,7 +356,7 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere
}
public int hashCode() {
- return this.urlHash.hashCode();
+ return new String(this.urlHash).hashCode();
}
public void addPosition(int position) {
diff --git a/source/net/yacy/kelondro/data/meta/DigestURI.java b/source/net/yacy/kelondro/data/meta/DigestURI.java
index e3f80121d..9594efc66 100644
--- a/source/net/yacy/kelondro/data/meta/DigestURI.java
+++ b/source/net/yacy/kelondro/data/meta/DigestURI.java
@@ -937,34 +937,6 @@ public class DigestURI implements Serializable {
private static String[] testTLDs = new String[] { "com", "net", "org", "uk", "fr", "de", "es", "it" };
- public static final DigestURI probablyWordURL(final byte[] urlHash, final TreeSet<String> words) {
- assert urlHash != null;
- final Iterator<String> wi = words.iterator();
- String word;
- while (wi.hasNext()) {
- word = wi.next();
- if ((word == null) || (word.length() == 0)) continue;
- final String pattern = new String(urlHash).substring(6, 11);
- for (int i = 0; i < testTLDs.length; i++) {
- if (pattern.equals(hosthash5("http", "www." + word.toLowerCase() + "." + testTLDs[i], 80)))
- try {
- return new DigestURI("http://www." + word.toLowerCase() + "." + testTLDs[i], null);
- } catch (final MalformedURLException e) {
- return null;
- }
- }
- }
- return null;
- }
-
- public static final boolean isWordRootURL(final byte[] givenURLHash, final TreeSet<String> words) {
- if (!(probablyRootURL(givenURLHash))) return false;
- final DigestURI wordURL = probablyWordURL(givenURLHash, words);
- if (wordURL == null) return false;
- if (Base64Order.enhancedCoder.equal(wordURL.hash(), givenURLHash)) return true;
- return false;
- }
-
public static final int domLengthEstimation(final byte[] urlHashBytes) {
// generates an estimation of the original domain length
assert (urlHashBytes != null);
diff --git a/source/net/yacy/kelondro/data/meta/URIMetadataRow.java b/source/net/yacy/kelondro/data/meta/URIMetadataRow.java
index fe61a9de4..37899527f 100644
--- a/source/net/yacy/kelondro/data/meta/URIMetadataRow.java
+++ b/source/net/yacy/kelondro/data/meta/URIMetadataRow.java
@@ -512,7 +512,7 @@ public class URIMetadataRow implements URIMetadata {
core.append(",snippet=").append(crypt.simpleEncode(snippet));
core.append("}");
- return new String(core);
+ return core.toString();
//return "{" + core + ",snippet=" + crypt.simpleEncode(snippet) + "}";
}
diff --git a/source/net/yacy/kelondro/data/navigation/NavigationReference.java b/source/net/yacy/kelondro/data/navigation/NavigationReference.java
index 9cb766ae2..6d0653ebc 100644
--- a/source/net/yacy/kelondro/data/navigation/NavigationReference.java
+++ b/source/net/yacy/kelondro/data/navigation/NavigationReference.java
@@ -37,9 +37,9 @@ public interface NavigationReference extends Reference {
public String navigationHash();
- public String metadataHash();
+ public byte[] metadataHash();
- public String termHash();
+ public byte[] termHash();
public int hitcount();
diff --git a/source/net/yacy/kelondro/data/navigation/NavigationReferenceRow.java b/source/net/yacy/kelondro/data/navigation/NavigationReferenceRow.java
index 0c2962575..ae2c3cda0 100644
--- a/source/net/yacy/kelondro/data/navigation/NavigationReferenceRow.java
+++ b/source/net/yacy/kelondro/data/navigation/NavigationReferenceRow.java
@@ -77,16 +77,16 @@ public final class NavigationReferenceRow extends AbstractReference implements N
private final Row.Entry entry;
public NavigationReferenceRow(
- final String termhash,
- final String refhash,
+ final byte[] termhash,
+ final byte[] refhash,
final int count,
final int pos,
final byte flags
) {
- assert (termhash.length() == 12) : "termhash = " + termhash;
- assert (refhash.length() == 12) : "refhash = " + refhash;
+ assert (termhash.length == 12) : "termhash = " + new String(termhash);
+ assert (refhash.length == 12) : "refhash = " + new String(refhash);
this.entry = navEntryRow.newEntry();
- this.entry.setCol(col_navhash, termhash + refhash, null);
+ this.entry.setCol(col_navhash, new String(termhash) + new String(refhash), null);
this.entry.setCol(col_count, count);
this.entry.setCol(col_pos, pos);
this.entry.setCol(col_flags, flags);
@@ -119,12 +119,12 @@ public final class NavigationReferenceRow extends AbstractReference implements N
return this.entry.getColString(col_navhash, null);
}
- public String metadataHash() {
- return navigationHash().substring(12);
+ public byte[] metadataHash() {
+ return navigationHash().substring(12).getBytes();
}
- public String termHash() {
- return navigationHash().substring(0, 12);
+ public byte[] termHash() {
+ return navigationHash().substring(0, 12).getBytes();
}
public int hitcount() {
diff --git a/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java b/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java
index 8910f1424..fd6f92b78 100644
--- a/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java
+++ b/source/net/yacy/kelondro/data/navigation/NavigationReferenceVars.java
@@ -32,13 +32,13 @@ import net.yacy.kelondro.rwi.Reference;
public class NavigationReferenceVars extends AbstractReference implements NavigationReference, Reference, Cloneable {
- public String refhash, termhash;
+ public byte[] termhash, refhash;
public int hitcount, position;
byte flags;
public NavigationReferenceVars(
- final String termhash,
- final String refhash,
+ final byte[] termhash,
+ final byte[] refhash,
final int count,
final int pos,
final byte flags
@@ -88,14 +88,14 @@ public class NavigationReferenceVars extends AbstractReference implements Navig
}
public String navigationHash() {
- return this.termhash + this.refhash;
+ return new String(this.termhash) + new String(this.refhash);
}
- public String metadataHash() {
+ public byte[] metadataHash() {
return this.refhash;
}
- public String termHash() {
+ public byte[] termHash() {
return this.termhash;
}
diff --git a/source/net/yacy/kelondro/data/word/Word.java b/source/net/yacy/kelondro/data/word/Word.java
index ea91b84d3..21657fd0e 100644
--- a/source/net/yacy/kelondro/data/word/Word.java
+++ b/source/net/yacy/kelondro/data/word/Word.java
@@ -30,10 +30,12 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
-import java.util.TreeSet;
import net.yacy.kelondro.index.ARC;
import net.yacy.kelondro.index.ConcurrentARC;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
+import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.order.Digest;
@@ -103,22 +105,27 @@ public class Word {
return h;
}
- public static final TreeSet<byte[]> words2hashSet(final String[] words) {
- final TreeSet<byte[]> hashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
- for (int i = 0; i < words.length; i++) hashes.add(word2hash(words[i]));
+ public static final HandleSet words2hashesHandles(final Set<String> words) {
+ final HandleSet hashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, words.size());
+ for (String word: words)
+ try {
+ hashes.put(word2hash(word));
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ return hashes;
+ }
return hashes;
}
-
- public static final String words2hashString(final String[] words) {
- final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < words.length; i++) sb.append(word2hash(words[i]));
- return new String(sb);
- }
-
- public static final TreeSet<byte[]> words2hashes(final Set<String> words) {
- final Iterator<String> i = words.iterator();
- final TreeSet<byte[]> hashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
- while (i.hasNext()) hashes.add(word2hash(i.next()));
+
+ public static final HandleSet words2hashesHandles(final String[] words) {
+ final HandleSet hashes = new HandleSet(WordReferenceRow.urlEntryRow.primaryKeyLength, WordReferenceRow.urlEntryRow.objectOrder, words.length);
+ for (String word: words)
+ try {
+ hashes.put(word2hash(word));
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ return hashes;
+ }
return hashes;
}
}
diff --git a/source/net/yacy/kelondro/data/word/WordReferenceRow.java b/source/net/yacy/kelondro/data/word/WordReferenceRow.java
index 13fc4362f..82306a7ba 100644
--- a/source/net/yacy/kelondro/data/word/WordReferenceRow.java
+++ b/source/net/yacy/kelondro/data/word/WordReferenceRow.java
@@ -111,7 +111,8 @@ public final class WordReferenceRow extends AbstractReference implements WordRef
private final Row.Entry entry;
- public WordReferenceRow(final String urlHash,
+ public WordReferenceRow(
+ final byte[] urlHash,
final int urlLength, // byte-length of complete URL
final int urlComps, // number of path components
final int titleLength, // length of description/length (longer are better?)
@@ -130,11 +131,11 @@ public final class WordReferenceRow extends AbstractReference implements WordRef
final Bitfield flags // attributes to the url and to the word according the url
) {
- assert (urlHash.length() == 12) : "urlhash = " + urlHash;
+ assert (urlHash.length == 12) : "urlhash = " + new String(urlHash);
this.entry = urlEntryRow.newEntry();
final int mddlm = MicroDate.microDateDays(lastmodified);
final int mddct = MicroDate.microDateDays(updatetime);
- this.entry.setCol(col_urlhash, urlHash, null);
+ this.entry.setCol(col_urlhash, urlHash);
this.entry.setCol(col_lastModified, mddlm);
this.entry.setCol(col_freshUntil, Math.max(0, mddlm + (mddct - mddlm) * 2)); // TTL computation
this.entry.setCol(col_wordsInTitle, titleLength / 6); // word count estimation; TODO: change value handover to number of words
@@ -235,8 +236,8 @@ public final class WordReferenceRow extends AbstractReference implements WordRef
return this.entry;
}
- public String metadataHash() {
- return this.entry.getColString(col_urlhash, null);
+ public byte[] metadataHash() {
+ return this.entry.getColBytes(col_urlhash, true);
}
public int virtualAge() {
@@ -333,12 +334,12 @@ public final class WordReferenceRow extends AbstractReference implements WordRef
if (obj == null) return false;
if (!(obj instanceof WordReferenceRow)) return false;
WordReferenceRow other = (WordReferenceRow) obj;
- return this.metadataHash().equals(other.metadataHash());
+ return Base64Order.enhancedCoder.equal(this.metadataHash(), other.metadataHash());
}
@Override
public int hashCode() {
- return this.metadataHash().hashCode();
+ return new String(this.metadataHash()).hashCode();
}
public void join(final Reference oe) {
diff --git a/source/net/yacy/kelondro/data/word/WordReferenceVars.java b/source/net/yacy/kelondro/data/word/WordReferenceVars.java
index 42674f6f9..580c2841e 100644
--- a/source/net/yacy/kelondro/data/word/WordReferenceVars.java
+++ b/source/net/yacy/kelondro/data/word/WordReferenceVars.java
@@ -51,7 +51,8 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
public Bitfield flags;
public long lastModified;
- public String language, urlHash;
+ public String language;
+ public byte[] urlHash;
public char type;
public int hitcount, llocal, lother, phrasesintext,
posinphrase, posofphrase,
@@ -61,7 +62,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
public double termFrequency;
public WordReferenceVars(
- final String urlHash,
+ final byte[] urlHash,
final int urlLength, // byte-length of complete URL
final int urlComps, // number of path components
final int titleLength, // length of description/length (longer are better?)
@@ -274,7 +275,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
return toRowEntry().toPropertyForm();
}
- public String metadataHash() {
+ public byte[] metadataHash() {
return urlHash;
}
@@ -367,16 +368,16 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
if (obj == null) return false;
if (!(obj instanceof WordReferenceVars)) return false;
WordReferenceVars other = (WordReferenceVars) obj;
- return this.urlHash.equals(other.urlHash);
+ return Base64Order.enhancedCoder.equal(this.urlHash, other.urlHash);
}
@Override
public int hashCode() {
- return this.urlHash.hashCode();
+ return new String(this.urlHash).hashCode();
}
public int compareTo(final WordReferenceVars o) {
- return Base64Order.enhancedCoder.compare(this.urlHash.getBytes(), o.metadataHash().getBytes());
+ return Base64Order.enhancedCoder.compare(this.urlHash, o.metadataHash());
}
public void addPosition(final int position) {
diff --git a/source/net/yacy/kelondro/index/Cache.java b/source/net/yacy/kelondro/index/Cache.java
index 5071729f1..6813f64ef 100644
--- a/source/net/yacy/kelondro/index/Cache.java
+++ b/source/net/yacy/kelondro/index/Cache.java
@@ -98,10 +98,6 @@ public final class Cache implements ObjectIndex, Iterable<Row.Entry> {
this.hasnotDelete = 0;
}
- public final int cacheObjectChunkSize() {
- return index.row().objectsize;
- }
-
public final int writeBufferSize() {
return 0;
}
diff --git a/source/net/yacy/kelondro/index/HandleSet.java b/source/net/yacy/kelondro/index/HandleSet.java
index 25e90aa75..40d8c7898 100644
--- a/source/net/yacy/kelondro/index/HandleSet.java
+++ b/source/net/yacy/kelondro/index/HandleSet.java
@@ -37,9 +37,10 @@ import java.util.Iterator;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator;
+import net.yacy.kelondro.util.SetTools;
-public final class HandleSet implements Iterable<byte[]> {
+public final class HandleSet implements Iterable<byte[]>, Cloneable {
private final Row rowdef;
private ObjectIndex index;
@@ -54,6 +55,15 @@ public final class HandleSet implements Iterable<byte[]> {
this.index = new ObjectIndexCache(rowdef, expectedspace, initialspace);
}
+ private HandleSet(Row rowdef, ObjectIndex index) {
+ this.rowdef = rowdef;
+ this.index = index;
+ }
+
+ public HandleSet clone() {
+ return new HandleSet(this.rowdef, ((ObjectIndexCache) this.index).clone());
+ }
+
/**
* initialize a HandleSet with the content of a dump
* @param keylength
@@ -100,12 +110,20 @@ public final class HandleSet implements Iterable<byte[]> {
return c;
}
+ public ByteOrder comparator() {
+ return this.rowdef.objectOrder;
+ }
+
public final Row row() {
return index.row();
}
- public final void clear() throws IOException {
- this.index.clear();
+ public final void clear() {
+ try {
+ this.index.clear();
+ } catch (IOException e) {
+ Log.logException(e);
+ }
}
public final synchronized boolean has(final byte[] key) {
@@ -113,33 +131,58 @@ public final class HandleSet implements Iterable<byte[]> {
return index.has(key);
}
- public final synchronized int put(final byte[] key) throws IOException, RowSpaceExceededException {
+ public final void putAll(final HandleSet aset) throws RowSpaceExceededException {
+ for (byte[] b: aset) put(b);
+ }
+
+ public final synchronized void put(final byte[] key) throws RowSpaceExceededException {
assert (key != null);
final Row.Entry newentry = index.row().newEntry();
newentry.setCol(0, key);
- final Row.Entry oldentry = index.replace(newentry);
- if (oldentry == null) return -1;
- return (int) oldentry.getColLong(1);
+ try {
+ index.put(newentry);
+ } catch (IOException e) {
+ Log.logException(e);
+ }
}
- public final synchronized void putUnique(final byte[] key) throws IOException, RowSpaceExceededException {
+ public final synchronized void putUnique(final byte[] key) throws RowSpaceExceededException {
assert (key != null);
final Row.Entry newentry = this.rowdef.newEntry();
newentry.setCol(0, key);
- index.addUnique(newentry);
+ try {
+ index.addUnique(newentry);
+ } catch (IOException e) {
+ Log.logException(e);
+ }
}
- public final synchronized int remove(final byte[] key) throws IOException {
+ public final synchronized boolean remove(final byte[] key) {
assert (key != null);
- final Row.Entry indexentry = index.remove(key);
- if (indexentry == null) return -1;
- return (int) indexentry.getColLong(1);
+ Row.Entry indexentry;
+ try {
+ indexentry = index.remove(key);
+ return indexentry != null;
+ } catch (IOException e) {
+ Log.logException(e);
+ return false;
+ }
}
- public final synchronized int removeone() throws IOException {
- final Row.Entry indexentry = index.removeOne();
- if (indexentry == null) return -1;
- return (int) indexentry.getColLong(1);
+ public final synchronized byte[] removeone() {
+ Row.Entry indexentry;
+ try {
+ indexentry = index.removeOne();
+ if (indexentry == null) return null;
+ return indexentry.getColBytes(0, true);
+ } catch (IOException e) {
+ Log.logException(e);
+ return null;
+ }
+ }
+
+ public final synchronized boolean isEmpty() {
+ return index.isEmpty();
}
public final synchronized int size() {
@@ -163,5 +206,95 @@ public final class HandleSet implements Iterable<byte[]> {
index.close();
index = null;
}
+
+ // set tools
+
+ public HandleSet joinConstructive(final HandleSet other) throws RowSpaceExceededException {
+ return joinConstructive(this, other);
+ }
+
+ // now the same for set-set
+ public static HandleSet joinConstructive(final HandleSet set1, final HandleSet set2) throws RowSpaceExceededException {
+ // comparators must be equal
+ if ((set1 == null) || (set2 == null)) return null;
+ assert set1.comparator() == set2.comparator();
+ if (set1.comparator() != set2.comparator()) return null;
+ if (set1.isEmpty() || set2.isEmpty()) return new HandleSet(set1.rowdef.primaryKeyLength, set1.comparator(), 0);
+
+ // decide which method to use
+ final int high = ((set1.size() > set2.size()) ? set1.size() : set2.size());
+ final int low = ((set1.size() > set2.size()) ? set2.size() : set1.size());
+ final int stepsEnum = 10 * (high + low - 1);
+ final int stepsTest = 12 * SetTools.log2a(high) * low;
+
+ // start most efficient method
+ if (stepsEnum > stepsTest) {
+ if (set1.size() < set2.size()) return joinConstructiveByTest(set1, set2);
+ return joinConstructiveByTest(set2, set1);
+ }
+ return joinConstructiveByEnumeration(set1, set2);
+ }
+
+ private static HandleSet joinConstructiveByTest(final HandleSet small, final HandleSet large) throws RowSpaceExceededException {
+ final Iterator<byte[]> mi = small.iterator();
+ final HandleSet result = new HandleSet(small.rowdef.primaryKeyLength, small.comparator(), 0);
+ byte[] o;
+ while (mi.hasNext()) {
+ o = mi.next();
+ if (large.has(o)) result.put(o);
+ }
+ return result;
+ }
+ private static HandleSet joinConstructiveByEnumeration(final HandleSet set1, final HandleSet set2) throws RowSpaceExceededException {
+ // implement pairwise enumeration
+ final ByteOrder comp = set1.comparator();
+ final Iterator<byte[]> mi = set1.iterator();
+ final Iterator<byte[]> si = set2.iterator();
+ final HandleSet result = new HandleSet(set1.rowdef.primaryKeyLength, comp, 0);
+ int c;
+ if (mi.hasNext() && si.hasNext()) {
+ byte[] mobj = mi.next();
+ byte[] sobj = si.next();
+ while (true) {
+ c = comp.compare(mobj, sobj);
+ if (c < 0) {
+ if (mi.hasNext()) mobj = mi.next(); else break;
+ } else if (c > 0) {
+ if (si.hasNext()) sobj = si.next(); else break;
+ } else {
+ result.put(mobj);
+ if (mi.hasNext()) mobj = mi.next(); else break;
+ if (si.hasNext()) sobj = si.next(); else break;
+ }
+ }
+ }
+ return result;
+ }
+
+ public void excludeDestructive(final HandleSet other) {
+ excludeDestructive(this, other);
+ }
+
+ private static void excludeDestructive(final HandleSet set1, final HandleSet set2) {
+ if (set1 == null) return;
+ if (set2 == null) return;
+ assert set1.comparator() == set2.comparator();
+ if (set1.isEmpty() || set2.isEmpty()) return;
+
+ if (set1.size() < set2.size())
+ excludeDestructiveByTestSmallInLarge(set1, set2);
+ else
+ excludeDestructiveByTestLargeInSmall(set1, set2);
+ }
+
+ private static void excludeDestructiveByTestSmallInLarge(final HandleSet small, final HandleSet large) {
+ final Iterator<byte[]> mi = small.iterator();
+ while (mi.hasNext()) if (large.has(mi.next())) mi.remove();
+ }
+
+ private static void excludeDestructiveByTestLargeInSmall(final HandleSet large, final HandleSet small) {
+ final Iterator<byte[]> si = small.iterator();
+ while (si.hasNext()) large.remove(si.next());
+ }
}
diff --git a/source/net/yacy/kelondro/index/ObjectIndex.java b/source/net/yacy/kelondro/index/ObjectIndex.java
index 857ff41e4..0d91274d5 100644
--- a/source/net/yacy/kelondro/index/ObjectIndex.java
+++ b/source/net/yacy/kelondro/index/ObjectIndex.java
@@ -46,9 +46,9 @@ public interface ObjectIndex {
public Row row();
public boolean has(byte[] key); // use this only if there is no get in case that has returns true
public Row.Entry get(byte[] key) throws IOException;
- public Row.Entry replace(Row.Entry row) throws IOException, RowSpaceExceededException;
+ public Row.Entry replace(Row.Entry row) throws RowSpaceExceededException, IOException;
public void put(Row.Entry row) throws IOException, RowSpaceExceededException;
- public void addUnique(Row.Entry row) throws IOException, RowSpaceExceededException; // no double-check
+ public void addUnique(Row.Entry row) throws RowSpaceExceededException, IOException; // no double-check
public ArrayList<RowCollection> removeDoubles() throws IOException, RowSpaceExceededException; // removes all elements that are double (to be used after all addUnique)
public Row.Entry remove(byte[] key) throws IOException;
public Row.Entry removeOne() throws IOException;
diff --git a/source/net/yacy/kelondro/index/ObjectIndexCache.java b/source/net/yacy/kelondro/index/ObjectIndexCache.java
index 9bd0c4264..0be430c28 100644
--- a/source/net/yacy/kelondro/index/ObjectIndexCache.java
+++ b/source/net/yacy/kelondro/index/ObjectIndexCache.java
@@ -56,6 +56,17 @@ public final class ObjectIndexCache implements ObjectIndex, Iterable<Row.Entry>
reset(initialspace);
}
+ private ObjectIndexCache(final Row rowdef, RowSet index0, RowSet index1, Row.EntryComparator entryComparator) {
+ this.rowdef = rowdef;
+ this.index0 = index0;
+ this.index1 = index1;
+ this.entryComparator = entryComparator;
+ }
+
+ public ObjectIndexCache clone() {
+ return new ObjectIndexCache(this.rowdef, index0.clone(), index1.clone(), entryComparator);
+ }
+
public void clear() {
reset();
}
diff --git a/source/net/yacy/kelondro/index/RowCollection.java b/source/net/yacy/kelondro/index/RowCollection.java
index e51c47399..9469a814a 100644
--- a/source/net/yacy/kelondro/index/RowCollection.java
+++ b/source/net/yacy/kelondro/index/RowCollection.java
@@ -47,13 +47,19 @@ import net.yacy.kelondro.util.NamePrefixThreadFactory;
import net.yacy.kelondro.util.kelondroException;
-public class RowCollection implements Iterable<Row.Entry> {
+public class RowCollection implements Iterable<Row.Entry>, Cloneable {
public static final long growfactorLarge100 = 140L;
public static final long growfactorSmall100 = 120L;
private static final int isortlimit = 20;
private static int availableCPU = Runtime.getRuntime().availableProcessors();
+ private static final int exp_chunkcount = 0;
+ private static final int exp_last_read = 1;
+ private static final int exp_last_wrote = 2;
+ private static final int exp_order_type = 3;
+ private static final int exp_order_bound = 4;
+ private static final int exp_collection = 5;
public static final ExecutorService sortingthreadexecutor = (availableCPU > 1) ? Executors.newCachedThreadPool(new NamePrefixThreadFactory("sorting")) : null;
public static final ExecutorService partitionthreadexecutor = (availableCPU > 1) ? Executors.newCachedThreadPool(new NamePrefixThreadFactory("partition")) : null;
@@ -64,13 +70,6 @@ public class RowCollection implements Iterable<Row.Entry> {
protected int sortBound;
protected long lastTimeWrote;
- private static final int exp_chunkcount = 0;
- private static final int exp_last_read = 1;
- private static final int exp_last_wrote = 2;
- private static final int exp_order_type = 3;
- private static final int exp_order_bound = 4;
- private static final int exp_collection = 5;
-
public RowCollection(final RowCollection rc) {
this.rowdef = rc.rowdef;
this.chunkcache = rc.chunkcache;
@@ -128,6 +127,19 @@ public class RowCollection implements Iterable<Row.Entry> {
}
this.chunkcache = exportedCollection.getColBytes(exp_collection, false);
}
+
+ protected RowCollection(Row rowdef, byte[] chunkcache, int chunkcount, int sortBound, long lastTimeWrote) {
+ this.rowdef = rowdef;
+ this.chunkcache = new byte[chunkcache.length];
+ System.arraycopy(chunkcache, 0, this.chunkcache, 0, chunkcache.length);
+ this.chunkcount = chunkcount;
+ this.sortBound = sortBound;
+ this.lastTimeWrote = lastTimeWrote;
+ }
+
+ public RowCollection clone() {
+ return new RowCollection(this.rowdef, this.chunkcache, this.chunkcount, this.sortBound, this.lastTimeWrote);
+ }
public void reset() {
this.chunkcache = new byte[0];
@@ -551,17 +563,6 @@ public class RowCollection implements Iterable<Row.Entry> {
}
- public synchronized void select(final Set<String> keys) {
- // removes all entries but the ones given by urlselection
- if ((keys == null) || (keys.isEmpty())) return;
- final Iterator<Row.Entry> i = iterator();
- Row.Entry row;
- while (i.hasNext()) {
- row = i.next();
- if (!(keys.contains(row.getColString(0, null)))) i.remove();
- }
- }
-
public synchronized final void sort() {
assert (this.rowdef.objectOrder != null);
if (this.sortBound == this.chunkcount) return; // this is already sorted
diff --git a/source/net/yacy/kelondro/index/RowSet.java b/source/net/yacy/kelondro/index/RowSet.java
index dc0198db7..e345596f2 100644
--- a/source/net/yacy/kelondro/index/RowSet.java
+++ b/source/net/yacy/kelondro/index/RowSet.java
@@ -83,6 +83,14 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
return new RowSet(rowdef, size, chunkcache, orderbound);
}
+ private RowSet(Row rowdef, byte[] chunkcache, int chunkcount, int sortBound, long lastTimeWrote) {
+ super(rowdef, chunkcache, chunkcount, sortBound, lastTimeWrote);
+ }
+
+ public RowSet clone() {
+ return new RowSet(super.rowdef, super.chunkcache, super.chunkcount, super.sortBound, super.lastTimeWrote);
+ }
+
public void reset() {
super.reset();
}
@@ -280,7 +288,6 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
p = 0;
} else {
p = binaryPosition(first, 0, first.length); // check this to find bug in DHT selection enumeration
- //System.out.println("binaryposition for key " + new String(firstKey) + " is " + p);
}
}
@@ -340,7 +347,6 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
p = 0;
} else {
p = binaryPosition(first, 0, first.length); // check this to find bug in DHT selection enumeration
- //System.out.println("binaryposition for key " + new String(firstKey) + " is " + p);
}
}
diff --git a/source/net/yacy/kelondro/rwi/AbstractIndex.java b/source/net/yacy/kelondro/rwi/AbstractIndex.java
index 96ace1d73..d1cd203f7 100644
--- a/source/net/yacy/kelondro/rwi/AbstractIndex.java
+++ b/source/net/yacy/kelondro/rwi/AbstractIndex.java
@@ -30,9 +30,9 @@ package net.yacy.kelondro.rwi;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.Set;
import java.util.TreeSet;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Order;
@@ -45,7 +45,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
this.factory = factory;
}
- public int remove(final TreeSet<byte[]> termHashes, final byte[] urlHashBytes) throws IOException {
+ public int remove(final HandleSet termHashes, final byte[] urlHashBytes) throws IOException {
// remove the same url hashes for multiple words
// this is mainly used when correcting a index after a search
final Iterator<byte[]> i = termHashes.iterator();
@@ -91,7 +91,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
* @param urlselection
* @return map of wordhash:indexContainer
*/
- public HashMap<byte[], ReferenceContainer<ReferenceType>> searchConjunction(final TreeSet<byte[]> wordHashes, final Set<String> urlselection) {
+ public HashMap<byte[], ReferenceContainer<ReferenceType>> searchConjunction(final HandleSet wordHashes, final HandleSet urlselection) {
// first check if there is any entry that has no match; this uses only operations in ram
/*
Iterator<byte[]> i = wordHashes.iterator();
@@ -136,7 +136,7 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
* @return ReferenceContainer the join result
* @throws RowSpaceExceededException
*/
- public ReferenceContainer<ReferenceType> searchJoin(final TreeSet<byte[]> wordHashes, final Set<String> urlselection, final int maxDistance) throws RowSpaceExceededException {
+ public ReferenceContainer<ReferenceType> searchJoin(final TreeSet<byte[]> wordHashes, final HandleSet urlselection, final int maxDistance) throws RowSpaceExceededException {
// first check if there is any entry that has no match;
// this uses only operations in ram
for (byte[] wordHash: wordHashes) {
@@ -168,9 +168,9 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
}
public TermSearch<ReferenceType> query(
- final TreeSet<byte[]> queryHashes,
- final TreeSet<byte[]> excludeHashes,
- final Set<String> urlselection,
+ final HandleSet queryHashes,
+ final HandleSet excludeHashes,
+ final HandleSet urlselection,
final ReferenceFactory<ReferenceType> termFactory,
final int maxDistance) throws RowSpaceExceededException {
diff --git a/source/net/yacy/kelondro/rwi/Index.java b/source/net/yacy/kelondro/rwi/Index.java
index 10a1b365b..5cfc1af18 100644
--- a/source/net/yacy/kelondro/rwi/Index.java
+++ b/source/net/yacy/kelondro/rwi/Index.java
@@ -30,9 +30,9 @@ package net.yacy.kelondro.rwi;
import java.io.IOException;
import java.util.HashMap;
-import java.util.Set;
import java.util.TreeSet;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.order.ByteOrder;
import net.yacy.kelondro.order.CloneableIterator;
@@ -88,7 +88,7 @@ public interface Index <ReferenceType extends Reference> {
* @return the references
* @throws IOException
*/
- public ReferenceContainer<ReferenceType> get(byte[] termHash, Set<String> referenceselection) throws IOException;
+ public ReferenceContainer<ReferenceType> get(byte[] termHash, HandleSet referenceselection) throws IOException;
/**
* delete all references for a word
@@ -114,8 +114,8 @@ public interface Index <ReferenceType extends Reference> {
* @return
* @throws IOException
*/
- public int remove(final byte[] termHash, Set<String> referenceHashes) throws IOException;
- public int remove(final TreeSet<byte[]> termHashes, final byte[] urlHashBytes) throws IOException;
+ public int remove(final byte[] termHash, HandleSet referenceHashes) throws IOException;
+ public int remove(final HandleSet termHashes, final byte[] urlHashBytes) throws IOException;
/**
* iterate all references from the beginning of a specific word hash
@@ -144,7 +144,7 @@ public interface Index <ReferenceType extends Reference> {
* @param urlselection
* @return map of wordhash:indexContainer
*/
- public HashMap<byte[], ReferenceContainer<ReferenceType>> searchConjunction(final TreeSet<byte[]> wordHashes, final Set<String> urlselection);
+ public HashMap<byte[], ReferenceContainer<ReferenceType>> searchConjunction(final HandleSet wordHashes, final HandleSet urlselection);
/**
* delete all references entries
diff --git a/source/net/yacy/kelondro/rwi/IndexCell.java b/source/net/yacy/kelondro/rwi/IndexCell.java
index 1a117cc42..b1c7af1f7 100644
--- a/source/net/yacy/kelondro/rwi/IndexCell.java
+++ b/source/net/yacy/kelondro/rwi/IndexCell.java
@@ -28,13 +28,14 @@ package net.yacy.kelondro.rwi;
import java.io.File;
import java.io.IOException;
-import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Semaphore;
import de.anomic.yacy.graphics.ProfilingGraph;
+import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.index.ARC;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.index.SimpleARC;
@@ -197,7 +198,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
* @throws IOException
* @return a container with merged ReferenceContainer from RAM and the file array or null if there is no data to be returned
*/
- public ReferenceContainer<ReferenceType> get(byte[] termHash, Set<String> urlselection) throws IOException {
+ public ReferenceContainer<ReferenceType> get(byte[] termHash, HandleSet urlselection) throws IOException {
ReferenceContainer<ReferenceType> c0 = this.ram.get(termHash, null);
ReferenceContainer<ReferenceType> c1 = null;
try {
@@ -265,6 +266,13 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
* new BLOBs. This returns the sum of all url references that have been removed
* @throws IOException
*/
+ public int remove(byte[] termHash, HandleSet urlHashes) throws IOException {
+ int removed = this.ram.remove(termHash, urlHashes);
+ int reduced = this.array.replace(termHash, new RemoveRewriter<ReferenceType>(urlHashes));
+ this.countCache.remove(new ByteArray(termHash));
+ return removed + (reduced / this.array.rowdef().objectsize);
+ }
+
public int remove(byte[] termHash, Set<String> urlHashes) throws IOException {
int removed = this.ram.remove(termHash, urlHashes);
int reduced = this.array.replace(termHash, new RemoveRewriter<ReferenceType>(urlHashes));
@@ -281,15 +289,29 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
private static class RemoveRewriter<ReferenceType extends Reference> implements ReferenceContainerArray.ContainerRewriter<ReferenceType> {
- Set<String> urlHashes;
+ HandleSet urlHashes;
- public RemoveRewriter(Set<String> urlHashes) {
+ public RemoveRewriter(HandleSet urlHashes) {
this.urlHashes = urlHashes;
}
+ public RemoveRewriter(Set<String> urlHashes) {
+ this.urlHashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
+ for (String s: urlHashes)
+ try {
+ this.urlHashes.put(s.getBytes());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
+ }
+
public RemoveRewriter(byte[] urlHashBytes) {
- this.urlHashes = new HashSet<String>();
- this.urlHashes.add(new String(urlHashBytes));
+ this.urlHashes = new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0);
+ try {
+ this.urlHashes.put(urlHashBytes);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
}
public ReferenceContainer<ReferenceType> rewrite(ReferenceContainer<ReferenceType> container) {
diff --git a/source/net/yacy/kelondro/rwi/IndexReader.java b/source/net/yacy/kelondro/rwi/IndexReader.java
index b8b340eea..8f440f004 100644
--- a/source/net/yacy/kelondro/rwi/IndexReader.java
+++ b/source/net/yacy/kelondro/rwi/IndexReader.java
@@ -26,8 +26,7 @@
package net.yacy.kelondro.rwi;
-import java.util.Set;
-
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.order.CloneableIterator;
@@ -35,7 +34,7 @@ public interface IndexReader<ReferenceType extends Reference> {
public int size();
public boolean has(byte[] wordHash); // should only be used if in case that true is returned the getContainer is NOT called
- public ReferenceContainer<ReferenceType> get(byte[] wordHash, Set<String> urlselection);
+ public ReferenceContainer<ReferenceType> get(byte[] wordHash, HandleSet urlselection);
public CloneableIterator<ReferenceContainer<ReferenceType>> references(byte[] startWordHash, boolean rot);
public void close();
diff --git a/source/net/yacy/kelondro/rwi/Reference.java b/source/net/yacy/kelondro/rwi/Reference.java
index eeaace717..2edb445ca 100644
--- a/source/net/yacy/kelondro/rwi/Reference.java
+++ b/source/net/yacy/kelondro/rwi/Reference.java
@@ -34,7 +34,7 @@ public interface Reference {
public Entry toKelondroEntry();
- public String metadataHash();
+ public byte[] metadataHash();
public long lastModified();
diff --git a/source/net/yacy/kelondro/rwi/ReferenceContainer.java b/source/net/yacy/kelondro/rwi/ReferenceContainer.java
index 464a94c1b..63612974f 100644
--- a/source/net/yacy/kelondro/rwi/ReferenceContainer.java
+++ b/source/net/yacy/kelondro/rwi/ReferenceContainer.java
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
@@ -107,10 +108,6 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
return termHash;
}
- public String getTermHashAsString() {
- return new String(termHash);
- }
-
public void add(final Reference entry) throws RowSpaceExceededException {
// add without double-occurrence test
assert entry.toKelondroEntry().objectsize() == super.rowdef.objectsize;
@@ -167,8 +164,8 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
return x;
}
- public ReferenceType get(final String urlHash) {
- final Row.Entry entry = this.get(urlHash.getBytes());
+ public ReferenceType getReference(final byte[] urlHash) {
+ final Row.Entry entry = super.get(urlHash);
if (entry == null) return null;
return this.factory.produceSlow(entry);
}
@@ -178,16 +175,23 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
* if the url hash was found, return the entry, but delete the entry from the container
* if the entry was not found, return null.
*/
- public ReferenceType remove(final String urlHash) {
- final Row.Entry entry = remove(urlHash.getBytes());
+ public ReferenceType removeReference(final byte[] urlHash) {
+ final Row.Entry entry = super.remove(urlHash);
if (entry == null) return null;
return this.factory.produceSlow(entry);
}
+ public int removeEntries(final HandleSet urlHashes) {
+ int count = 0;
+ final Iterator<byte[]> i = urlHashes.iterator();
+ while (i.hasNext()) count += (remove(i.next()) == null) ? 0 : 1;
+ return count;
+ }
+
public int removeEntries(final Set<String> urlHashes) {
int count = 0;
final Iterator<String> i = urlHashes.iterator();
- while (i.hasNext()) count += (remove(i.next()) == null) ? 0 : 1;
+ while (i.hasNext()) count += (remove(i.next().getBytes()) == null) ? 0 : 1;
return count;
}
@@ -369,10 +373,10 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
ReferenceType ie2;
while (se.hasNext()) {
ie1 = se.next();
- ie2 = large.get(ie1.metadataHash());
+ ie2 = large.getReference(ie1.metadataHash());
if ((ie1 != null) && (ie2 != null)) {
- assert (ie1.metadataHash().length() == keylength) : "ie0.urlHash() = " + ie1.metadataHash();
- assert (ie2.metadataHash().length() == keylength) : "ie1.urlHash() = " + ie2.metadataHash();
+ assert (ie1.metadataHash().length == keylength) : "ie0.urlHash() = " + new String(ie1.metadataHash());
+ assert (ie2.metadataHash().length == keylength) : "ie1.urlHash() = " + new String(ie2.metadataHash());
// this is a hit. Calculate word distance:
ie1 = factory.produceFast(ie2);
@@ -405,9 +409,9 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
ie2 = e2.next();
while (true) {
- assert (ie1.metadataHash().length() == keylength) : "ie1.urlHash() = " + ie1.metadataHash();
- assert (ie2.metadataHash().length() == keylength) : "ie2.urlHash() = " + ie2.metadataHash();
- c = ordering.compare(ie1.metadataHash().getBytes(), ie2.metadataHash().getBytes());
+ assert (ie1.metadataHash().length == keylength) : "ie1.urlHash() = " + new String(ie1.metadataHash());
+ assert (ie2.metadataHash().length == keylength) : "ie2.urlHash() = " + new String(ie2.metadataHash());
+ c = ordering.compare(ie1.metadataHash(), ie2.metadataHash());
//System.out.println("** '" + ie1.getUrlHash() + "'.compareTo('" + ie2.getUrlHash() + "')="+c);
if (c < 0) {
if (e1.hasNext()) ie1 = e1.next(); else break;
@@ -459,11 +463,11 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
Reference ie0, ie1;
while (se.hasNext()) {
ie0 = se.next();
- ie1 = excl.get(ie0.metadataHash());
+ ie1 = excl.getReference(ie0.metadataHash());
if ((ie0 != null) && (ie1 != null)) {
- assert (ie0.metadataHash().length() == keylength) : "ie0.urlHash() = " + ie0.metadataHash();
- assert (ie1.metadataHash().length() == keylength) : "ie1.urlHash() = " + ie1.metadataHash();
- if (iterate_pivot) se.remove(); pivot.remove(ie0.metadataHash().getBytes());
+ assert (ie0.metadataHash().length == keylength) : "ie0.urlHash() = " + new String(ie0.metadataHash());
+ assert (ie1.metadataHash().length == keylength) : "ie1.urlHash() = " + new String(ie1.metadataHash());
+ if (iterate_pivot) se.remove(); pivot.remove(ie0.metadataHash());
}
}
return pivot;
@@ -487,9 +491,9 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
ie2 = e2.next();
while (true) {
- assert (ie1.metadataHash().length() == keylength) : "ie1.urlHash() = " + ie1.metadataHash();
- assert (ie2.metadataHash().length() == keylength) : "ie2.urlHash() = " + ie2.metadataHash();
- c = pivot.rowdef.getOrdering().compare(ie1.metadataHash().getBytes(), ie2.metadataHash().getBytes());
+ assert (ie1.metadataHash().length == keylength) : "ie1.urlHash() = " + new String(ie1.metadataHash());
+ assert (ie2.metadataHash().length == keylength) : "ie2.urlHash() = " + new String(ie2.metadataHash());
+ c = pivot.rowdef.getOrdering().compare(ie1.metadataHash(), ie2.metadataHash());
//System.out.println("** '" + ie1.getUrlHash() + "'.compareTo('" + ie2.getUrlHash() + "')="+c);
if (c < 0) {
if (e1.hasNext()) ie1 = e1.next(); else break;
@@ -524,15 +528,16 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
synchronized (inputContainer) {
final Iterator<ReferenceType> i = inputContainer.entries();
Reference iEntry;
- String dom, paths;
+ String dom, mod, paths;
while (i.hasNext()) {
iEntry = i.next();
- if ((excludeContainer != null) && (excludeContainer.get(iEntry.metadataHash()) != null)) continue; // do not include urls that are in excludeContainer
- dom = iEntry.metadataHash().substring(6);
+ if ((excludeContainer != null) && (excludeContainer.getReference(iEntry.metadataHash()) != null)) continue; // do not include urls that are in excludeContainer
+ dom = new String(iEntry.metadataHash()).substring(6);
+ mod = new String(iEntry.metadataHash()).substring(0, 6);
if ((paths = doms.get(dom)) == null) {
- doms.put(dom, iEntry.metadataHash().substring(0, 6));
+ doms.put(dom, mod);
} else {
- doms.put(dom, paths + iEntry.metadataHash().substring(0, 6));
+ doms.put(dom, paths + mod);
}
if (System.currentTimeMillis() > timeout)
break;
diff --git a/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java b/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java
index 605375d96..226395b55 100644
--- a/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java
+++ b/source/net/yacy/kelondro/rwi/ReferenceContainerArray.java
@@ -239,7 +239,7 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
/**
* delete a indexContainer from the heap cache. This can only be used for write-enabled heaps
* @param wordHash
- * @return the indexContainer if the cache contained the container, null othervise
+ * @return the indexContainer if the cache contained the container, null otherwise
* @throws IOException
*/
public synchronized void delete(final byte[] termHash) throws IOException {
@@ -342,7 +342,7 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
long lastlog = start - 27000;
int count = 0;
ReferenceType reference;
- String mh;
+ byte[] mh;
while (ei.hasNext()) {
container = ei.next();
if (container == null) continue;
@@ -352,7 +352,7 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
if (reference == null) continue;
mh = reference.metadataHash();
if (mh == null) continue;
- references.inc(mh.getBytes());
+ references.inc(mh);
}
count++;
// write a log
diff --git a/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java b/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java
index 52893ce88..07024acf0 100644
--- a/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java
+++ b/source/net/yacy/kelondro/rwi/ReferenceContainerCache.java
@@ -37,6 +37,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.kelondro.blob.HeapWriter;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.Row;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
@@ -284,7 +285,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* @return the indexContainer if one exist, null otherwise
* @throws
*/
- public ReferenceContainer<ReferenceType> get(final byte[] key, Set<String> urlselection) {
+ public ReferenceContainer<ReferenceType> get(final byte[] key, HandleSet urlselection) {
ReferenceContainer<ReferenceType> c = this.cache.get(new ByteArray(key));
if (urlselection == null) return c;
if (c == null) return null;
@@ -295,7 +296,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
ReferenceType ee;
while (e.hasNext()) {
ee = e.next();
- if (urlselection.contains(ee.metadataHash())) {
+ if (urlselection.has(ee.metadataHash())) {
c1.add(ee);
}
}
@@ -345,23 +346,43 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
}
return false;
}
-
+
+ public int remove(final byte[] termHash, final HandleSet urlHashes) {
+ assert this.cache != null;
+ if (urlHashes.isEmpty()) return 0;
+ ByteArray tha = new ByteArray(termHash);
+ int count;
+ synchronized (cache) {
+ final ReferenceContainer<ReferenceType> c = cache.get(tha);
+ if ((c != null) && ((count = c.removeEntries(urlHashes)) > 0)) {
+ // removal successful
+ if (c.isEmpty()) {
+ delete(termHash);
+ } else {
+ cache.put(tha, c);
+ }
+ return count;
+ }
+ }
+ return 0;
+ }
+
public int remove(final byte[] termHash, final Set<String> urlHashes) {
assert this.cache != null;
if (urlHashes.isEmpty()) return 0;
ByteArray tha = new ByteArray(termHash);
int count;
synchronized (cache) {
- final ReferenceContainer<ReferenceType> c = cache.get(tha);
- if ((c != null) && ((count = c.removeEntries(urlHashes)) > 0)) {
- // removal successful
- if (c.isEmpty()) {
- delete(termHash);
- } else {
- cache.put(tha, c);
- }
- return count;
- }
+ final ReferenceContainer<ReferenceType> c = cache.get(tha);
+ if ((c != null) && ((count = c.removeEntries(urlHashes)) > 0)) {
+ // removal successful
+ if (c.isEmpty()) {
+ delete(termHash);
+ } else {
+ cache.put(tha, c);
+ }
+ return count;
+ }
}
return 0;
}
diff --git a/source/net/yacy/kelondro/rwi/TermSearch.java b/source/net/yacy/kelondro/rwi/TermSearch.java
index ce7bc7f71..4f2bebf4e 100644
--- a/source/net/yacy/kelondro/rwi/TermSearch.java
+++ b/source/net/yacy/kelondro/rwi/TermSearch.java
@@ -28,9 +28,8 @@
package net.yacy.kelondro.rwi;
import java.util.HashMap;
-import java.util.Set;
-import java.util.TreeSet;
+import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
@@ -41,9 +40,9 @@ public class TermSearch <ReferenceType extends Reference> {
public TermSearch(
Index<ReferenceType> base,
- final TreeSet<byte[]> queryHashes,
- final TreeSet<byte[]> excludeHashes,
- final Set<String> urlselection,
+ final HandleSet queryHashes,
+ final HandleSet excludeHashes,
+ final HandleSet urlselection,
ReferenceFactory<ReferenceType> termFactory,
int maxDistance) throws RowSpaceExceededException {
diff --git a/source/net/yacy/kelondro/util/CompressedHashMap.java b/source/net/yacy/kelondro/util/CompressedHashMap.java
index 1b0d42e03..c0bfcb255 100644
--- a/source/net/yacy/kelondro/util/CompressedHashMap.java
+++ b/source/net/yacy/kelondro/util/CompressedHashMap.java
@@ -67,7 +67,6 @@ public class CompressedHashMap {
private static int hashkey(final byte[] key, final int capacity) {
int h = 0;
for (int i = 0; i < key.length; i++) h = h * 15 + (0xff & key[i]);
- //System.out.println("hash code of key " + new String(key) + " is " + h);
return h % capacity;
}
@@ -83,7 +82,6 @@ public class CompressedHashMap {
private int findExisting(final byte[] key) {
// returns an index position if found; -1 otherwise
int hash = hashkey(key, capacity());
- //System.out.println("first guess for key " + new String(key) + ": " + hash + "( capacity is " + capacity() + " )");
int testcount = 0;
while (testcount++ < rehashtry()) {
if (mem[hash * reclen] == 0) return -1;
@@ -167,7 +165,6 @@ public class CompressedHashMap {
}
} else {
// there is enough space
- //System.out.println("put " + new String(key) + " into cell " + hash);
final int mempos = hash * reclen;
System.arraycopy(key, 0, mem, mempos, keylen);
System.arraycopy(value, 0, mem, mempos + keylen, valuelen);
@@ -189,7 +186,6 @@ public class CompressedHashMap {
assert (key.length == keylen);
final int hash = findExisting(key);
- //System.out.println("get " + new String(key) + " from cell " + hash);
if (hash < 0) {
return null;
}
diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.java
index 9d4d03eb8..c73de4974 100644
--- a/source/net/yacy/kelondro/util/FileUtils.java
+++ b/source/net/yacy/kelondro/util/FileUtils.java
@@ -740,32 +740,6 @@ public final class FileUtils {
}
return FileUtils.writeList(listFile, new String(out)); //(File, String)
}
-
-
- /*
- public static ArrayList<String> strings(byte[] a) {
- final ArrayList<String> list = new ArrayList<String>();
- Iterator<String> i = new StringsIterator(new BufferedReader(new InputStreamReader(new ByteArrayInputStream(a))));
- while (i.hasNext()) list.add(i.next());
- return list;
- }
-
- public static ArrayList<String> strings(byte[] a) {
- final ArrayList<String> list = new ArrayList<String>();
- BufferedReader bufreader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(a)));
- String line = null;
- try {
- while ((line = bufreader.readLine()) != null) {
- line = line.trim();
- if (line.length() > 0) list.add(line);
- }
- } catch (IOException e) {
- Log.logWarning("FileUtils", "failed strings: " + e.getMessage(), e);
- return list;
- }
- return list;
- }
- */
public static class StringsIterator implements Iterator<String> {
private final BufferedReader reader;
diff --git a/source/net/yacy/kelondro/util/MapTools.java b/source/net/yacy/kelondro/util/MapTools.java
index 3906784ea..e85513ca6 100644
--- a/source/net/yacy/kelondro/util/MapTools.java
+++ b/source/net/yacy/kelondro/util/MapTools.java
@@ -91,7 +91,7 @@ public final class MapTools {
}
if (buf.length() > 1) { buf.setLength(buf.length() - 1); } // remove last separator
if (braces) { buf.append("}"); }
- return new String(buf);
+ return buf.toString();
}
}
diff --git a/source/net/yacy/kelondro/util/SetTools.java b/source/net/yacy/kelondro/util/SetTools.java
index 5391e6718..867cf6cb2 100644
--- a/source/net/yacy/kelondro/util/SetTools.java
+++ b/source/net/yacy/kelondro/util/SetTools.java
@@ -39,6 +39,8 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
+import net.yacy.kelondro.index.HandleSet;
+
public class SetTools {
@@ -47,9 +49,9 @@ public class SetTools {
// ------------------------------------------------------------------------------------------------
// helper methods
- public static int log2a(int x) {
+ public final static int log2a(int x) {
// this computes 1 + log2
- // it is the number of bits in x, not the logarithmus by 2
+ // it is the number of bits in x, not the logarithm by 2
int l = 0;
while (x > 0) {x = x >>> 1; l++;}
return l;
@@ -211,7 +213,7 @@ public class SetTools {
}
private static <A> TreeSet<A> joinConstructiveByEnumeration(final TreeSet<A> set1, final TreeSet<A> set2) {
- // implement pairvise enumeration
+ // implement pairwise enumeration
final Comparator<? super A> comp = set1.comparator();
final Iterator<A> mi = set1.iterator();
final Iterator<A> si = set2.iterator();
@@ -257,38 +259,91 @@ public class SetTools {
return anymatchByEnumeration(set1, set2);
}
- private static <A> boolean anymatchByTest(final TreeSet<A> small, final TreeSet<A> large) {
- final Iterator<A> mi = small.iterator();
- A o;
- while (mi.hasNext()) {
- o = mi.next();
- if (large.contains(o)) return true;
- }
- return false;
- }
+ public static <A> boolean anymatch(final HandleSet set1, final HandleSet set2) {
+ // comparators must be equal
+ if ((set1 == null) || (set2 == null)) return false;
+ if (set1.comparator() != set2.comparator()) return false;
+ if (set1.isEmpty() || set2.isEmpty()) return false;
+
+ // decide which method to use
+ final int high = ((set1.size() > set2.size()) ? set1.size() : set2.size());
+ final int low = ((set1.size() > set2.size()) ? set2.size() : set1.size());
+ final int stepsEnum = 10 * (high + low - 1);
+ final int stepsTest = 12 * log2a(high) * low;
+
+ // start most efficient method
+ if (stepsEnum > stepsTest) {
+ if (set1.size() < set2.size()) return anymatchByTest(set1, set2);
+ return anymatchByTest(set2, set1);
+ }
+ return anymatchByEnumeration(set1, set2);
+ }
+
+ private static <A> boolean anymatchByTest(final TreeSet<A> small, final TreeSet<A> large) {
+ final Iterator<A> mi = small.iterator();
+ A o;
+ while (mi.hasNext()) {
+ o = mi.next();
+ if (large.contains(o)) return true;
+ }
+ return false;
+ }
+
+ private static boolean anymatchByTest(final HandleSet small, final HandleSet large) {
+ final Iterator<byte[]> mi = small.iterator();
+ byte[] o;
+ while (mi.hasNext()) {
+ o = mi.next();
+ if (large.has(o)) return true;
+ }
+ return false;
+ }
private static <A> boolean anymatchByEnumeration(final TreeSet<A> set1, final TreeSet<A> set2) {
- // implement pairvise enumeration
- final Comparator<? super A> comp = set1.comparator();
- final Iterator<A> mi = set1.iterator();
- final Iterator<A> si = set2.iterator();
- int c;
- if ((mi.hasNext()) && (si.hasNext())) {
- A mobj = mi.next();
- A sobj = si.next();
- while (true) {
- c = comp.compare(mobj, sobj);
- if (c < 0) {
- if (mi.hasNext()) mobj = mi.next(); else break;
- } else if (c > 0) {
- if (si.hasNext()) sobj = si.next(); else break;
- } else {
- return true;
- }
- }
- }
- return false;
- }
+ // implement pairwise enumeration
+ final Comparator<? super A> comp = set1.comparator();
+ final Iterator<A> mi = set1.iterator();
+ final Iterator<A> si = set2.iterator();
+ int c;
+ if ((mi.hasNext()) && (si.hasNext())) {
+ A mobj = mi.next();
+ A sobj = si.next();
+ while (true) {
+ c = comp.compare(mobj, sobj);
+ if (c < 0) {
+ if (mi.hasNext()) mobj = mi.next(); else break;
+ } else if (c > 0) {
+ if (si.hasNext()) sobj = si.next(); else break;
+ } else {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static boolean anymatchByEnumeration(final HandleSet set1, final HandleSet set2) {
+ // implement pairwise enumeration
+ final Comparator<byte[]> comp = set1.comparator();
+ final Iterator<byte[]> mi = set1.iterator();
+ final Iterator<byte[]> si = set2.iterator();
+ int c;
+ if ((mi.hasNext()) && (si.hasNext())) {
+ byte[] mobj = mi.next();
+ byte[] sobj = si.next();
+ while (true) {
+ c = comp.compare(mobj, sobj);
+ if (c < 0) {
+ if (mi.hasNext()) mobj = mi.next(); else break;
+ } else if (c > 0) {
+ if (si.hasNext()) sobj = si.next(); else break;
+ } else {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
// ------------------------------------------------------------------------------------------------
// exclude
@@ -425,7 +480,7 @@ public class SetTools {
return list;
}
- public static String setToString(final TreeSet<byte[]> set, final char separator) {
+ public static String setToString(final HandleSet set, final char separator) {
final Iterator<byte[]> i = set.iterator();
final StringBuilder sb = new StringBuilder(set.size() * 7);
if (i.hasNext()) sb.append(new String(i.next()));
@@ -434,6 +489,7 @@ public class SetTools {
}
return sb.toString();
}
+
public static String setToString(final Set<String> set, final char separator) {
final Iterator<String> i = set.iterator();
final StringBuilder sb = new StringBuilder(set.size() * 7);
diff --git a/source/net/yacy/repository/Blacklist.java b/source/net/yacy/repository/Blacklist.java
index abaddc81b..bf1b8466a 100644
--- a/source/net/yacy/repository/Blacklist.java
+++ b/source/net/yacy/repository/Blacklist.java
@@ -30,7 +30,6 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -42,6 +41,9 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import net.yacy.kelondro.data.meta.DigestURI;
+import net.yacy.kelondro.data.meta.URIMetadataRow;
+import net.yacy.kelondro.index.HandleSet;
+import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.SetTools;
@@ -77,7 +79,7 @@ public class Blacklist {
public static final String BLACKLIST_TYPES_STRING="proxy,crawler,dht,search,surftips,news";
protected File blacklistRootPath = null;
- protected HashMap<String, Set<String>> cachedUrlHashs = null;
+ protected HashMap<String, HandleSet> cachedUrlHashs = null;
//protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here
protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths_matchable = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here
protected HashMap<String, HashMap<String, ArrayList<String>>> hostpaths_notmatchable = null; // key=host, value=path; mapped url is http://host/path; path does not start with '/' here
@@ -91,7 +93,7 @@ public class Blacklist {
//this.hostpaths = new HashMap<String, HashMap<String, ArrayList<String>>>();
this.hostpaths_matchable = new HashMap<String, HashMap<String, ArrayList<String>>>();
this.hostpaths_notmatchable = new HashMap<String, HashMap<String, ArrayList<String>>>();
- this.cachedUrlHashs = new HashMap<String, Set<String>>();
+ this.cachedUrlHashs = new HashMap<String, HandleSet>();
final Iterator<String> iter = BLACKLIST_TYPES.iterator();
while (iter.hasNext()) {
@@ -99,7 +101,7 @@ public class Blacklist {
//this.hostpaths.put(blacklistType, new HashMap<String, ArrayList<String>>());
this.hostpaths_matchable.put(blacklistType, new HashMap<String, ArrayList<String>>());
this.hostpaths_notmatchable.put(blacklistType, new HashMap<String, ArrayList<String>>());
- this.cachedUrlHashs.put(blacklistType, Collections.synchronizedSet(new HashSet<String>()));
+ this.cachedUrlHashs.put(blacklistType, new HandleSet(URIMetadataRow.rowdef.primaryKeyLength, URIMetadataRow.rowdef.objectOrder, 0));
}
}
@@ -121,7 +123,7 @@ public class Blacklist {
return (matchable)? this.hostpaths_matchable.get(blacklistType) : this.hostpaths_notmatchable.get(blacklistType);
}
- protected Set<String> getCacheUrlHashsSet(final String blacklistType) {
+ protected HandleSet getCacheUrlHashsSet(final String blacklistType) {
if (blacklistType == null) throw new IllegalArgumentException();
if (!BLACKLIST_TYPES.contains(blacklistType)) throw new IllegalArgumentException("Unknown backlist type.");
@@ -129,13 +131,13 @@ public class Blacklist {
}
public void clear() {
- for(final HashMap<String, ArrayList<String>> entry: this.hostpaths_matchable.values()) {
+ for (final HashMap<String, ArrayList<String>> entry: this.hostpaths_matchable.values()) {
entry.clear();
}
- for(final HashMap<String, ArrayList<String>> entry: this.hostpaths_notmatchable.values()) {
+ for (final HashMap<String, ArrayList<String>> entry: this.hostpaths_notmatchable.values()) {
entry.clear();
}
- for(final Set<String> entry: this.cachedUrlHashs.values()) {
+ for (final HandleSet entry: this.cachedUrlHashs.values()) {
entry.clear();
}
}
@@ -162,7 +164,7 @@ public class Blacklist {
}
}
- public void loadList(final BlacklistFile blFile, final String sep) {
+ private void loadList(final BlacklistFile blFile, final String sep) {
final HashMap<String, ArrayList<String>> blacklistMapMatch = getBlacklistMap(blFile.getType(),true);
final HashMap<String, ArrayList<String>> blacklistMapNotMatch = getBlacklistMap(blFile.getType(),false);
Set<Map.Entry<String, ArrayList<String>>> loadedBlacklist;
@@ -253,15 +255,15 @@ public class Blacklist {
int size = 0;
final Iterator<String> iter = this.cachedUrlHashs.keySet().iterator();
while (iter.hasNext()) {
- final Set<String> blacklistMap = this.cachedUrlHashs.get(iter.next());
+ final HandleSet blacklistMap = this.cachedUrlHashs.get(iter.next());
size += blacklistMap.size();
}
return size;
}
- public boolean hashInBlacklistedCache(final String blacklistType, final String urlHash) {
- final Set<String> urlHashCache = getCacheUrlHashsSet(blacklistType);
- return urlHashCache.contains(urlHash);
+ public boolean hashInBlacklistedCache(final String blacklistType, final byte[] urlHash) {
+ final HandleSet urlHashCache = getCacheUrlHashsSet(blacklistType);
+ return urlHashCache.has(urlHash);
}
public boolean contains(final String blacklistType, String host, String path) {
@@ -282,11 +284,15 @@ public class Blacklist {
public boolean isListed(final String blacklistType, final DigestURI url) {
- final Set<String> urlHashCache = getCacheUrlHashsSet(blacklistType);
- if (!urlHashCache.contains(new String(url.hash()))) {
+ final HandleSet urlHashCache = getCacheUrlHashsSet(blacklistType);
+ if (!urlHashCache.has(url.hash())) {
final boolean temp = isListed(blacklistType, url.getHost().toLowerCase(), url.getFile());
if (temp) {
- urlHashCache.add(new String(url.hash()));
+ try {
+ urlHashCache.put(url.hash());
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
}
return temp;
}
diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java
index 821d6ae13..a85b48c14 100644
--- a/source/net/yacy/yacy.java
+++ b/source/net/yacy/yacy.java
@@ -677,9 +677,9 @@ public final class yacy {
Reference iEntry;
while (wordIdxEntries.hasNext()) {
iEntry = wordIdxEntries.next();
- final String urlHash = iEntry.metadataHash();
- if ((currentUrlDB.exists(urlHash.getBytes())) && (!minimizedUrlDB.exists(urlHash.getBytes()))) try {
- final URIMetadataRow urlEntry = currentUrlDB.load(urlHash.getBytes(), null, 0);
+ final byte[] urlHash = iEntry.metadataHash();
+ if ((currentUrlDB.exists(urlHash)) && (!minimizedUrlDB.exists(urlHash))) try {
+ final URIMetadataRow urlEntry = currentUrlDB.load(urlHash, null, 0);
urlCounter++;
minimizedUrlDB.store(urlEntry);
if (urlCounter % 500 == 0) {
@@ -689,7 +689,7 @@ public final class yacy {
}
if (wordCounter%500 == 0) {
- wordChunkEndHash = wordIdxContainer.getTermHashAsString();
+ wordChunkEndHash = new String(wordIdxContainer.getTermHash());
wordChunkEnd = System.currentTimeMillis();
final long duration = wordChunkEnd - wordChunkStart;
log.logInfo(wordCounter + " words scanned " +
@@ -871,7 +871,7 @@ public final class yacy {
bos.write(container.getTermHash());
bos.write(serverCore.CRLF);
if (counter % 500 == 0) {
- log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + container.getTermHashAsString());
+ log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + new String(container.getTermHash()));
}
}
}
@@ -888,14 +888,14 @@ public final class yacy {
bos.write(container.getTermHash());
bos.write(serverCore.CRLF);
if (counter % 500 == 0) {
- log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + container.getTermHashAsString());
+ log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + new String(container.getTermHash()));
}
}
}
bos.flush();
bos.close();
}
- log.logInfo("Total number of Hashs: " + counter + ". Last found Hash: " + (container == null ? "null" : container.getTermHashAsString()));
+ log.logInfo("Total number of Hashs: " + counter + ". Last found Hash: " + (container == null ? "null" : new String(container.getTermHash())));
} catch (final IOException e) {
log.logSevere("IOException", e);
}