Skip to content

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

full redesign of index access data model: terms (words) are not any more retrieved by their word hash string, but by a byte[] containing the word hash. this has strong advantages when RWIs are sorted in the ReferenceContainer Cache and compared with the sun.java TreeMap method, which needed getBytes() and new String() transformations before. Many thousands of such conversions are now omitted every second, which increases the indexing speed by a factor of two.

orbiterc8624903c64d
diff --git a/htroot/IndexCleaner_p.java b/htroot/IndexCleaner_p.java
index 7fadfc7b0..fe4ecc693 100755
--- a/htroot/IndexCleaner_p.java
+++ b/htroot/IndexCleaner_p.java
@@ -58,7 +58,7 @@ public class IndexCleaner_p {
}
else if (post.get("action").equals("rstart")) {
if (indexCleanerThread==null || !indexCleanerThread.isAlive()) {
- indexCleanerThread = sb.webIndex.getReferenceCleaner(post.get("wordHash","AAAAAAAAAAAA"));
+ indexCleanerThread = sb.webIndex.getReferenceCleaner(post.get("wordHash","AAAAAAAAAAAA").getBytes());
indexCleanerThread.start();
}
else {
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.java
index 370d02258..9b5da3084 100644
--- a/htroot/IndexControlRWIs_p.java
+++ b/htroot/IndexControlRWIs_p.java
@@ -77,9 +77,9 @@ public class IndexControlRWIs_p {
if (post != null) {
// default values
final String keystring = post.get("keystring", "").trim();
- String keyhash = post.get("keyhash", "").trim();
+ byte[] keyhash = post.get("keyhash", "").trim().getBytes();
prop.putHTML("keystring", keystring);
- prop.putHTML("keyhash", keyhash);
+ prop.putHTML("keyhash", new String(keyhash));
// read values from checkboxes
String[] urlx = post.getAll("urlhx.*");
@@ -103,7 +103,7 @@ public class IndexControlRWIs_p {
final plasmaSearchRankingProcess ranking = plasmaSearchAPI.genSearchresult(prop, sb, keyhash, null);
if (ranking.filteredCount() == 0) {
prop.put("searchresult", 2);
- prop.putHTML("searchresult_wordhash", keyhash);
+ prop.putHTML("searchresult_wordhash", new String(keyhash));
}
}
diff --git a/htroot/api/timeline.java b/htroot/api/timeline.java
index 1aa5e9724..a2f6c6a21 100644
--- a/htroot/api/timeline.java
+++ b/htroot/api/timeline.java
@@ -36,6 +36,7 @@ import de.anomic.kelondro.util.DateFormatter;
import de.anomic.plasma.plasmaSearchQuery;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaWordIndex;
+import de.anomic.plasma.parser.Word;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.tools.iso639;
@@ -63,7 +64,7 @@ public final class timeline {
if (language == null) language = "en";
}
final TreeSet<String>[] query = plasmaSearchQuery.cleanQuery(querystring); // converts also umlaute
-
+ TreeSet<byte[]> q = Word.words2hashes(query[0]);
// tell all threads to do nothing for a specific time
sb.intermissionAllThreads(3000);
@@ -76,10 +77,10 @@ public final class timeline {
int joincount = 0;
// retrieve index containers
- yacyCore.log.logInfo("INIT TIMELINE SEARCH: " + plasmaSearchQuery.anonymizedQueryHashes(query[0]) + " - " + count + " links");
+ //yacyCore.log.logInfo("INIT TIMELINE SEARCH: " + plasmaSearchQuery.anonymizedQueryHashes(query[0]) + " - " + count + " links");
// get the index container with the result vector
- HashMap<String, ReferenceContainer<WordReference>>[] localSearchContainerMaps = sb.webIndex.localSearchContainers(query[0], query[1], null);
+ HashMap<byte[], ReferenceContainer<WordReference>>[] localSearchContainerMaps = sb.webIndex.localSearchContainers(q, Word.words2hashes(query[1]), null);
final ReferenceContainer<WordReference> index =
ReferenceContainer.joinExcludeContainers(
plasmaWordIndex.wordReferenceFactory,
@@ -107,7 +108,7 @@ public final class timeline {
// log
yacyCore.log.logInfo("EXIT TIMELINE SEARCH: " +
- plasmaSearchQuery.anonymizedQueryHashes(query[0]) + " - " + joincount + " links found, " +
+ plasmaSearchQuery.anonymizedQueryHashes(q) + " - " + joincount + " links found, " +
prop.get("linkcount", "?") + " links selected, " +
indexabstractContainercount + " index abstracts, " +
(System.currentTimeMillis() - timestamp) + " milliseconds");
diff --git a/htroot/yacy/query.java b/htroot/yacy/query.java
index 6755fd8ad..56ecdda12 100644
--- a/htroot/yacy/query.java
+++ b/htroot/yacy/query.java
@@ -84,7 +84,7 @@ public final class query {
if (obj.equals("rwiurlcount")) try {
// the total number of different urls in the rwi is returned
// <env> shall contain a word hash, the number of assigned lurls to this hash is returned
- prop.put("response", sb.webIndex.index().get(env, null).size());
+ prop.put("response", sb.webIndex.index().get(env.getBytes(), null).size());
return prop;
} catch (IOException e) {
e.printStackTrace();
diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java
index d08959582..1daf76879 100644
--- a/htroot/yacy/search.java
+++ b/htroot/yacy/search.java
@@ -155,7 +155,7 @@ public final class search {
// tell all threads to do nothing for a specific time
sb.intermissionAllThreads(3000);
- final TreeSet<String> abstractSet = ((abstracts.length() == 0) || (abstracts.equals("auto"))) ? null : plasmaSearchQuery.hashes2Set(abstracts);
+ final TreeSet<byte[]> abstractSet = ((abstracts.length() == 0) || (abstracts.equals("auto"))) ? null : plasmaSearchQuery.hashes2Set(abstracts);
// store accessing peer
final yacySeed remoteSeed = yacySeed.genRemoteSeed(oseed, key, false);
@@ -166,8 +166,8 @@ public final class search {
}
// prepare search
- final TreeSet<String> queryhashes = plasmaSearchQuery.hashes2Set(query);
- final TreeSet<String> excludehashes = (exclude.length() == 0) ? new TreeSet<String>(Base64Order.enhancedComparator) : plasmaSearchQuery.hashes2Set(exclude);
+ final TreeSet<byte[]> queryhashes = plasmaSearchQuery.hashes2Set(query);
+ final TreeSet<byte[]> excludehashes = (exclude.length() == 0) ? new TreeSet<byte[]>(Base64Order.enhancedCoder) : plasmaSearchQuery.hashes2Set(exclude);
final long timestamp = System.currentTimeMillis();
// prepare a search profile
@@ -185,7 +185,7 @@ public final class search {
theQuery = new plasmaSearchQuery(
null,
abstractSet,
- new TreeSet<String>(Base64Order.enhancedComparator),
+ new TreeSet<byte[]>(Base64Order.enhancedCoder),
null,
rankingProfile,
maxdist,
@@ -209,19 +209,19 @@ public final class search {
yacyCore.log.logInfo("INIT HASH SEARCH (abstracts only): " + plasmaSearchQuery.anonymizedQueryHashes(theQuery.queryHashes) + " - " + theQuery.displayResults() + " links");
final long timer = System.currentTimeMillis();
- final Map<String, ReferenceContainer<WordReference>>[] containers = sb.webIndex.localSearchContainers(theQuery.queryHashes, theQuery.excludeHashes, plasmaSearchQuery.hashes2Set(urls));
+ final Map<byte[], ReferenceContainer<WordReference>>[] containers = sb.webIndex.localSearchContainers(theQuery.queryHashes, theQuery.excludeHashes, plasmaSearchQuery.hashes2StringSet(urls));
serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(theQuery.id(true), plasmaSearchEvent.COLLECTION, containers[0].size(), System.currentTimeMillis() - timer), false);
if (containers != null) {
- final Iterator<Map.Entry<String, ReferenceContainer<WordReference>>> ci = containers[0].entrySet().iterator();
- Map.Entry<String, ReferenceContainer<WordReference>> entry;
- String wordhash;
+ final Iterator<Map.Entry<byte[], ReferenceContainer<WordReference>>> ci = containers[0].entrySet().iterator();
+ Map.Entry<byte[], ReferenceContainer<WordReference>> entry;
+ byte[] wordhash;
while (ci.hasNext()) {
entry = ci.next();
wordhash = entry.getKey();
final ReferenceContainer<WordReference> container = entry.getValue();
indexabstractContainercount += container.size();
- indexabstract.append("indexabstract." + wordhash + "=").append(ReferenceContainer.compressIndex(container, null, 1000).toString()).append(serverCore.CRLF_STRING);
+ indexabstract.append("indexabstract." + new String(wordhash) + "=").append(ReferenceContainer.compressIndex(container, null, 1000).toString()).append(serverCore.CRLF_STRING);
}
}
@@ -269,16 +269,16 @@ public final class search {
} else {
// attach information about index abstracts
final StringBuilder indexcount = new StringBuilder();
- Map.Entry<String, Integer> entry;
- final Iterator<Map.Entry<String, Integer>> i = theSearch.IACount.entrySet().iterator();
+ Map.Entry<byte[], Integer> entry;
+ final Iterator<Map.Entry<byte[], Integer>> i = theSearch.IACount.entrySet().iterator();
while (i.hasNext()) {
entry = i.next();
- indexcount.append("indexcount.").append(entry.getKey()).append('=').append((entry.getValue()).toString()).append(serverCore.CRLF_STRING);
+ indexcount.append("indexcount.").append(new String(entry.getKey())).append('=').append((entry.getValue()).toString()).append(serverCore.CRLF_STRING);
}
if (abstractSet != null) {
// if a specific index-abstract is demanded, attach it here
- final Iterator<String> j = abstractSet.iterator();
- String wordhash;
+ final Iterator<byte[]> j = abstractSet.iterator();
+ byte[] wordhash;
while (j.hasNext()) {
wordhash = j.next();
indexabstractContainercount += (theSearch.IACount.get(wordhash)).intValue();
diff --git a/htroot/yacy/transferRWI.java b/htroot/yacy/transferRWI.java
index c12593556..99dddcc20 100644
--- a/htroot/yacy/transferRWI.java
+++ b/htroot/yacy/transferRWI.java
@@ -159,7 +159,7 @@ public final class transferRWI {
// learn entry
try {
- sb.webIndex.index().add(wordHash, iEntry);
+ sb.webIndex.index().add(wordHash.getBytes(), iEntry);
} catch (IOException e) {
e.printStackTrace();
}
@@ -192,7 +192,7 @@ public final class transferRWI {
if ((wordhashes.length == 0) || (received == 0)) {
sb.getLog().logInfo("Received 0 RWIs from " + otherPeerName + ", processed in " + (System.currentTimeMillis() - startProcess) + " milliseconds, requesting " + unknownURL.size() + " URLs, blocked " + blocked + " RWIs");
} else {
- final long avdist = (FlatWordPartitionScheme.std.dhtDistance(wordhashes[0], null, sb.webIndex.peers().mySeed()) + FlatWordPartitionScheme.std.dhtDistance(wordhashes[received - 1], null, sb.webIndex.peers().mySeed())) / 2;
+ final long avdist = (FlatWordPartitionScheme.std.dhtDistance(wordhashes[0].getBytes(), null, sb.webIndex.peers().mySeed()) + FlatWordPartitionScheme.std.dhtDistance(wordhashes[received - 1].getBytes(), null, sb.webIndex.peers().mySeed())) / 2;
sb.getLog().logInfo("Received " + received + " Entries " + wordc + " Words [" + wordhashes[0] + " .. " + wordhashes[received - 1] + "]/" + avdist + " from " + otherPeerName + ", processed in " + (System.currentTimeMillis() - startProcess) + " milliseconds, requesting " + unknownURL.size() + "/" + receivedURL + " URLs, blocked " + blocked + " RWIs");
RSSFeed.channels(RSSFeed.INDEXRECEIVE).addMessage(new RSSMessage("Received " + received + " RWIs [" + wordhashes[0] + " .. " + wordhashes[received - 1] + "]/" + avdist + " from " + otherPeerName + ", requesting " + unknownURL.size() + " URLs, blocked " + blocked, "", ""));
}
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index ecd2d27c1..ef241850a 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -361,7 +361,7 @@ public class yacysearch {
final boolean globalsearch = (global) /* && (yacyonline)*/ && (sb.getConfigBool(plasmaSwitchboardConstants.INDEX_RECEIVE_ALLOW, false));
// do the search
- final TreeSet<String> queryHashes = Word.words2hashes(query[0]);
+ final TreeSet<byte[]> queryHashes = Word.words2hashes(query[0]);
final plasmaSearchQuery theQuery = new plasmaSearchQuery(
querystring,
queryHashes,
diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java
index 9eb3f722f..2aaedfe6d 100644
--- a/source/de/anomic/data/bookmarksDB.java
+++ b/source/de/anomic/data/bookmarksDB.java
@@ -46,6 +46,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Map.Entry;
import java.util.regex.Pattern;
@@ -95,7 +96,7 @@ public class bookmarksDB {
// tags
MapView tagsTable;
- HashMap<String, Tag> tagCache;
+ TreeMap<String, Tag> tagCache;
// dates
MapView datesTable;
@@ -109,7 +110,7 @@ public class bookmarksDB {
public bookmarksDB(final File bookmarksFile, final File tagsFile, final File datesFile) {
// bookmarks
- tagCache=new HashMap<String, Tag>();
+ tagCache=new TreeMap<String, Tag>();
bookmarksFile.getParentFile().mkdirs();
//this.bookmarksTable = new kelondroMap(kelondroDyn.open(bookmarksFile, bufferkb * 1024, preloadTime, 12, 256, '_', true, false));
this.bookmarksTable = new MapView(new BLOBTree(bookmarksFile, true, true, 12, 256, '_', NaturalOrder.naturalOrder, true, false, false), 1000);
@@ -305,10 +306,10 @@ public class bookmarksDB {
* tagName is converted to lower case before hash is generated!
*/
public static String tagHash(final String tagName){
- return Word.word2hash(tagName.toLowerCase());
+ return new String(Word.word2hash(tagName.toLowerCase()));
}
public static String tagHash(final String tagName, final String user){
- return Word.word2hash(user+":"+tagName.toLowerCase());
+ return new String(Word.word2hash(user+":"+tagName.toLowerCase()));
}
public Iterator<String> getFolderList(final boolean priv){
@@ -548,7 +549,7 @@ public class bookmarksDB {
while(it.hasNext()){
storeTag(tagCache.get(it.next()));
}
- tagCache=new HashMap<String, Tag>();
+ tagCache=new TreeMap<String, Tag>();
}
public String addTag(final Tag tag) { // TODO: is addTag() really needed - check storeTag() and saveTag()
diff --git a/source/de/anomic/kelondro/blob/BLOBArray.java b/source/de/anomic/kelondro/blob/BLOBArray.java
index 91adcbca1..738b1954f 100755
--- a/source/de/anomic/kelondro/blob/BLOBArray.java
+++ b/source/de/anomic/kelondro/blob/BLOBArray.java
@@ -611,30 +611,30 @@ public class BLOBArray implements BLOB {
while (true) {
assert c1 != null;
assert c2 != null;
- e = ordering.compare(c1.getTermHash().getBytes(), c2.getTermHash().getBytes());
+ e = ordering.compare(c1.getTermHash(), c2.getTermHash());
if (e < 0) {
- writer.add(c1.getTermHash().getBytes(), c1.exportCollection());
+ writer.add(c1.getTermHash(), c1.exportCollection());
if (i1.hasNext()) {
c1o = c1;
c1 = i1.next();
- assert ordering.compare(c1.getTermHash().getBytes(), c1o.getTermHash().getBytes()) > 0;
+ assert ordering.compare(c1.getTermHash(), c1o.getTermHash()) > 0;
continue;
}
break;
}
if (e > 0) {
- writer.add(c2.getTermHash().getBytes(), c2.exportCollection());
+ writer.add(c2.getTermHash(), c2.exportCollection());
if (i2.hasNext()) {
c2o = c2;
c2 = i2.next();
- assert ordering.compare(c2.getTermHash().getBytes(), c2o.getTermHash().getBytes()) > 0;
+ assert ordering.compare(c2.getTermHash(), c2o.getTermHash()) > 0;
continue;
}
break;
}
assert e == 0;
// merge the entries
- writer.add(c1.getTermHash().getBytes(), (c1.merge(c2)).exportCollection());
+ writer.add(c1.getTermHash(), (c1.merge(c2)).exportCollection());
if (i1.hasNext() && i2.hasNext()) {
c1 = i1.next();
c2 = i2.next();
@@ -649,22 +649,22 @@ public class BLOBArray implements BLOB {
assert !(i1.hasNext() && i2.hasNext());
while (i1.hasNext()) {
//System.out.println("FLUSH REMAINING 1: " + c1.getWordHash());
- writer.add(c1.getTermHash().getBytes(), c1.exportCollection());
+ writer.add(c1.getTermHash(), c1.exportCollection());
if (i1.hasNext()) {
c1o = c1;
c1 = i1.next();
- assert ordering.compare(c1.getTermHash().getBytes(), c1o.getTermHash().getBytes()) > 0;
+ assert ordering.compare(c1.getTermHash(), c1o.getTermHash()) > 0;
continue;
}
break;
}
while (i2.hasNext()) {
//System.out.println("FLUSH REMAINING 2: " + c2.getWordHash());
- writer.add(c2.getTermHash().getBytes(), c2.exportCollection());
+ writer.add(c2.getTermHash(), c2.exportCollection());
if (i2.hasNext()) {
c2o = c2;
c2 = i2.next();
- assert ordering.compare(c2.getTermHash().getBytes(), c2o.getTermHash().getBytes()) > 0;
+ assert ordering.compare(c2.getTermHash(), c2o.getTermHash()) > 0;
continue;
}
break;
diff --git a/source/de/anomic/kelondro/index/IntegerHandleIndex.java b/source/de/anomic/kelondro/index/IntegerHandleIndex.java
index 1e3c3a828..6f3cbd666 100644
--- a/source/de/anomic/kelondro/index/IntegerHandleIndex.java
+++ b/source/de/anomic/kelondro/index/IntegerHandleIndex.java
@@ -335,23 +335,23 @@ public class IntegerHandleIndex {
long a = MemoryControl.available();
IntegerHandleIndex idx = new IntegerHandleIndex(12, Base64Order.enhancedCoder, 0, 150000);
for (int i = 0; i < count; i++) {
- idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count)).getBytes(), 1);
+ idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count)), 1);
}
long timek = ((long) count) * 1000L / (System.currentTimeMillis() - start);
System.out.println("Result IntegerHandleIndex: " + timek + " inc per second " + count + " loops.");
System.gc();
long memk = a - MemoryControl.available();
System.out.println("Used Memory: " + memk + " bytes");
- System.out.println("x " + idx.get(FlatWordPartitionScheme.positionToHash(0).getBytes()));
+ System.out.println("x " + idx.get(FlatWordPartitionScheme.positionToHash(0)));
idx = null;
r = new Random(0);
start = System.currentTimeMillis();
- String hash;
+ byte[] hash;
Integer d;
System.gc(); // for resource measurement
a = MemoryControl.available();
- TreeMap<String, Integer> hm = new TreeMap<String, Integer>();
+ TreeMap<byte[], Integer> hm = new TreeMap<byte[], Integer>(Base64Order.enhancedCoder);
for (int i = 0; i < count; i++) {
hash = FlatWordPartitionScheme.positionToHash(r.nextInt(count));
d = hm.get(hash);
diff --git a/source/de/anomic/kelondro/order/Base64Order.java b/source/de/anomic/kelondro/order/Base64Order.java
index a6f8972ec..573d08dd6 100644
--- a/source/de/anomic/kelondro/order/Base64Order.java
+++ b/source/de/anomic/kelondro/order/Base64Order.java
@@ -54,8 +54,6 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Cod
public static final Base64Order standardCoder = new Base64Order(true, true);
public static final Base64Order enhancedCoder = new Base64Order(true, false);
- public static final Comparator<String> standardComparator = new ByteOrder.StringOrder(standardCoder);
- public static final Comparator<String> enhancedComparator = new ByteOrder.StringOrder(enhancedCoder);
private final boolean rfc1113compliant;
private final char[] alpha;
@@ -185,7 +183,8 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Cod
// we will do that by grouping each three input bytes to four output bytes.
public final String encode(final byte[] in) {
if (in.length == 0) return "";
- StringBuilder out = new StringBuilder(in.length / 3 * 4 + 3);
+ int lene = in.length / 3 * 4 + 3;
+ StringBuilder out = new StringBuilder(lene);
int pos = 0;
long l;
while (in.length - pos >= 3) {
@@ -197,6 +196,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Cod
if (in.length % 3 != 0) out = out.append((in.length % 3 == 2) ? encodeLong((((0XffL & in[pos]) << 8) + (0XffL & in[pos + 1])) << 8, 4).substring(0, 3) : encodeLong((((0XffL & in[pos])) << 8) << 8, 4).substring(0, 2));
if (rfc1113compliant) while (out.length() % 4 > 0) out.append("=");
// return result
+ //assert lene == out.length() : "lene = " + lene + ", out.len = " + out.length();
return new String(out);
}
diff --git a/source/de/anomic/kelondro/text/AbstractBufferedIndex.java b/source/de/anomic/kelondro/text/AbstractBufferedIndex.java
index f87b229d9..ec21457df 100644
--- a/source/de/anomic/kelondro/text/AbstractBufferedIndex.java
+++ b/source/de/anomic/kelondro/text/AbstractBufferedIndex.java
@@ -39,7 +39,7 @@ public abstract class AbstractBufferedIndex<ReferenceType extends Reference> ext
super(factory);
}
- public synchronized TreeSet<ReferenceContainer<ReferenceType>> references(final String startHash, final boolean rot, int count, boolean ram) throws IOException {
+ public synchronized TreeSet<ReferenceContainer<ReferenceType>> references(final byte[] startHash, final boolean rot, int count, boolean ram) throws IOException {
// creates a set of indexContainers
// this does not use the cache
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, this.ordering().clone());
diff --git a/source/de/anomic/kelondro/text/AbstractIndex.java b/source/de/anomic/kelondro/text/AbstractIndex.java
index 8c835de5a..e8abe06e8 100644
--- a/source/de/anomic/kelondro/text/AbstractIndex.java
+++ b/source/de/anomic/kelondro/text/AbstractIndex.java
@@ -42,10 +42,10 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
this.factory = factory;
}
- public int remove(final Set<String> wordHashes, final String urlHash) throws IOException {
+ public int remove(final TreeSet<byte[]> termHashes, final String urlHash) throws IOException {
// remove the same url hashes for multiple words
// this is mainly used when correcting a index after a search
- final Iterator<String> i = wordHashes.iterator();
+ final Iterator<byte[]> i = termHashes.iterator();
int c = 0;
while (i.hasNext()) {
if (remove(i.next(), urlHash)) c++;
@@ -53,16 +53,16 @@ public abstract class AbstractIndex <ReferenceType extends Reference> implements
return c;
}
- public void remove(final Set<String> wordHashes, final Set<String> urlHashes) throws IOException {
+ public void remove(final TreeSet<byte[]> termHashes, final Set<String> urlHashes) throws IOException {
// remove the same url hashes for multiple words
// this is mainly used when correcting a index after a search
- final Iterator<String> i = wordHashes.iterator();
+ final Iterator<byte[]> i = termHashes.iterator();
while (i.hasNext()) {
remove(i.next(), urlHashes);
}
}
- public synchronized TreeSet<ReferenceContainer<ReferenceType>> references(final String startHash, final boolean rot, int count) throws IOException {
+ public synchronized TreeSet<ReferenceContainer<ReferenceType>> references(final byte[] startHash, final boolean rot, int count) throws IOException {
// creates a set of indexContainers
// this does not use the cache
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, this.ordering().clone());
diff --git a/source/de/anomic/kelondro/text/BufferedIndex.java b/source/de/anomic/kelondro/text/BufferedIndex.java
index 72ea61a54..fccee1096 100644
--- a/source/de/anomic/kelondro/text/BufferedIndex.java
+++ b/source/de/anomic/kelondro/text/BufferedIndex.java
@@ -119,7 +119,7 @@ public interface BufferedIndex<ReferenceType extends Reference> extends Index<Re
* @throws IOException
*/
public CloneableIterator<ReferenceContainer<ReferenceType>> references(
- String startHash,
+ byte[] startHash,
boolean rot,
boolean buffer
) throws IOException;
@@ -138,7 +138,7 @@ public interface BufferedIndex<ReferenceType extends Reference> extends Index<Re
* @throws IOException
*/
public TreeSet<ReferenceContainer<ReferenceType>> references(
- String startHash,
+ byte[] startHash,
boolean rot,
int count,
boolean buffer
diff --git a/source/de/anomic/kelondro/text/BufferedIndexCollection.java b/source/de/anomic/kelondro/text/BufferedIndexCollection.java
index 70c28cd5e..4cd1cde13 100644
--- a/source/de/anomic/kelondro/text/BufferedIndexCollection.java
+++ b/source/de/anomic/kelondro/text/BufferedIndexCollection.java
@@ -111,23 +111,23 @@ public final class BufferedIndexCollection<ReferenceType extends Reference> exte
cacheFlushControl();
}
- public void add(final String wordHash, final ReferenceType entry) throws IOException {
+ public void add(final byte[] wordHash, final ReferenceType entry) throws IOException {
// add the entry
buffer.add(wordHash, entry);
cacheFlushControl();
}
- public boolean has(final String wordHash) {
+ public boolean has(final byte[] wordHash) {
if (buffer.has(wordHash)) return true;
if (collections.has(wordHash)) return true;
return false;
}
- public int count(String key) {
+ public int count(byte[] key) {
return buffer.count(key) + collections.count(key);
}
- public ReferenceContainer<ReferenceType> get(final String wordHash, final Set<String> urlselection) {
+ public ReferenceContainer<ReferenceType> get(final byte[] wordHash, final Set<String> urlselection) {
if (wordHash == null) {
// wrong input
return null;
@@ -172,7 +172,7 @@ public final class BufferedIndexCollection<ReferenceType extends Reference> exte
return container;
}
- public ReferenceContainer<ReferenceType> delete(final String wordHash) {
+ public ReferenceContainer<ReferenceType> delete(final byte[] wordHash) {
final ReferenceContainer<ReferenceType> c = new ReferenceContainer<ReferenceType>(
factory,
wordHash,
@@ -183,29 +183,29 @@ public final class BufferedIndexCollection<ReferenceType extends Reference> exte
return c;
}
- public boolean remove(final String wordHash, final String urlHash) {
+ public boolean remove(final byte[] wordHash, final String urlHash) {
boolean removed = false;
removed = removed | (buffer.remove(wordHash, urlHash));
removed = removed | (collections.remove(wordHash, urlHash));
return removed;
}
- public int remove(final String wordHash, final Set<String> urlHashes) {
+ public int remove(final byte[] wordHash, final Set<String> urlHashes) {
int removed = 0;
removed += buffer.remove(wordHash, urlHashes);
removed += collections.remove(wordHash, urlHashes);
return removed;
}
- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final String startHash, final boolean rot, final boolean ram) throws IOException {
+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final byte[] startHash, final boolean rot, final boolean ram) throws IOException {
final CloneableIterator<ReferenceContainer<ReferenceType>> i = wordContainers(startHash, ram);
if (rot) {
- return new RotateIterator<ReferenceContainer<ReferenceType>>(i, new String(Base64Order.zero(startHash.length())), buffer.size() + ((ram) ? 0 : collections.size()));
+ return new RotateIterator<ReferenceContainer<ReferenceType>>(i, Base64Order.zero(startHash.length), buffer.size() + ((ram) ? 0 : collections.size()));
}
return i;
}
- private synchronized CloneableIterator<ReferenceContainer<ReferenceType>> wordContainers(final String startWordHash, final boolean ram) throws IOException {
+ private synchronized CloneableIterator<ReferenceContainer<ReferenceType>> wordContainers(final byte[] startWordHash, final boolean ram) throws IOException {
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, buffer.ordering().clone());
ReferenceContainer<ReferenceType> emptyContainer = ReferenceContainer.emptyContainer(factory, startWordHash, 0);
containerOrder.rotate(emptyContainer);
@@ -308,7 +308,7 @@ public final class BufferedIndexCollection<ReferenceType extends Reference> exte
}
private ReferenceContainer<ReferenceType> flushContainer(final IndexBuffer<ReferenceType> ram) {
- String wordHash;
+ byte[] wordHash;
ReferenceContainer<ReferenceType> c;
wordHash = ram.maxScoreWordHash();
c = ram.get(wordHash, null);
@@ -331,7 +331,7 @@ public final class BufferedIndexCollection<ReferenceType extends Reference> exte
return collections.ordering();
}
- public CloneableIterator<ReferenceContainer<ReferenceType>> references(String startWordHash, boolean rot) {
+ public CloneableIterator<ReferenceContainer<ReferenceType>> references(byte[] startWordHash, boolean rot) {
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, this.buffer.ordering().clone());
return new MergeIterator<ReferenceContainer<ReferenceType>>(
this.buffer.references(startWordHash, false),
diff --git a/source/de/anomic/kelondro/text/Index.java b/source/de/anomic/kelondro/text/Index.java
index ac4ea9e2a..d10eed8e0 100644
--- a/source/de/anomic/kelondro/text/Index.java
+++ b/source/de/anomic/kelondro/text/Index.java
@@ -56,14 +56,14 @@ public interface Index <ReferenceType extends Reference> {
* @param entry
* @throws IOException
*/
- public void add(final String termHash, final ReferenceType entry) throws IOException;
+ public void add(final byte[] termHash, final ReferenceType entry) throws IOException;
/**
* check if there are references stored to the given word hash
* @param termHash
* @return true if references exist, false if not
*/
- public boolean has(String termHash); // should only be used if in case that true is returned the getContainer is NOT called
+ public boolean has(final byte[] termHash); // should only be used if in case that true is returned the getContainer is NOT called
/**
* count the number of references for the given word
@@ -72,7 +72,7 @@ public interface Index <ReferenceType extends Reference> {
* @param termHash
* @return the number of references to the given word
*/
- public int count(final String termHash);
+ public int count(final byte[] termHash);
/**
* get the references to a given word.
@@ -83,7 +83,7 @@ public interface Index <ReferenceType extends Reference> {
* @return the references
* @throws IOException
*/
- public ReferenceContainer<ReferenceType> get(String termHash, Set<String> referenceselection) throws IOException;
+ public ReferenceContainer<ReferenceType> get(byte[] termHash, Set<String> referenceselection) throws IOException;
/**
* delete all references for a word
@@ -91,7 +91,7 @@ public interface Index <ReferenceType extends Reference> {
* @return the deleted references
* @throws IOException
*/
- public ReferenceContainer<ReferenceType> delete(String termHash) throws IOException;
+ public ReferenceContainer<ReferenceType> delete(byte[] termHash) throws IOException;
/**
* remove a specific reference entry
@@ -100,7 +100,7 @@ public interface Index <ReferenceType extends Reference> {
* @return
* @throws IOException
*/
- public boolean remove(String termHash, String referenceHash) throws IOException;
+ public boolean remove(byte[] termHash, String referenceHash) throws IOException;
/**
* remove a set of reference entries for a given word
@@ -109,11 +109,11 @@ public interface Index <ReferenceType extends Reference> {
* @return
* @throws IOException
*/
- public int remove(String termHash, Set<String> referenceHashes) throws IOException;
+ public int remove(final byte[] termHash, Set<String> referenceHashes) throws IOException;
- public int remove(final Set<String> termHashes, final String urlHash) throws IOException;
+ public int remove(final TreeSet<byte[]> termHashes, final String urlHash) throws IOException;
- public void remove(final Set<String> termHashes, final Set<String> urlHashes) throws IOException;
+ public void remove(final TreeSet<byte[]> termHashes, final Set<String> urlHashes) throws IOException;
/**
* iterate all references from the beginning of a specific word hash
@@ -124,13 +124,13 @@ public interface Index <ReferenceType extends Reference> {
* @throws IOException
*/
public CloneableIterator<ReferenceContainer<ReferenceType>> references(
- String startHash,
+ byte[] startHash,
boolean rot
) throws IOException;
public TreeSet<ReferenceContainer<ReferenceType>> references(
- String startHash,
+ byte[] startHash,
boolean rot,
int count
) throws IOException;
diff --git a/source/de/anomic/kelondro/text/IndexBuffer.java b/source/de/anomic/kelondro/text/IndexBuffer.java
index 2a4c669b3..2dc753124 100644
--- a/source/de/anomic/kelondro/text/IndexBuffer.java
+++ b/source/de/anomic/kelondro/text/IndexBuffer.java
@@ -47,8 +47,8 @@ import de.anomic.kelondro.util.Log;
public final class IndexBuffer<ReferenceType extends Reference> extends AbstractIndex<ReferenceType> implements Index<ReferenceType>, IndexReader<ReferenceType>, Iterable<ReferenceContainer<ReferenceType>> {
// class variables
- private final ScoreCluster<String> hashScore;
- private final ScoreCluster<String> hashDate;
+ private final ScoreCluster<byte[]> hashScore;
+ private final ScoreCluster<byte[]> hashDate;
private long initTime;
private int cacheEntityMaxCount; // the maximum number of cache slots for RWI entries
public int cacheReferenceCountLimit; // the maximum number of references to a single RWI entity
@@ -72,8 +72,8 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
// creates a new index cache
// the cache has a back-end where indexes that do not fit in the cache are flushed
- this.hashScore = new ScoreCluster<String>();
- this.hashDate = new ScoreCluster<String>();
+ this.hashScore = new ScoreCluster<byte[]>();
+ this.hashDate = new ScoreCluster<byte[]>();
this.initTime = System.currentTimeMillis();
this.cacheEntityMaxCount = entityCacheMaxSize;
this.cacheReferenceCountLimit = wCacheReferenceCountLimitInit;
@@ -151,14 +151,14 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
return heap.size();
}
- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final String startWordHash, final boolean rot) {
+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final byte[] startWordHash, final boolean rot) {
// we return an iterator object that creates top-level-clones of the indexContainers
// in the cache, so that manipulations of the iterated objects do not change
// objects in the cache.
return heap.references(startWordHash, rot);
}
- public synchronized String maxScoreWordHash() {
+ public synchronized byte[] maxScoreWordHash() {
if (heap == null || heap.size() == 0) return null;
try {
return hashScore.getMaxObject();
@@ -168,7 +168,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
return null;
}
- public String bestFlushWordHash() {
+ public byte[] bestFlushWordHash() {
// select appropriate hash
// we have 2 different methods to find a good hash:
// - the oldest entry in the cache
@@ -176,7 +176,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
if (heap == null || heap.size() == 0) return null;
try {
//return hashScore.getMaxObject();
- String hash = null;
+ byte[] hash = null;
final int count = hashScore.getMaxScore();
if ((count >= cacheReferenceCountLimit) &&
((hash = hashScore.getMaxObject()) != null)) {
@@ -212,7 +212,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
public synchronized ArrayList<ReferenceContainer<ReferenceType>> bestFlushContainers(final int count) {
final ArrayList<ReferenceContainer<ReferenceType>> containerList = new ArrayList<ReferenceContainer<ReferenceType>>();
- String hash;
+ byte[] hash;
ReferenceContainer<ReferenceType> container;
for (int i = 0; i < count; i++) {
hash = bestFlushWordHash();
@@ -235,15 +235,15 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
return (((long) intTime) * (long) 1000) + initTime;
}
- public boolean has(final String wordHash) {
+ public boolean has(final byte[] wordHash) {
return heap.has(wordHash);
}
- public int count(String key) {
+ public int count(byte[] key) {
return this.heap.count(key);
}
- public synchronized ReferenceContainer<ReferenceType> get(final String wordHash, final Set<String> urlselection) {
+ public synchronized ReferenceContainer<ReferenceType> get(final byte[] wordHash, final Set<String> urlselection) {
if (wordHash == null) return null;
// retrieve container
@@ -261,7 +261,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
return container;
}
- public synchronized ReferenceContainer<ReferenceType> delete(final String wordHash) {
+ public synchronized ReferenceContainer<ReferenceType> delete(final byte[] wordHash) {
// returns the index that had been deleted
if (wordHash == null || heap == null) return null;
final ReferenceContainer<ReferenceType> container = heap.delete(wordHash);
@@ -270,7 +270,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
return container;
}
- public synchronized boolean remove(final String wordHash, final String urlHash) {
+ public synchronized boolean remove(final byte[] wordHash, final String urlHash) {
final boolean removed = heap.remove(wordHash, urlHash);
if (removed) {
if (heap.has(wordHash)) {
@@ -285,7 +285,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
return false;
}
- public synchronized int remove(final String wordHash, final Set<String> urlHashes) {
+ public synchronized int remove(final byte[] wordHash, final Set<String> urlHashes) {
if (urlHashes.size() == 0) return 0;
final int c = heap.remove(wordHash, urlHashes);
if (c > 0) {
@@ -311,7 +311,7 @@ public final class IndexBuffer<ReferenceType extends Reference> extends Abstract
hashDate.setScore(container.getTermHash(), intTime(System.currentTimeMillis()));
}
- public void add(final String wordHash, final ReferenceType entry) throws IOException {
+ public void add(final byte[] wordHash, final ReferenceType entry) throws IOException {
if (entry == null || heap == null) return;
// put new words into cache
diff --git a/source/de/anomic/kelondro/text/IndexCell.java b/source/de/anomic/kelondro/text/IndexCell.java
index ccb0b4606..f7a33cbc2 100644
--- a/source/de/anomic/kelondro/text/IndexCell.java
+++ b/source/de/anomic/kelondro/text/IndexCell.java
@@ -102,8 +102,8 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
cleanCache();
}
- public synchronized void add(String hash, ReferenceType entry) throws IOException {
- this.ram.add(hash, entry);
+ public synchronized void add(byte[] termHash, ReferenceType entry) throws IOException {
+ this.ram.add(termHash, entry);
serverProfiling.update("wordcache", Long.valueOf(this.ram.size()), true);
cleanCache();
}
@@ -111,12 +111,12 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
/**
* checks if there is any container for this termHash, either in RAM or any BLOB
*/
- public boolean has(String termHash) {
+ public boolean has(byte[] termHash) {
if (this.ram.has(termHash)) return true;
return this.array.has(termHash);
}
- public int count(String termHash) {
+ public int count(byte[] termHash) {
ReferenceContainer<ReferenceType> c0 = this.ram.get(termHash, null);
ReferenceContainer<ReferenceType> c1;
try {
@@ -136,7 +136,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
* all containers in the BLOBs and the RAM are merged and returned
* @throws IOException
*/
- public ReferenceContainer<ReferenceType> get(String termHash, Set<String> urlselection) throws IOException {
+ public ReferenceContainer<ReferenceType> get(byte[] termHash, Set<String> urlselection) throws IOException {
ReferenceContainer<ReferenceType> c0 = this.ram.get(termHash, null);
ReferenceContainer<ReferenceType> c1 = this.array.get(termHash);
if (c1 == null) {
@@ -152,7 +152,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
* the deleted containers are merged and returned as result of the method
* @throws IOException
*/
- public ReferenceContainer<ReferenceType> delete(String termHash) throws IOException {
+ public ReferenceContainer<ReferenceType> delete(byte[] termHash) throws IOException {
ReferenceContainer<ReferenceType> c0 = this.ram.delete(termHash);
ReferenceContainer<ReferenceType> c1 = this.array.get(termHash);
if (c1 == null) {
@@ -172,17 +172,17 @@ 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(String termHash, Set<String> urlHashes) throws IOException {
+ public int remove(byte[] termHash, Set<String> urlHashes) throws IOException {
int reduced = this.array.replace(termHash, new RemoveRewriter<ReferenceType>(urlHashes));
return reduced / this.array.rowdef().objectsize;
}
- public boolean remove(String termHash, String urlHash) throws IOException {
+ public boolean remove(byte[] termHash, String urlHash) throws IOException {
int reduced = this.array.replace(termHash, new RemoveRewriter<ReferenceType>(urlHash));
return reduced > 0;
}
- private static class RemoveRewriter<RT extends Reference> implements ReferenceContainerArray.ContainerRewriter<RT> {
+ private static class RemoveRewriter<ReferenceType extends Reference> implements ReferenceContainerArray.ContainerRewriter<ReferenceType> {
Set<String> urlHashes;
@@ -195,14 +195,14 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
this.urlHashes.add(urlHash);
}
- public ReferenceContainer<RT> rewrite(ReferenceContainer<RT> container) {
+ public ReferenceContainer<ReferenceType> rewrite(ReferenceContainer<ReferenceType> container) {
container.removeEntries(urlHashes);
return container;
}
}
- public CloneableIterator<ReferenceContainer<ReferenceType>> references(String starttermHash, boolean rot) {
+ public CloneableIterator<ReferenceContainer<ReferenceType>> references(byte[] starttermHash, boolean rot) {
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, this.ram.rowdef().getOrdering().clone());
containerOrder.rotate(new ReferenceContainer<ReferenceType>(factory, starttermHash, this.ram.rowdef(), 0));
return new MergeIterator<ReferenceContainer<ReferenceType>>(
@@ -218,7 +218,7 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
true);
}
- public CloneableIterator<ReferenceContainer<ReferenceType>> references(String startTermHash, boolean rot, boolean ram) {
+ public CloneableIterator<ReferenceContainer<ReferenceType>> references(byte[] startTermHash, boolean rot, boolean ram) {
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, this.ram.rowdef().getOrdering().clone());
containerOrder.rotate(new ReferenceContainer<ReferenceType>(factory, startTermHash, this.ram.rowdef(), 0));
if (ram) {
diff --git a/source/de/anomic/kelondro/text/IndexCollection.java b/source/de/anomic/kelondro/text/IndexCollection.java
index a1c141f70..f8de3eb8e 100644
--- a/source/de/anomic/kelondro/text/IndexCollection.java
+++ b/source/de/anomic/kelondro/text/IndexCollection.java
@@ -49,18 +49,15 @@ import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.order.ByteOrder;
import de.anomic.kelondro.order.CloneableIterator;
import de.anomic.kelondro.order.Digest;
-import de.anomic.kelondro.order.NaturalOrder;
import de.anomic.kelondro.order.RotateIterator;
import de.anomic.kelondro.table.EcoTable;
import de.anomic.kelondro.table.FixedWidthArray;
import de.anomic.kelondro.table.FlexTable;
-import de.anomic.kelondro.text.referencePrototype.WordReference;
import de.anomic.kelondro.util.FileUtils;
import de.anomic.kelondro.util.MemoryControl;
import de.anomic.kelondro.util.kelondroException;
import de.anomic.kelondro.util.kelondroOutOfLimitsException;
import de.anomic.kelondro.util.Log;
-import de.anomic.plasma.plasmaWordIndex;
import de.anomic.yacy.yacyURL;
public class IndexCollection<ReferenceType extends Reference> extends AbstractIndex<ReferenceType> implements Index<ReferenceType> {
@@ -164,7 +161,7 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
return index.row().objectOrder;
}
- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final String startWordHash, final boolean rot) {
+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final byte[] startWordHash, final boolean rot) {
return new wordContainersIterator(startWordHash, rot);
}
@@ -173,13 +170,13 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
private final Iterator<Object[]> wci;
private final boolean rot;
- public wordContainersIterator(final String startWordHash, final boolean rot) {
+ public wordContainersIterator(final byte[] startWordHash, final boolean rot) {
this.rot = rot;
- this.wci = keycollections(startWordHash.getBytes(), Base64Order.zero(startWordHash.length()), rot);
+ this.wci = keycollections(startWordHash, Base64Order.zero(startWordHash.length), rot);
}
public wordContainersIterator clone(final Object secondWordHash) {
- return new wordContainersIterator((String) secondWordHash, rot);
+ return new wordContainersIterator((byte[]) secondWordHash, rot);
}
public boolean hasNext() {
@@ -192,7 +189,7 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
final byte[] key = (byte[]) oo[0];
final RowSet collection = (RowSet) oo[1];
if (collection == null) return null;
- return new ReferenceContainer<ReferenceType>(factory, new String(key), collection);
+ return new ReferenceContainer<ReferenceType>(factory, key, collection);
}
public void remove() {
@@ -201,13 +198,9 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
}
- public boolean has(final String wordHash) {
- return this.has(wordHash.getBytes());
- }
-
- public ReferenceContainer<ReferenceType> get(final String wordHash, final Set<String> urlselection) {
+ public ReferenceContainer<ReferenceType> get(final byte[] wordHash, final Set<String> urlselection) {
try {
- final RowSet collection = this.get(wordHash.getBytes());
+ final RowSet collection = this.get(wordHash);
if (collection != null) collection.select(urlselection);
if ((collection == null) || (collection.size() == 0)) return null;
return new ReferenceContainer<ReferenceType>(factory, wordHash, collection);
@@ -216,31 +209,28 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
}
}
- public ReferenceContainer<ReferenceType> delete(final String wordHash) {
+ public ReferenceContainer<ReferenceType> delete(final byte[] wordHash) {
try {
- final RowSet collection = this.delete(wordHash.getBytes());
- if (collection == null) return null;
- return new ReferenceContainer<ReferenceType>(factory, wordHash, collection);
+ // find an entry, if one exists
+ final Row.Entry indexrow = index.remove(wordHash);
+ if (indexrow == null) return null;
+ final RowSet removedCollection = getdelete(indexrow, true);
+ assert (removedCollection != null);
+ if (removedCollection == null) return null;
+ return new ReferenceContainer<ReferenceType>(factory, wordHash, removedCollection);
} catch (final IOException e) {
return null;
}
}
- public boolean remove(final String wordHash, final String urlHash) {
+ public boolean remove(final byte[] wordHash, final String urlHash) {
final HashSet<String> hs = new HashSet<String>();
hs.add(urlHash);
- return remove(wordHash, hs) == 1;
- }
-
- public int remove(final String wordHash, final Set<String> urlHashes) {
try {
- return this.remove(wordHash.getBytes(), urlHashes);
- } catch (final kelondroOutOfLimitsException e) {
- e.printStackTrace();
- return 0;
- } catch (final IOException e) {
+ return remove(wordHash, hs) == 1;
+ } catch (kelondroOutOfLimitsException e) {
e.printStackTrace();
- return 0;
+ return false;
}
}
@@ -255,7 +245,7 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
}
}
- public void add(String wordhash, ReferenceType entry) {
+ public void add(byte[] wordhash, ReferenceType entry) {
if (entry == null) return;
try {
ReferenceContainer<ReferenceType> container = new ReferenceContainer<ReferenceType>(factory, wordhash, this.payloadrow, 1);
@@ -268,9 +258,9 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
}
}
- public int count(String key) {
+ public int count(byte[] key) {
try {
- final RowSet collection = this.get(key.getBytes());
+ final RowSet collection = this.get(key);
if (collection == null) return 0;
return collection.size();
} catch (final IOException e) {
@@ -711,7 +701,7 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
private synchronized void merge(final ReferenceContainer<ReferenceType> container) throws IOException, kelondroOutOfLimitsException {
if ((container == null) || (container.size() == 0)) return;
- final byte[] key = container.getTermHash().getBytes();
+ final byte[] key = container.getTermHash();
// first find an old entry, if one exists
Row.Entry indexrow = index.get(key);
@@ -841,77 +831,84 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
}
}
- private synchronized int remove(final byte[] key, final Set<String> removekeys) throws IOException, kelondroOutOfLimitsException {
+ public synchronized int remove(final byte[] key, final Set<String> removekeys) {
if ((removekeys == null) || (removekeys.size() == 0)) return 0;
// first find an old entry, if one exists
- final Row.Entry indexrow = index.get(key);
-
- if (indexrow == null) return 0;
+ Row.Entry indexrow;
+ try {
+ indexrow = index.get(key);
+
- // overwrite the old collection
- // read old information
- final int oldchunksize = (int) indexrow.getColLong(idx_col_chunksize); // needed only for migration
- final int oldchunkcount = (int) indexrow.getColLong(idx_col_chunkcount); // the number if rows in the collection
- final int oldrownumber = (int) indexrow.getColLong(idx_col_indexpos); // index of the entry in array
- final int oldPartitionNumber = indexrow.getColByte(idx_col_clusteridx); // points to array file
- assert (oldPartitionNumber >= arrayIndex(oldchunkcount));
+ if (indexrow == null) return 0;
+
+ // overwrite the old collection
+ // read old information
+ final int oldchunksize = (int) indexrow.getColLong(idx_col_chunksize); // needed only for migration
+ final int oldchunkcount = (int) indexrow.getColLong(idx_col_chunkcount); // the number if rows in the collection
+ final int oldrownumber = (int) indexrow.getColLong(idx_col_indexpos); // index of the entry in array
+ final int oldPartitionNumber = indexrow.getColByte(idx_col_clusteridx); // points to array file
+ assert (oldPartitionNumber >= arrayIndex(oldchunkcount));
- int removed = 0;
- assert (removekeys != null);
- // load the old collection and remove keys
- RowSet oldcollection = null;
- try {
- oldcollection = getwithparams(indexrow, oldchunksize, oldchunkcount, oldPartitionNumber, oldrownumber, serialNumber, false);
- } catch (kelondroException e) {
- // some internal problems occurred. however, go on like there was no old collection
- e.printStackTrace();
- }
- // the oldcollection may be null here!
-
- if (oldcollection != null && oldcollection.size() > 0) {
- // remove the keys from the set
- final Iterator<String> i = removekeys.iterator();
- while (i.hasNext()) {
- if (oldcollection.remove(i.next().getBytes()) != null) removed++;
+ int removed = 0;
+ assert (removekeys != null);
+ // load the old collection and remove keys
+ RowSet oldcollection = null;
+ try {
+ oldcollection = getwithparams(indexrow, oldchunksize, oldchunkcount, oldPartitionNumber, oldrownumber, serialNumber, false);
+ } catch (kelondroException e) {
+ // some internal problems occurred. however, go on like there was no old collection
+ e.printStackTrace();
}
- oldcollection.sort();
- oldcollection.trim(false);
- }
-
- // in case of an error or an empty collection, remove the collection:
- if (oldcollection == null || oldcollection.size() == 0) {
- // delete the index entry and the array
- array_remove(
- oldPartitionNumber, serialNumber, this.payloadrow.objectsize,
- oldrownumber);
- index.remove(key);
- return removed;
- }
-
- // now write to a new partition (which may be the same partition as the old one)
- final int newPartitionNumber = arrayIndex(oldcollection.size());
+ // the oldcollection may be null here!
+
+ if (oldcollection != null && oldcollection.size() > 0) {
+ // remove the keys from the set
+ final Iterator<String> i = removekeys.iterator();
+ while (i.hasNext()) {
+ if (oldcollection.remove(i.next().getBytes()) != null) removed++;
+ }
+ oldcollection.sort();
+ oldcollection.trim(false);
+ }
+
+ // in case of an error or an empty collection, remove the collection:
+ if (oldcollection == null || oldcollection.size() == 0) {
+ // delete the index entry and the array
+ array_remove(
+ oldPartitionNumber, serialNumber, this.payloadrow.objectsize,
+ oldrownumber);
+ index.remove(key);
+ return removed;
+ }
+
+ // now write to a new partition (which may be the same partition as the old one)
+ final int newPartitionNumber = arrayIndex(oldcollection.size());
- // see if we need new space or if we can overwrite the old space
- if (oldPartitionNumber == newPartitionNumber) {
- array_replace(
- key, oldcollection, indexrow,
- oldPartitionNumber, serialNumber, this.payloadrow.objectsize,
- oldrownumber); // modifies indexrow
- } else {
- array_remove(
- oldPartitionNumber, serialNumber, this.payloadrow.objectsize,
- oldrownumber);
- array_add(
- key, oldcollection, indexrow,
- newPartitionNumber, serialNumber, this.payloadrow.objectsize); // modifies indexrow
+ // see if we need new space or if we can overwrite the old space
+ if (oldPartitionNumber == newPartitionNumber) {
+ array_replace(
+ key, oldcollection, indexrow,
+ oldPartitionNumber, serialNumber, this.payloadrow.objectsize,
+ oldrownumber); // modifies indexrow
+ } else {
+ array_remove(
+ oldPartitionNumber, serialNumber, this.payloadrow.objectsize,
+ oldrownumber);
+ array_add(
+ key, oldcollection, indexrow,
+ newPartitionNumber, serialNumber, this.payloadrow.objectsize); // modifies indexrow
+ }
+ index.put(indexrow); // write modified indexrow
+ return removed;
+ } catch (IOException e1) {
+ e1.printStackTrace();
}
- index.put(indexrow); // write modified indexrow
- return removed;
+ return 0;
}
- private synchronized boolean has(final byte[] key) {
+ public synchronized boolean has(final byte[] key) {
return index.has(key);
}
@@ -924,14 +921,6 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
return col;
}
- private synchronized RowSet delete(final byte[] key) throws IOException {
- // find an entry, if one exists
- final Row.Entry indexrow = index.remove(key);
- if (indexrow == null) return null;
- final RowSet removedCollection = getdelete(indexrow, true);
- assert (removedCollection != null);
- return removedCollection;
- }
private RowSet getdelete(final Row.Entry indexrow, final boolean remove) throws IOException {
// call this only within a synchronized(index) environment
@@ -1054,54 +1043,4 @@ public class IndexCollection<ReferenceType extends Reference> extends AbstractIn
this.arrays = null;
}
- public static void main(final String[] args) {
-
- // define payload structure
- final Row rowdef = new Row("byte[] a-10, byte[] b-80", NaturalOrder.naturalOrder);
-
- final File path = new File(args[0]);
- final String filenameStub = args[1];
- try {
- // initialize collection index
- final IndexCollection<WordReference> collectionIndex = new IndexCollection<WordReference>(
- path, filenameStub,
- plasmaWordIndex.wordReferenceFactory,
- 9 /*keyLength*/,
- NaturalOrder.naturalOrder,
- 7, rowdef, false);
-
- // fill index with values
- RowSet collection = new RowSet(rowdef, 0);
- collection.addUnique(rowdef.newEntry(new byte[][]{"abc".getBytes(), "efg".getBytes()}));
- collectionIndex.put("erstes".getBytes(), collection);
-
- for (int i = 1; i <= 170; i++) {
- collection = new RowSet(rowdef, 0);
- for (int j = 0; j < i; j++) {
- collection.addUnique(rowdef.newEntry(new byte[][]{("abc" + j).getBytes(), "xxx".getBytes()}));
- }
- System.out.println("put key-" + i + ": " + collection.toString());
- collectionIndex.put(("key-" + i).getBytes(), collection);
- }
-
- // extend collections with more values
- for (int i = 0; i <= 170; i++) {
- collection = new RowSet(rowdef, 0);
- for (int j = 0; j < i; j++) {
- collection.addUnique(rowdef.newEntry(new byte[][]{("def" + j).getBytes(), "xxx".getBytes()}));
- }
- collectionIndex.merge(new ReferenceContainer<WordReference>(plasmaWordIndex.wordReferenceFactory,"key-" + i, collection));
- }
-
- // printout of index
- collectionIndex.close();
- final EcoTable index = new EcoTable(new File(path, filenameStub + ".index"), IndexCollection.indexRow(9, NaturalOrder.naturalOrder), EcoTable.tailCacheUsageAuto, 0, 0);
- index.print();
- index.close();
- } catch (final IOException e) {
- e.printStackTrace();
- }
-
- }
-
}
diff --git a/source/de/anomic/kelondro/text/IndexCollectionMigration.java b/source/de/anomic/kelondro/text/IndexCollectionMigration.java
index ac608256d..58034a772 100644
--- a/source/de/anomic/kelondro/text/IndexCollectionMigration.java
+++ b/source/de/anomic/kelondro/text/IndexCollectionMigration.java
@@ -145,7 +145,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
}
}
- public void add(final String wordHash, final ReferenceType entry) throws IOException {
+ public void add(final byte[] wordHash, final ReferenceType entry) throws IOException {
if (this.collections != null) {
ReferenceContainer<ReferenceType> e = this.collections.delete(wordHash);
if (e != null) {
@@ -159,7 +159,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
}
}
- public boolean has(final String wordHash) {
+ public boolean has(final byte[] wordHash) {
if (this.collections != null) {
ReferenceContainer<ReferenceType> e = this.collections.delete(wordHash);
if (e != null) {
@@ -177,7 +177,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
}
}
- public int count(String wordHash) {
+ public int count(byte[] wordHash) {
if (this.collections != null) {
ReferenceContainer<ReferenceType> e = this.collections.delete(wordHash);
if (e != null) {
@@ -195,7 +195,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
}
}
- public ReferenceContainer<ReferenceType> get(final String wordHash, final Set<String> urlselection) throws IOException {
+ public ReferenceContainer<ReferenceType> get(final byte[] wordHash, final Set<String> urlselection) throws IOException {
if (wordHash == null) {
// wrong input
return null;
@@ -209,7 +209,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
return this.cell.get(wordHash, urlselection);
}
- public ReferenceContainer<ReferenceType> delete(final String wordHash) throws IOException {
+ public ReferenceContainer<ReferenceType> delete(final byte[] wordHash) throws IOException {
ReferenceContainer<ReferenceType> cc = cell.delete(wordHash);
if (cc == null) {
if (collections == null) return null;
@@ -222,7 +222,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
}
}
- public boolean remove(final String wordHash, final String urlHash) throws IOException {
+ public boolean remove(final byte[] wordHash, final String urlHash) throws IOException {
if (this.collections != null) {
ReferenceContainer<ReferenceType> e = this.collections.delete(wordHash);
if (e != null) cell.add(e);
@@ -230,7 +230,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
return cell.remove(wordHash, urlHash);
}
- public int remove(final String wordHash, final Set<String> urlHashes) throws IOException {
+ public int remove(final byte[] wordHash, final Set<String> urlHashes) throws IOException {
if (this.collections != null) {
ReferenceContainer<ReferenceType> e = this.collections.delete(wordHash);
if (e != null) cell.add(e);
@@ -238,15 +238,15 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
return cell.remove(wordHash, urlHashes);
}
- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final String startHash, final boolean rot, final boolean ram) throws IOException {
+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final byte[] startHash, final boolean rot, final boolean ram) throws IOException {
final CloneableIterator<ReferenceContainer<ReferenceType>> i = wordContainers(startHash, ram);
if (rot) {
- return new RotateIterator<ReferenceContainer<ReferenceType>>(i, new String(Base64Order.zero(startHash.length())), cell.size() + ((ram) ? 0 : collections.size()));
+ return new RotateIterator<ReferenceContainer<ReferenceType>>(i, Base64Order.zero(startHash.length), cell.size() + ((ram) ? 0 : collections.size()));
}
return i;
}
- private synchronized CloneableIterator<ReferenceContainer<ReferenceType>> wordContainers(final String startWordHash, final boolean ram) throws IOException {
+ private synchronized CloneableIterator<ReferenceContainer<ReferenceType>> wordContainers(final byte[] startWordHash, final boolean ram) throws IOException {
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, cell.ordering().clone());
ReferenceContainer<ReferenceType> emptyContainer = ReferenceContainer.emptyContainer(factory, startWordHash, 0);
containerOrder.rotate(emptyContainer);
@@ -325,7 +325,7 @@ public final class IndexCollectionMigration<ReferenceType extends Reference> ext
return cell.ordering();
}
- public CloneableIterator<ReferenceContainer<ReferenceType>> references(String startWordHash, boolean rot) {
+ public CloneableIterator<ReferenceContainer<ReferenceType>> references(byte[] startWordHash, boolean rot) {
final Order<ReferenceContainer<ReferenceType>> containerOrder = new ReferenceContainerOrder<ReferenceType>(factory, this.cell.ordering().clone());
if (this.collections == null) return this.cell.references(startWordHash, rot);
//else
diff --git a/source/de/anomic/kelondro/text/IndexReader.java b/source/de/anomic/kelondro/text/IndexReader.java
index 2874990d0..951e1dc44 100644
--- a/source/de/anomic/kelondro/text/IndexReader.java
+++ b/source/de/anomic/kelondro/text/IndexReader.java
@@ -33,9 +33,9 @@ import de.anomic.kelondro.order.CloneableIterator;
public interface IndexReader<ReferenceType extends Reference> {
public int size();
- public boolean has(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called
- public ReferenceContainer<ReferenceType> get(String wordHash, Set<String> urlselection);
- public CloneableIterator<ReferenceContainer<ReferenceType>> references(String startWordHash, boolean rot);
+ 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 CloneableIterator<ReferenceContainer<ReferenceType>> references(byte[] startWordHash, boolean rot);
public void close();
}
diff --git a/source/de/anomic/kelondro/text/ReferenceContainer.java b/source/de/anomic/kelondro/text/ReferenceContainer.java
index c04c2b632..c6246e278 100644
--- a/source/de/anomic/kelondro/text/ReferenceContainer.java
+++ b/source/de/anomic/kelondro/text/ReferenceContainer.java
@@ -49,16 +49,16 @@ import de.anomic.kelondro.util.ByteBuffer;
*/
public class ReferenceContainer<ReferenceType extends Reference> extends RowSet {
- private String termHash;
+ private byte[] termHash;
private ReferenceFactory<ReferenceType> factory;
- public ReferenceContainer(final ReferenceFactory<ReferenceType> factory, final String termHash, final RowSet collection) {
+ public ReferenceContainer(final ReferenceFactory<ReferenceType> factory, final byte[] termHash, final RowSet collection) {
super(collection);
this.factory = factory;
this.termHash = termHash;
}
- public ReferenceContainer(final ReferenceFactory<ReferenceType> factory, final String termHash, final Row rowdef, final int objectCount) {
+ public ReferenceContainer(final ReferenceFactory<ReferenceType> factory, final byte[] termHash, final Row rowdef, final int objectCount) {
super(rowdef, objectCount);
this.termHash = termHash;
this.factory = factory;
@@ -71,19 +71,19 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
return newContainer;
}
- public static <RT extends Reference> ReferenceContainer<RT> emptyContainer(final ReferenceFactory<RT> factory, final String wordHash, final int elementCount) {
- return new ReferenceContainer<RT>(factory, wordHash, WordReferenceRow.urlEntryRow, elementCount);
+ public static <ReferenceType extends Reference> ReferenceContainer<ReferenceType> emptyContainer(final ReferenceFactory<ReferenceType> factory, final byte[] termHash, final int elementCount) {
+ return new ReferenceContainer<ReferenceType>(factory, termHash, WordReferenceRow.urlEntryRow, elementCount);
}
- public void setWordHash(final String newWordHash) {
- this.termHash = newWordHash;
+ public void setWordHash(final byte[] newTermHash) {
+ this.termHash = newTermHash;
}
public long updated() {
return super.lastWrote();
}
- public String getTermHash() {
+ public byte[] getTermHash() {
return termHash;
}
@@ -481,11 +481,11 @@ public class ReferenceContainer<ReferenceType extends Reference> extends RowSet
}
public String toString() {
- return "C[" + termHash + "] has " + this.size() + " entries";
+ return "C[" + new String(termHash) + "] has " + this.size() + " entries";
}
public int hashCode() {
- return (int) Base64Order.enhancedCoder.decodeLong(this.termHash.substring(0, 4));
+ return (int) Base64Order.enhancedCoder.decodeLong(new String(this.termHash).substring(0, 4));
}
diff --git a/source/de/anomic/kelondro/text/ReferenceContainerArray.java b/source/de/anomic/kelondro/text/ReferenceContainerArray.java
index 439d33db8..db5695384 100644
--- a/source/de/anomic/kelondro/text/ReferenceContainerArray.java
+++ b/source/de/anomic/kelondro/text/ReferenceContainerArray.java
@@ -107,7 +107,7 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
* objects in the cache.
* @throws IOException
*/
- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> wordContainerIterator(final String startWordHash, final boolean rot, final boolean ram) {
+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> wordContainerIterator(final byte[] startWordHash, final boolean rot, final boolean ram) {
try {
return new heapCacheIterator(startWordHash, rot);
} catch (IOException e) {
@@ -130,15 +130,15 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
private final boolean rot;
private CloneableIterator<byte[]> iterator;
- public heapCacheIterator(final String startWordHash, final boolean rot) throws IOException {
+ public heapCacheIterator(final byte[] startWordHash, final boolean rot) throws IOException {
this.rot = rot;
- this.iterator = array.keys(true, startWordHash.getBytes());
+ this.iterator = array.keys(true, startWordHash);
// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.
}
public heapCacheIterator clone(final Object secondWordHash) {
try {
- return new heapCacheIterator((String) secondWordHash, rot);
+ return new heapCacheIterator((byte[]) secondWordHash, rot);
} catch (IOException e) {
e.printStackTrace();
return null;
@@ -154,14 +154,14 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
public ReferenceContainer<ReferenceType> next() {
try {
if (iterator.hasNext()) {
- return get(new String(iterator.next()));
+ return get(iterator.next());
}
// rotation iteration
if (!rot) {
return null;
}
iterator = array.keys(true, null);
- return get(new String(iterator.next()));
+ return get(iterator.next());
} catch (IOException e) {
e.printStackTrace();
return null;
@@ -185,8 +185,8 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
* @return true, if the key is used in the heap; false othervise
* @throws IOException
*/
- public synchronized boolean has(final String termHash) {
- return this.array.has(termHash.getBytes());
+ public synchronized boolean has(final byte[] termHash) {
+ return this.array.has(termHash);
}
/**
@@ -195,8 +195,8 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
* @return the indexContainer if one exist, null otherwise
* @throws IOException
*/
- public synchronized ReferenceContainer<ReferenceType> get(final String termHash) throws IOException {
- List<byte[]> entries = this.array.getAll(termHash.getBytes());
+ public synchronized ReferenceContainer<ReferenceType> get(final byte[] termHash) throws IOException {
+ List<byte[]> entries = this.array.getAll(termHash);
if (entries == null || entries.size() == 0) return null;
byte[] a = entries.remove(0);
ReferenceContainer<ReferenceType> c = new ReferenceContainer<ReferenceType>(this.factory, termHash, RowSet.importRowSet(a, payloadrow));
@@ -212,21 +212,21 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
* @return the indexContainer if the cache contained the container, null othervise
* @throws IOException
*/
- public synchronized void delete(final String termHash) throws IOException {
+ public synchronized void delete(final byte[] termHash) throws IOException {
// returns the index that had been deleted
- array.remove(termHash.getBytes());
+ array.remove(termHash);
}
- public synchronized int replace(final String termHash, ContainerRewriter<ReferenceType> rewriter) throws IOException {
- return array.replace(termHash.getBytes(), new BLOBRewriter(termHash, rewriter));
+ public synchronized int replace(final byte[] termHash, ContainerRewriter<ReferenceType> rewriter) throws IOException {
+ return array.replace(termHash, new BLOBRewriter(termHash, rewriter));
}
public class BLOBRewriter implements BLOB.Rewriter {
ContainerRewriter<ReferenceType> rewriter;
- String wordHash;
+ byte[] wordHash;
- public BLOBRewriter(String wordHash, ContainerRewriter<ReferenceType> rewriter) {
+ public BLOBRewriter(byte[] wordHash, ContainerRewriter<ReferenceType> rewriter) {
this.rewriter = rewriter;
this.wordHash = wordHash;
}
@@ -239,9 +239,9 @@ public final class ReferenceContainerArray<ReferenceType extends Reference> {
}
}
- public interface ContainerRewriter<RT extends Reference> {
+ public interface ContainerRewriter<ReferenceType extends Reference> {
- public ReferenceContainer<RT> rewrite(ReferenceContainer<RT> container);
+ public ReferenceContainer<ReferenceType> rewrite(ReferenceContainer<ReferenceType> container);
}
diff --git a/source/de/anomic/kelondro/text/ReferenceContainerCache.java b/source/de/anomic/kelondro/text/ReferenceContainerCache.java
index 9c938f439..98d4e560e 100644
--- a/source/de/anomic/kelondro/text/ReferenceContainerCache.java
+++ b/source/de/anomic/kelondro/text/ReferenceContainerCache.java
@@ -50,7 +50,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
private final Row payloadrow;
private final ByteOrder termOrder;
- private SortedMap<String, ReferenceContainer<ReferenceType>> cache;
+ private SortedMap<byte[], ReferenceContainer<ReferenceType>> cache;
/**
* opens an existing heap file in undefined mode
@@ -84,7 +84,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* another dump reading afterwards is not possible
*/
public void initWriteMode() {
- this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer<ReferenceType>>(new ByteOrder.StringOrder(this.termOrder)));
+ this.cache = Collections.synchronizedSortedMap(new TreeMap<byte[], ReferenceContainer<ReferenceType>>(this.termOrder));
}
/**
@@ -95,7 +95,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
public void initWriteModeFromBLOB(final File blobFile) throws IOException {
Log.logInfo("indexContainerRAMHeap", "restoring rwi blob dump '" + blobFile.getName() + "'");
final long start = System.currentTimeMillis();
- this.cache = Collections.synchronizedSortedMap(new TreeMap<String, ReferenceContainer<ReferenceType>>(new ByteOrder.StringOrder(this.termOrder)));
+ this.cache = Collections.synchronizedSortedMap(new TreeMap<byte[], ReferenceContainer<ReferenceType>>(this.termOrder));
int urlCount = 0;
synchronized (cache) {
for (final ReferenceContainer<ReferenceType> container : new blobFileEntries<ReferenceType>(blobFile, factory, this.payloadrow)) {
@@ -125,25 +125,25 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
}
final long startTime = System.currentTimeMillis();
long wordcount = 0, urlcount = 0;
- String wordHash = null, lwh;
+ byte[] wordHash = null, lwh;
ReferenceContainer<ReferenceType> container;
// write wCache
synchronized (cache) {
- for (final Map.Entry<String, ReferenceContainer<ReferenceType>> entry: cache.entrySet()) {
+ for (final Map.Entry<byte[], ReferenceContainer<ReferenceType>> entry: cache.entrySet()) {
// get entries
lwh = wordHash;
wordHash = entry.getKey();
container = entry.getValue();
// check consistency: entries must be ordered
- assert (lwh == null || this.ordering().compare(wordHash.getBytes(), lwh.getBytes()) > 0);
+ assert (lwh == null || this.ordering().compare(wordHash, lwh) > 0);
// put entries on heap
- if (container != null && wordHash.length() == payloadrow.primaryKeyLength) {
+ if (container != null && wordHash.length == payloadrow.primaryKeyLength) {
//System.out.println("Dump: " + wordHash);
try {
- dump.add(wordHash.getBytes(), container.exportCollection());
+ dump.add(wordHash, container.exportCollection());
} catch (IOException e) {
e.printStackTrace();
}
@@ -170,13 +170,13 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
/**
* static iterator of BLOBHeap files: is used to import heap dumps into a write-enabled index heap
*/
- public static class blobFileEntries <RT extends Reference> implements CloneableIterator<ReferenceContainer<RT>>, Iterable<ReferenceContainer<RT>> {
+ public static class blobFileEntries <ReferenceType extends Reference> implements CloneableIterator<ReferenceContainer<ReferenceType>>, Iterable<ReferenceContainer<ReferenceType>> {
HeapReader.entries blobs;
Row payloadrow;
File blobFile;
- ReferenceFactory<RT> factory;
+ ReferenceFactory<ReferenceType> factory;
- public blobFileEntries(final File blobFile, ReferenceFactory<RT> factory, final Row payloadrow) throws IOException {
+ public blobFileEntries(final File blobFile, ReferenceFactory<ReferenceType> factory, final Row payloadrow) throws IOException {
this.blobs = new HeapReader.entries(blobFile, payloadrow.primaryKeyLength);
this.payloadrow = payloadrow;
this.blobFile = blobFile;
@@ -194,17 +194,17 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* return an index container
* because they may get very large, it is wise to deallocate some memory before calling next()
*/
- public ReferenceContainer<RT> next() {
+ public ReferenceContainer<ReferenceType> next() {
Map.Entry<String, byte[]> entry = blobs.next();
byte[] payload = entry.getValue();
- return new ReferenceContainer<RT>(factory, entry.getKey(), RowSet.importRowSet(payload, payloadrow));
+ return new ReferenceContainer<ReferenceType>(factory, entry.getKey().getBytes(), RowSet.importRowSet(payload, payloadrow));
}
public void remove() {
throw new UnsupportedOperationException("heap dumps are read-only");
}
- public Iterator<ReferenceContainer<RT>> iterator() {
+ public Iterator<ReferenceContainer<ReferenceType>> iterator() {
return this;
}
@@ -217,11 +217,11 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
this.close();
}
- public CloneableIterator<ReferenceContainer<RT>> clone(Object modifier) {
+ public CloneableIterator<ReferenceContainer<ReferenceType>> clone(Object modifier) {
if (blobs != null) this.blobs.close();
blobs = null;
try {
- return new blobFileEntries<RT>(this.blobFile, factory, this.payloadrow);
+ return new blobFileEntries<ReferenceType>(this.blobFile, factory, this.payloadrow);
} catch (IOException e) {
e.printStackTrace();
return null;
@@ -238,10 +238,10 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
return max;
}
- public synchronized String maxReferencesHash() {
+ public synchronized byte[] maxReferencesHash() {
// iterate to find the max score
int max = 0;
- String hash = null;
+ byte[] hash = null;
for (ReferenceContainer<ReferenceType> container : cache.values()) {
if (container.size() > max) {
max = container.size();
@@ -251,9 +251,9 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
return hash;
}
- public synchronized ArrayList<String> maxReferencesHash(int bound) {
+ public synchronized ArrayList<byte[]> maxReferencesHash(int bound) {
// iterate to find the max score
- ArrayList<String> hashes = new ArrayList<String>();
+ ArrayList<byte[]> hashes = new ArrayList<byte[]>();
for (ReferenceContainer<ReferenceType> container : cache.values()) {
if (container.size() >= bound) {
hashes.add(container.getTermHash());
@@ -280,8 +280,8 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
return c;
}
- public synchronized ArrayList<String> overAge(long maxage) {
- ArrayList<String> hashes = new ArrayList<String>();
+ public synchronized ArrayList<byte[]> overAge(long maxage) {
+ ArrayList<byte[]> hashes = new ArrayList<byte[]>();
long limit = System.currentTimeMillis() - maxage;
for (ReferenceContainer<ReferenceType> container : cache.values()) {
if (container.lastWrote() < limit) hashes.add(container.getTermHash());
@@ -294,7 +294,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* in the cache, so that manipulations of the iterated objects do not change
* objects in the cache.
*/
- public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final String startWordHash, final boolean rot) {
+ public synchronized CloneableIterator<ReferenceContainer<ReferenceType>> references(final byte[] startWordHash, final boolean rot) {
return new heapCacheIterator(startWordHash, rot);
}
@@ -318,14 +318,14 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
private final boolean rot;
private Iterator<ReferenceContainer<ReferenceType>> iterator;
- public heapCacheIterator(final String startWordHash, final boolean rot) {
+ public heapCacheIterator(final byte[] startWordHash, final boolean rot) {
this.rot = rot;
this.iterator = (startWordHash == null) ? cache.values().iterator() : cache.tailMap(startWordHash).values().iterator();
// The collection's iterator will return the values in the order that their corresponding keys appear in the tree.
}
public heapCacheIterator clone(final Object secondWordHash) {
- return new heapCacheIterator((String) secondWordHash, rot);
+ return new heapCacheIterator((byte[]) secondWordHash, rot);
}
public boolean hasNext() {
@@ -361,7 +361,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* @param key
* @return true, if the key is used in the heap; false othervise
*/
- public boolean has(final String key) {
+ public boolean has(final byte[] key) {
return this.cache.containsKey(key);
}
@@ -370,7 +370,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* @param key
* @return the indexContainer if one exist, null otherwise
*/
- public ReferenceContainer<ReferenceType> get(final String key, Set<String> urlselection) {
+ public ReferenceContainer<ReferenceType> get(final byte[] key, Set<String> urlselection) {
if (urlselection == null) return this.cache.get(key);
ReferenceContainer<ReferenceType> c = this.cache.get(key);
if (c == null) return null;
@@ -390,7 +390,7 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* @param key
* @return
*/
- public int count(final String key) {
+ public int count(final byte[] key) {
ReferenceContainer<ReferenceType> c = this.cache.get(key);
if (c == null) return 0;
return c.size();
@@ -401,38 +401,38 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
* @param wordHash
* @return the indexContainer if the cache contained the container, null othervise
*/
- public synchronized ReferenceContainer<ReferenceType> delete(final String wordHash) {
+ public synchronized ReferenceContainer<ReferenceType> delete(final byte[] termHash) {
// returns the index that had been deleted
assert this.cache != null;
- return cache.remove(wordHash);
+ return cache.remove(termHash);
}
- public synchronized boolean remove(final String wordHash, final String urlHash) {
+ public synchronized boolean remove(final byte[] termHash, final String urlHash) {
assert this.cache != null;
- final ReferenceContainer<ReferenceType> c = cache.get(wordHash);
+ final ReferenceContainer<ReferenceType> c = cache.get(termHash);
if ((c != null) && (c.remove(urlHash) != null)) {
// removal successful
if (c.size() == 0) {
- delete(wordHash);
+ delete(termHash);
} else {
- cache.put(wordHash, c);
+ cache.put(termHash, c);
}
return true;
}
return false;
}
- public synchronized int remove(final String wordHash, final Set<String> urlHashes) {
+ public synchronized int remove(final byte[] termHash, final Set<String> urlHashes) {
assert this.cache != null;
if (urlHashes.size() == 0) return 0;
- final ReferenceContainer<ReferenceType> c = cache.get(wordHash);
+ final ReferenceContainer<ReferenceType> c = cache.get(termHash);
int count;
if ((c != null) && ((count = c.removeEntries(urlHashes)) > 0)) {
// removal successful
if (c.size() == 0) {
- delete(wordHash);
+ delete(termHash);
} else {
- cache.put(wordHash, c);
+ cache.put(termHash, c);
}
return count;
}
@@ -444,8 +444,8 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
if (this.cache == null || container == null || container.size() == 0) return;
// put new words into cache
- final String wordHash = container.getTermHash();
- ReferenceContainer<ReferenceType> entries = cache.get(wordHash); // null pointer exception? wordhash != null! must be cache==null
+ final byte[] termHash = container.getTermHash();
+ ReferenceContainer<ReferenceType> entries = cache.get(termHash); // null pointer exception? wordhash != null! must be cache==null
int added = 0;
if (entries == null) {
entries = container.topLevelClone();
@@ -454,18 +454,18 @@ public final class ReferenceContainerCache<ReferenceType extends Reference> exte
added = entries.putAllRecent(container);
}
if (added > 0) {
- cache.put(wordHash, entries);
+ cache.put(termHash, entries);
}
entries = null;
return;
}
- public synchronized void add(final String wordHash, final ReferenceType newEntry) {
+ public synchronized void add(final byte[] termHash, final ReferenceType newEntry) {
assert this.cache != null;
- ReferenceContainer<ReferenceType> container = cache.get(wordHash);
- if (container == null) container = new ReferenceContainer<ReferenceType>(factory, wordHash, this.payloadrow, 1);
+ ReferenceContainer<ReferenceType> container = cache.get(termHash);
+ if (container == null) container = new ReferenceContainer<ReferenceType>(factory, termHash, this.payloadrow, 1);
container.put(newEntry);
- cache.put(wordHash, container);
+ cache.put(termHash, container);
}
public int minMem() {
diff --git a/source/de/anomic/kelondro/text/ReferenceContainerOrder.java b/source/de/anomic/kelondro/text/ReferenceContainerOrder.java
index 8ad49b7f6..db2031244 100644
--- a/source/de/anomic/kelondro/text/ReferenceContainerOrder.java
+++ b/source/de/anomic/kelondro/text/ReferenceContainerOrder.java
@@ -40,7 +40,7 @@ public class ReferenceContainerOrder<ReferenceType extends Reference> extends Ab
}
public boolean wellformed(final ReferenceContainer<ReferenceType> a) {
- return embeddedOrder.wellformed(a.getTermHash().getBytes());
+ return embeddedOrder.wellformed(a.getTermHash());
}
public void direction(final boolean ascending) {
@@ -52,16 +52,16 @@ public class ReferenceContainerOrder<ReferenceType extends Reference> extends Ab
}
public int compare(final ReferenceContainer<ReferenceType> a, final ReferenceContainer<ReferenceType> b) {
- return this.embeddedOrder.compare(a.getTermHash().getBytes(), b.getTermHash().getBytes());
+ return this.embeddedOrder.compare(a.getTermHash(), b.getTermHash());
}
public boolean equal(ReferenceContainer<ReferenceType> a, ReferenceContainer<ReferenceType> b) {
- return this.embeddedOrder.equal(a.getTermHash().getBytes(), b.getTermHash().getBytes());
+ return this.embeddedOrder.equal(a.getTermHash(), b.getTermHash());
}
public void rotate(final ReferenceContainer<ReferenceType> zero) {
- this.embeddedOrder.rotate(zero.getTermHash().getBytes());
- this.zero = new ReferenceContainer<ReferenceType>(this.factory, new String(this.embeddedOrder.zero()), zero);
+ this.embeddedOrder.rotate(zero.getTermHash());
+ this.zero = new ReferenceContainer<ReferenceType>(this.factory, this.embeddedOrder.zero(), zero);
}
public Order<ReferenceContainer<ReferenceType>> clone() {
@@ -82,7 +82,7 @@ public class ReferenceContainerOrder<ReferenceType extends Reference> extends Ab
}
public long cardinal(final ReferenceContainer<ReferenceType> key) {
- return this.embeddedOrder.cardinal(key.getTermHash().getBytes());
+ return this.embeddedOrder.cardinal(key.getTermHash());
}
}
diff --git a/source/de/anomic/kelondro/util/FileUtils.java b/source/de/anomic/kelondro/util/FileUtils.java
index bfdd15f2a..6ef9ada5b 100644
--- a/source/de/anomic/kelondro/util/FileUtils.java
+++ b/source/de/anomic/kelondro/util/FileUtils.java
@@ -434,7 +434,7 @@ public final class FileUtils {
return set;
}
- public static void saveSet(final File file, final String format, final Set<String> set, final String sep) throws IOException {
+ public static void saveSet(final File file, final String format, final Set<byte[]> set, final String sep) throws IOException {
final File tf = new File(file.toString() + ".tmp" + (System.currentTimeMillis() % 1000));
OutputStream os = null;
if ((format == null) || (format.equals("plain"))) {
@@ -449,8 +449,8 @@ public final class FileUtils {
os = zos;
}
if(os != null) {
- for (final Iterator<String> i = set.iterator(); i.hasNext(); ) {
- os.write((i.next()).getBytes("UTF-8"));
+ for (final Iterator<byte[]> i = set.iterator(); i.hasNext(); ) {
+ os.write(i.next());
if (sep != null) os.write(sep.getBytes("UTF-8"));
}
os.close();
diff --git a/source/de/anomic/kelondro/util/SetTools.java b/source/de/anomic/kelondro/util/SetTools.java
index 7da802810..f155dbd8e 100644
--- a/source/de/anomic/kelondro/util/SetTools.java
+++ b/source/de/anomic/kelondro/util/SetTools.java
@@ -421,6 +421,15 @@ public class SetTools {
return list;
}
+ public static String setToString(final TreeSet<byte[]> 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()));
+ while (i.hasNext()) {
+ sb.append(separator).append(i.next());
+ }
+ return new String(sb);
+ }
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/de/anomic/net/ftpc.java b/source/de/anomic/net/ftpc.java
index 9272ca715..bd14c5b33 100644
--- a/source/de/anomic/net/ftpc.java
+++ b/source/de/anomic/net/ftpc.java
@@ -2795,7 +2795,7 @@ public class ftpc {
public static Thread putAsync(final String host, final File localFile, final String remotePath,
final String remoteName, final String account, final String password) {
- final Thread t = new Thread(new pt(host, localFile, remotePath, remoteName, account, password));
+ final Thread t = new Thread(new pt(host, localFile, remotePath, remoteName, account, password), "ftp to " + host);
t.start();
return t; // return value can be used to determine status of transfer
// with isAlive() or join()
diff --git a/source/de/anomic/plasma/parser/Word.java b/source/de/anomic/plasma/parser/Word.java
index 7112f640f..08fad275b 100644
--- a/source/de/anomic/plasma/parser/Word.java
+++ b/source/de/anomic/plasma/parser/Word.java
@@ -40,7 +40,7 @@ import de.anomic.yacy.yacySeedDB;
public class Word {
- private static final ConcurrentHashMap<String, String> hashCache = new ConcurrentHashMap<String, String>(1000);
+ private static final ConcurrentHashMap<String, byte[]> hashCache = new ConcurrentHashMap<String, byte[]>(1000);
// object carries statistics for words and sentences
public int count; // number of occurrences
@@ -79,10 +79,10 @@ public class Word {
// static methods
// create a word hash
- public static final String word2hash(final String word) {
- String h = hashCache.get(word);
+ public static final byte[] word2hash(final String word) {
+ byte[] h = hashCache.get(word);
if (h != null) return h;
- h = Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(word.toLowerCase(Locale.ENGLISH))).substring(0, yacySeedDB.commonHashLength);
+ h = Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(word.toLowerCase(Locale.ENGLISH))).substring(0, yacySeedDB.commonHashLength).getBytes();
hashCache.put(word, h); // prevent expensive MD5 computation and encoding
if (hashCache.size() > 20000) {
// prevent memory leak
@@ -91,8 +91,8 @@ public class Word {
return h;
}
- public static final Set<String> words2hashSet(final String[] words) {
- final TreeSet<String> hashes = new TreeSet<String>(Base64Order.enhancedComparator);
+ 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]));
return hashes;
}
@@ -103,9 +103,9 @@ public class Word {
return new String(sb);
}
- public static final TreeSet<String> words2hashes(final Set<String> words) {
+ public static final TreeSet<byte[]> words2hashes(final Set<String> words) {
final Iterator<String> i = words.iterator();
- final TreeSet<String> hashes = new TreeSet<String>(Base64Order.enhancedComparator);
+ final TreeSet<byte[]> hashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
while (i.hasNext()) hashes.add(word2hash(i.next()));
return hashes;
}
diff --git a/source/de/anomic/plasma/plasmaDbImporter.java b/source/de/anomic/plasma/plasmaDbImporter.java
index 02f7ba1d2..b0298804d 100644
--- a/source/de/anomic/plasma/plasmaDbImporter.java
+++ b/source/de/anomic/plasma/plasmaDbImporter.java
@@ -25,10 +25,10 @@ public class plasmaDbImporter extends AbstractImporter implements Importer {
protected plasmaWordIndex homeWordIndex;
private final int importStartSize;
- private String wordHash = "------------";
+ private byte[] wordHash = "------------".getBytes();
long wordChunkStart = System.currentTimeMillis(), wordChunkEnd = this.wordChunkStart;
- String wordChunkStartHash = "------------", wordChunkEndHash;
+ byte[] wordChunkStartHash = "------------".getBytes(), wordChunkEndHash;
private long urlCounter = 0, wordCounter = 0, entryCounter = 0, notBoundEntryCounter = 0;
diff --git a/source/de/anomic/plasma/plasmaGrafics.java b/source/de/anomic/plasma/plasmaGrafics.java
index 7d2e75f31..7e8a0e383 100644
--- a/source/de/anomic/plasma/plasmaGrafics.java
+++ b/source/de/anomic/plasma/plasmaGrafics.java
@@ -129,7 +129,7 @@ public class plasmaGrafics {
// draw in the primary search peers
for (int j = 0; j < primarySearches.length; j++) {
eventPicture.setColor((primarySearches[j].isAlive()) ? ymageMatrix.RED : ymageMatrix.GREEN);
- angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(primarySearches[j].target().hash, null)) / ((double) Long.MAX_VALUE)));
+ angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(primarySearches[j].target().hash.getBytes(), null)) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 20, cr, angle);
}
@@ -137,7 +137,7 @@ public class plasmaGrafics {
if (secondarySearches != null) {
for (int j = 0; j < secondarySearches.length; j++) {
eventPicture.setColor((secondarySearches[j].isAlive()) ? ymageMatrix.RED : ymageMatrix.GREEN);
- angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(secondarySearches[j].target().hash, null)) / ((double) Long.MAX_VALUE)));
+ angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(secondarySearches[j].target().hash.getBytes(), null)) / ((double) Long.MAX_VALUE)));
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1);
eventPicture.arcLine(cx, cy, cr - 10, cr, angle + 1);
}
@@ -145,7 +145,7 @@ public class plasmaGrafics {
// draw in the search target
final plasmaSearchQuery query = event.getQuery();
- final Iterator<String> i = query.queryHashes.iterator();
+ final Iterator<byte[]> i = query.queryHashes.iterator();
eventPicture.setColor(ymageMatrix.GREY);
while (i.hasNext()) {
long[] positions = seedDB.scheme.dhtPositions(i.next());
@@ -249,7 +249,7 @@ public class plasmaGrafics {
final String name = seed.getName().toUpperCase() /*+ ":" + seed.hash + ":" + (((double) ((int) (100 * (((double) yacySeed.dhtPosition(seed.hash)) / ((double) yacySeed.maxDHTDistance))))) / 100.0)*/;
if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length();
- final int angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(seed.hash, null)) / ((double) Long.MAX_VALUE)));
+ final int angle = (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(seed.hash.getBytes(), null)) / ((double) Long.MAX_VALUE)));
//System.out.println("Seed " + seed.hash + " has distance " + seed.dhtDistance() + ", angle = " + angle);
int linelength = 20 + outerradius * (20 * (name.length() - shortestName) / (longestName - shortestName) + Math.abs(seed.hash.hashCode() % 20)) / 60;
if (linelength > outerradius) linelength = outerradius;
diff --git a/source/de/anomic/plasma/plasmaRankingCRProcess.java b/source/de/anomic/plasma/plasmaRankingCRProcess.java
index e92f390c0..68989de0a 100644
--- a/source/de/anomic/plasma/plasmaRankingCRProcess.java
+++ b/source/de/anomic/plasma/plasmaRankingCRProcess.java
@@ -389,7 +389,7 @@ public class plasmaRankingCRProcess {
CloneableIterator<Row.Entry> cr_entry;
while (i.hasNext()) {
keycollection = i.next();
- referee = keycollection.getTermHash();
+ referee = new String(keycollection.getTermHash());
if (referee.length() == 6) refereeDom = referee; else refereeDom = referee.substring(6);
cr_entry = keycollection.rows();
@@ -401,7 +401,7 @@ public class plasmaRankingCRProcess {
if (anchor.length() == 6) anchorDom = anchor; else anchorDom = anchor.substring(6);
// update domain-specific entry
- rci_entry = rci.get(anchorDom, null);
+ rci_entry = rci.get(anchorDom.getBytes(), null);
if (rci_entry == null) rci_entry = new RowSet(RCI_coli, 0);
rci_entry.add(refereeDom.getBytes());
diff --git a/source/de/anomic/plasma/plasmaRankingRCIEvaluation.java b/source/de/anomic/plasma/plasmaRankingRCIEvaluation.java
index 78391e27c..4fac48e89 100644
--- a/source/de/anomic/plasma/plasmaRankingRCIEvaluation.java
+++ b/source/de/anomic/plasma/plasmaRankingRCIEvaluation.java
@@ -135,16 +135,16 @@ public class plasmaRankingRCIEvaluation {
}
@SuppressWarnings("unchecked")
- public static TreeSet<String>[] genRankingTable(final AttrSeq rci, final int[] partition) {
- final TreeSet<String>[] ranked = new TreeSet[partition.length];
- for (int i = 0; i < partition.length; i++) ranked[i] = new TreeSet<String>(Base64Order.enhancedComparator);
+ public static TreeSet<byte[]>[] genRankingTable(final AttrSeq rci, final int[] partition) {
+ final TreeSet<byte[]>[] ranked = new TreeSet[partition.length];
+ for (int i = 0; i < partition.length; i++) ranked[i] = new TreeSet<byte[]>(Base64Order.enhancedCoder);
final Iterator<String> i = rci.keys();
String key;
AttrSeq.Entry entry;
while (i.hasNext()) {
key = i.next();
entry = rci.getEntry(key);
- ranked[orderIntoYBI(partition, entry.getSeqSet().size())].add(key);
+ ranked[orderIntoYBI(partition, entry.getSeqSet().size())].add(key.getBytes());
}
return ranked;
}
@@ -165,7 +165,7 @@ public class plasmaRankingRCIEvaluation {
return dommap;
}
- public static void storeRankingTable(final TreeSet<String>[] ranking, final File tablePath) throws IOException {
+ public static void storeRankingTable(final TreeSet<byte[]>[] ranking, final File tablePath) throws IOException {
String filename;
if (!(tablePath.exists())) tablePath.mkdirs();
for (int i = 0; i < ranking.length - 1; i++) {
@@ -200,7 +200,7 @@ public class plasmaRankingRCIEvaluation {
System.out.println("sum of all references: " + sum);
// create ranking
- final TreeSet<String>[] ranked = genRankingTable(rci, partition);
+ final TreeSet<byte[]>[] ranked = genRankingTable(rci, partition);
storeRankingTable(ranked, new File(root_path, "ranking/YBR"));
final long seconds = java.lang.Math.max(1, (System.currentTimeMillis() - start) / 1000);
System.out.println("Finished YBR generation in " + seconds + " seconds.");
diff --git a/source/de/anomic/plasma/plasmaSearchAPI.java b/source/de/anomic/plasma/plasmaSearchAPI.java
index 42b71ff0f..c03415acb 100644
--- a/source/de/anomic/plasma/plasmaSearchAPI.java
+++ b/source/de/anomic/plasma/plasmaSearchAPI.java
@@ -69,7 +69,7 @@ public class plasmaSearchAPI {
return b;
}
- public static void listHosts(final serverObjects prop, final String startHash, final plasmaSwitchboard sb) {
+ public static void listHosts(final serverObjects prop, final byte[] startHash, final plasmaSwitchboard sb) {
// list known hosts
yacySeed seed;
int hc = 0;
@@ -86,8 +86,8 @@ public class plasmaSearchAPI {
prop.put("searchresult_hosts", hc);
}
- public static plasmaSearchRankingProcess genSearchresult(final serverObjects prop, final plasmaSwitchboard sb, final String keyhash, final Bitfield filter) {
- final plasmaSearchQuery query = new plasmaSearchQuery(keyhash, -1, sb.getRanking(), filter);
+ public static plasmaSearchRankingProcess genSearchresult(final serverObjects prop, final plasmaSwitchboard sb, final byte[] keyhash, final Bitfield filter) {
+ final plasmaSearchQuery query = new plasmaSearchQuery(new String(keyhash), -1, sb.getRanking(), filter);
final plasmaSearchRankingProcess ranked = new plasmaSearchRankingProcess(sb.webIndex, query, Integer.MAX_VALUE, 1);
ranked.execQuery();
@@ -112,9 +112,9 @@ public class plasmaSearchAPI {
return ranked;
}
- public static void genURLList(final serverObjects prop, final String keyhash, final String keystring, final plasmaSearchRankingProcess ranked, final Bitfield flags, final int maxlines) {
+ public static void genURLList(final serverObjects prop, final byte[] keyhash, final String keystring, final plasmaSearchRankingProcess ranked, final Bitfield flags, final int maxlines) {
// search for a word hash and generate a list of url links
- prop.put("genUrlList_keyHash", keyhash);
+ prop.put("genUrlList_keyHash", new String(keyhash));
if (ranked.filteredCount() == 0) {
prop.put("genUrlList", 1);
@@ -140,7 +140,7 @@ public class plasmaSearchAPI {
prop.put("genUrlList_urlList_"+i+"_urlExists_urlhxCount", i);
prop.putHTML("genUrlList_urlList_"+i+"_urlExists_urlhxValue", entry.word().metadataHash());
prop.putHTML("genUrlList_urlList_"+i+"_urlExists_keyString", keystring);
- prop.put("genUrlList_urlList_"+i+"_urlExists_keyHash", keyhash);
+ prop.put("genUrlList_urlList_"+i+"_urlExists_keyHash", new String(keyhash));
prop.putHTML("genUrlList_urlList_"+i+"_urlExists_urlString", us);
prop.put("genUrlList_urlList_"+i+"_urlExists_urlStringShort", (us.length() > 40) ? (us.substring(0, 20) + "<br>" + us.substring(20, 40) + "...") : ((us.length() > 30) ? (us.substring(0, 20) + "<br>" + us.substring(20)) : us));
prop.putNum("genUrlList_urlList_"+i+"_urlExists_ranking", (entry.ranking() - rn));
diff --git a/source/de/anomic/plasma/plasmaSearchEvent.java b/source/de/anomic/plasma/plasmaSearchEvent.java
index adadd745f..e2c6c49ef 100644
--- a/source/de/anomic/plasma/plasmaSearchEvent.java
+++ b/source/de/anomic/plasma/plasmaSearchEvent.java
@@ -38,6 +38,7 @@ import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import de.anomic.crawler.ResultURLs;
+import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.order.Bitfield;
import de.anomic.kelondro.text.Reference;
import de.anomic.kelondro.text.ReferenceContainer;
@@ -81,16 +82,16 @@ public final class plasmaSearchEvent {
private final Map<String, TreeMap<String, String>> rcAbstracts; // cache for index abstracts; word:TreeMap mapping where the embedded TreeMap is a urlhash:peerlist relation
private yacySearch[] primarySearchThreads, secondarySearchThreads;
private Thread localSearchThread;
- private final TreeMap<String, String> preselectedPeerHashes;
+ private final TreeMap<byte[], String> preselectedPeerHashes;
//private Object[] references;
- public TreeMap<String, String> IAResults;
- public TreeMap<String, Integer> IACount;
- public String IAmaxcounthash, IAneardhthash;
+ public TreeMap<byte[], String> IAResults;
+ public TreeMap<byte[], Integer> IACount;
+ public byte[] IAmaxcounthash, IAneardhthash;
private resultWorker[] workerThreads;
SortStore<ResultEntry> result;
SortStore<plasmaSnippetCache.MediaSnippet> images; // container to sort images by size
HashMap<String, String> failedURLs; // a mapping from a urlhash to a fail reason string
- TreeSet<String> snippetFetchWordHashes; // a set of word hashes that are used to match with the snippets
+ TreeSet<byte[]> snippetFetchWordHashes; // a set of word hashes that are used to match with the snippets
long urlRetrievalAllTime;
long snippetComputationAllTime;
ResultURLs crawlResults;
@@ -99,7 +100,7 @@ public final class plasmaSearchEvent {
private plasmaSearchEvent(final plasmaSearchQuery query,
final plasmaWordIndex wordIndex,
final ResultURLs crawlResults,
- final TreeMap<String, String> preselectedPeerHashes,
+ final TreeMap<byte[], String> preselectedPeerHashes,
final boolean generateAbstracts) {
this.eventTime = System.currentTimeMillis(); // for lifetime check
this.wordIndex = wordIndex;
@@ -109,8 +110,8 @@ public final class plasmaSearchEvent {
this.primarySearchThreads = null;
this.secondarySearchThreads = null;
this.preselectedPeerHashes = preselectedPeerHashes;
- this.IAResults = new TreeMap<String, String>();
- this.IACount = new TreeMap<String, Integer>();
+ this.IAResults = new TreeMap<byte[], String>(Base64Order.enhancedCoder);
+ this.IACount = new TreeMap<byte[], Integer>(Base64Order.enhancedCoder);
this.IAmaxcounthash = null;
this.IAneardhthash = null;
this.urlRetrievalAllTime = 0;
@@ -123,10 +124,10 @@ public final class plasmaSearchEvent {
// 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<String> filtered = SetTools.joinConstructive(query.queryHashes, plasmaSwitchboard.stopwords);
- this.snippetFetchWordHashes = (TreeSet<String>) query.queryHashes.clone();
+ final TreeSet<byte[]> filtered = SetTools.joinConstructive(query.queryHashes, plasmaSwitchboard.stopwordHashes);
+ this.snippetFetchWordHashes = (TreeSet<byte[]>) query.queryHashes.clone();
if ((filtered != null) && (filtered.size() > 0)) {
- SetTools.excludeDestructive(this.snippetFetchWordHashes, plasmaSwitchboard.stopwords);
+ SetTools.excludeDestructive(this.snippetFetchWordHashes, plasmaSwitchboard.stopwordHashes);
}
final long start = System.currentTimeMillis();
@@ -177,8 +178,8 @@ public final class plasmaSearchEvent {
final long timer = System.currentTimeMillis();
int maxcount = -1;
long mindhtdistance = Long.MAX_VALUE, l;
- String wordhash;
- for (Map.Entry<String, ReferenceContainer<WordReference>> entry : this.rankedCache.searchContainerMaps()[0].entrySet()) {
+ byte[] wordhash;
+ for (Map.Entry<byte[], ReferenceContainer<WordReference>> entry : this.rankedCache.searchContainerMaps()[0].entrySet()) {
wordhash = entry.getKey();
final ReferenceContainer container = entry.getValue();
assert (container.getTermHash().equals(wordhash));
@@ -249,7 +250,7 @@ public final class plasmaSearchEvent {
// execute deletion of failed words
int rw = cleanEvent.failedURLs.size();
if (rw > 0) {
- final Set<String> removeWords = cleanEvent.query.queryHashes;
+ final TreeSet<byte[]> removeWords = cleanEvent.query.queryHashes;
removeWords.addAll(cleanEvent.query.excludeHashes);
try {
cleanEvent.wordIndex.index().remove(removeWords, cleanEvent.failedURLs.keySet());
@@ -307,7 +308,7 @@ public final class plasmaSearchEvent {
if ((query.constraint != null) &&
(query.constraint.get(Condenser.flag_cat_indexof)) &&
(!(metadata.dc_title().startsWith("Index of")))) {
- final Iterator<String> wi = query.queryHashes.iterator();
+ final Iterator<byte[]> wi = query.queryHashes.iterator();
while (wi.hasNext()) try { wordIndex.index().remove(wi.next(), page.hash()); } catch (IOException e) {}
registerFailure(page.hash(), "index-of constraint not fullfilled");
return null;
@@ -451,7 +452,7 @@ public final class plasmaSearchEvent {
final plasmaSearchRankingProfile ranking,
final plasmaWordIndex wordIndex,
final ResultURLs crawlResults,
- final TreeMap<String, String> preselectedPeerHashes,
+ final TreeMap<byte[], String> preselectedPeerHashes,
final boolean generateAbstracts) {
String id = query.id(false);
diff --git a/source/de/anomic/plasma/plasmaSearchQuery.java b/source/de/anomic/plasma/plasmaSearchQuery.java
index eee2fe2b6..73e600a58 100644
--- a/source/de/anomic/plasma/plasmaSearchQuery.java
+++ b/source/de/anomic/plasma/plasmaSearchQuery.java
@@ -22,8 +22,8 @@
package de.anomic.plasma;
+import java.util.HashSet;
import java.util.Iterator;
-import java.util.Set;
import java.util.TreeSet;
import de.anomic.htmlFilter.htmlFilterAbstractScraper;
@@ -57,7 +57,7 @@ public final class plasmaSearchQuery {
public static final Bitfield catchall_constraint = new Bitfield(4, "______");
public String queryString;
- public TreeSet<String> fullqueryHashes, queryHashes, excludeHashes;
+ public TreeSet<byte[]> fullqueryHashes, queryHashes, excludeHashes;
public int linesPerPage, offset;
public String prefer;
public int contentdom;
@@ -86,9 +86,9 @@ public final class plasmaSearchQuery {
final Bitfield constraint) {
if ((queryString.length() == 12) && (Base64Order.enhancedCoder.wellformed(queryString.getBytes()))) {
this.queryString = null;
- this.queryHashes = new TreeSet<String>();
- this.excludeHashes = new TreeSet<String>();
- this.queryHashes.add(queryString);
+ this.queryHashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
+ this.excludeHashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
+ this.queryHashes.add(queryString.getBytes());
} else {
this.queryString = queryString;
final TreeSet<String>[] cq = cleanQuery(queryString);
@@ -118,9 +118,9 @@ public final class plasmaSearchQuery {
}
public plasmaSearchQuery(
- final String queryString, final TreeSet<String> queryHashes,
- final TreeSet<String> excludeHashes,
- final TreeSet<String> fullqueryHashes,
+ final String queryString, final TreeSet<byte[]> queryHashes,
+ final TreeSet<byte[]> excludeHashes,
+ final TreeSet<byte[]> fullqueryHashes,
final plasmaSearchRankingProfile ranking,
final int maxDistance, final String prefer, final int contentdom,
final String language,
@@ -198,44 +198,53 @@ public final class plasmaSearchQuery {
return this.domType == SEARCHDOM_LOCAL;
}
- public static TreeSet<String> hashes2Set(final String query) {
- if (query == null) return new TreeSet<String>(Base64Order.enhancedComparator);
- final TreeSet<String> keyhashes = new TreeSet<String>(Base64Order.enhancedComparator);
+ 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() / yacySeedDB.commonHashLength); i++) {
+ keyhashes.add(query.substring(i * yacySeedDB.commonHashLength, (i + 1) * yacySeedDB.commonHashLength).getBytes());
+ }
+ return keyhashes;
+ }
+
+ public static HashSet<String> hashes2StringSet(final String query) {
+ if (query == null) return new HashSet<String>();
+ final HashSet<String> keyhashes = new HashSet<String>();
for (int i = 0; i < (query.length() / yacySeedDB.commonHashLength); i++) {
keyhashes.add(query.substring(i * yacySeedDB.commonHashLength, (i + 1) * yacySeedDB.commonHashLength));
}
return keyhashes;
}
- public static String hashSet2hashString(final Set<String> hashes) {
- final Iterator<String> i = hashes.iterator();
+ public static String hashSet2hashString(final TreeSet<byte[]> hashes) {
+ final Iterator<byte[]> i = hashes.iterator();
final StringBuilder sb = new StringBuilder(hashes.size() * yacySeedDB.commonHashLength);
- while (i.hasNext()) sb.append(i.next());
+ while (i.hasNext()) sb.append(new String(i.next()));
return new String(sb);
}
- public static String anonymizedQueryHashes(final Set<String> hashes) {
+ public static String anonymizedQueryHashes(final TreeSet<byte[]> hashes) {
// create a more anonymized representation of a query hashes for logging
- final Iterator<String> i = hashes.iterator();
+ final Iterator<byte[]> i = hashes.iterator();
final StringBuilder sb = new StringBuilder(hashes.size() * (yacySeedDB.commonHashLength + 2) + 2);
sb.append("[");
- String hash;
+ byte[] hash;
if (i.hasNext()) {
hash = i.next();
- sb.append(hash.substring(0, 3)).append(".........");
+ sb.append(new String(hash).substring(0, 3)).append(".........");
}
while (i.hasNext()) {
hash = i.next();
- sb.append(", ").append(hash.substring(0, 3)).append(".........");
+ sb.append(", ").append(new String(hash).substring(0, 3)).append(".........");
}
sb.append("]");
return new String(sb);
}
- public static final boolean matches(final String text, final TreeSet<String> keyhashes) {
+ public static final boolean matches(final String text, final TreeSet<byte[]> 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<String> wordhashes = Word.words2hashes(Condenser.getWords(text).keySet());
+ final TreeSet<byte[]> wordhashes = Word.words2hashes(Condenser.getWords(text).keySet());
return SetTools.anymatch(wordhashes, keyhashes);
}
@@ -291,10 +300,10 @@ public final class plasmaSearchQuery {
return cleanQuery(this.queryString);
}
- public void filterOut(final Set<String> blueList) {
+ public void filterOut(final TreeSet<String> blueList) {
// filter out words that appear in this set
// this is applied to the queryHashes
- final TreeSet<String> blues = Word.words2hashes(blueList);
+ final TreeSet<byte[]> blues = Word.words2hashes(blueList);
SetTools.excludeDestructive(queryHashes, blues);
}
diff --git a/source/de/anomic/plasma/plasmaSearchRankingProcess.java b/source/de/anomic/plasma/plasmaSearchRankingProcess.java
index baf5d87ba..3a389239b 100644
--- a/source/de/anomic/plasma/plasmaSearchRankingProcess.java
+++ b/source/de/anomic/plasma/plasmaSearchRankingProcess.java
@@ -72,7 +72,7 @@ public final class plasmaSearchRankingProcess {
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 plasmaWordIndex wordIndex;
- private HashMap<String, ReferenceContainer<WordReference>>[] localSearchContainerMaps;
+ private HashMap<byte[], ReferenceContainer<WordReference>>[] localSearchContainerMaps;
private final int[] domZones;
public plasmaSearchRankingProcess(
@@ -242,7 +242,7 @@ public final class plasmaSearchRankingProcess {
return false;
}
- public Map<String, ReferenceContainer<WordReference>>[] searchContainerMaps() {
+ public Map<byte[], ReferenceContainer<WordReference>>[] searchContainerMaps() {
// direct access to the result maps is needed for abstract generation
// this is only available if execQuery() was called before
return localSearchContainerMaps;
@@ -485,10 +485,10 @@ public final class plasmaSearchRankingProcess {
}
// apply query-in-result matching
- final Set<String> urlcomph = Word.words2hashSet(urlcomps);
- final Set<String> descrcomph = Word.words2hashSet(descrcomps);
- final Iterator<String> shi = query.queryHashes.iterator();
- String queryhash;
+ final Set<byte[]> urlcomph = Word.words2hashSet(urlcomps);
+ final Set<byte[]> descrcomph = Word.words2hashSet(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;
diff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.java
index 28784c629..814697bb6 100644
--- a/source/de/anomic/plasma/plasmaSnippetCache.java
+++ b/source/de/anomic/plasma/plasmaSnippetCache.java
@@ -30,7 +30,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -43,6 +42,7 @@ import de.anomic.htmlFilter.htmlFilterCharacterCoding;
import de.anomic.htmlFilter.htmlFilterImageEntry;
import de.anomic.http.httpClient;
import de.anomic.http.httpResponseHeader;
+import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.text.metadataPrototype.URLMetadataRow;
import de.anomic.kelondro.util.ScoreCluster;
import de.anomic.kelondro.util.SetTools;
@@ -104,7 +104,7 @@ public class plasmaSnippetCache {
private String line;
private final String error;
private final int errorCode;
- Set<String> remaingHashes;
+ TreeSet<byte[]> remaingHashes;
private final yacyURL favicon;
/**
@@ -128,11 +128,11 @@ public class plasmaSnippetCache {
*/
private final static Pattern p01 = Pattern.compile("(.*?)(\\<b\\>.+?\\</b\\>)(.*)"); // marked words are in <b>-tags
- public TextSnippet(final yacyURL url, final String line, final int errorCode, final Set<String> remaingHashes, final String errortext) {
+ public TextSnippet(final yacyURL url, final String line, final int errorCode, final TreeSet<byte[]> remaingHashes, final String errortext) {
this(url,line,errorCode,remaingHashes,errortext,null);
}
- public TextSnippet(final yacyURL url, final String line, final int errorCode, final Set<String> remaingHashes, final String errortext, final yacyURL favicon) {
+ public TextSnippet(final yacyURL url, final String line, final int errorCode, final TreeSet<byte[]> remaingHashes, final String errortext, final yacyURL favicon) {
this.url = url;
this.line = line;
this.errorCode = errorCode;
@@ -161,15 +161,15 @@ public class plasmaSnippetCache {
public int getErrorCode() {
return errorCode;
}
- public Set<String> getRemainingHashes() {
+ public TreeSet<byte[]> getRemainingHashes() {
return this.remaingHashes;
}
- public String getLineMarked(final Set<String> queryHashes) {
+ public String getLineMarked(final TreeSet<byte[]> queryHashes) {
if (line == null) return "";
if ((queryHashes == null) || (queryHashes.size() == 0)) return line.trim();
if (line.endsWith(".")) line = line.substring(0, line.length() - 1);
- final Iterator<String> i = queryHashes.iterator();
- String h;
+ final Iterator<byte[]> i = queryHashes.iterator();
+ byte[] h;
final String[] w = line.split(" ");
while (i.hasNext()) {
h = i.next();
@@ -200,7 +200,7 @@ public class plasmaSnippetCache {
* @return the marked word if hash matches, else the unmarked word
* @see #getLineMarked(Set)
*/
- private static String getWordMarked(String word, String h){
+ private static String getWordMarked(String word, byte[] h){
//ignore punctuation marks (contrib [MN])
//note to myself:
//For details on regex see "Mastering regular expressions" by J.E.F. Friedl
@@ -297,13 +297,13 @@ public class plasmaSnippetCache {
}
}
- public static boolean existsInCache(final yacyURL url, final Set<String> queryhashes) {
+ public static boolean existsInCache(final yacyURL url, final TreeSet<byte[]> queryhashes) {
final String hashes = yacySearch.set2string(queryhashes);
return retrieveFromCache(hashes, url.hash()) != null;
}
@SuppressWarnings("unchecked")
- public static TextSnippet retrieveTextSnippet(final URLMetadataRow.Components comp, final Set<String> queryhashes, final boolean fetchOnline, final boolean pre, final int snippetMaxLength, final int timeout, final int maxDocLen, final boolean reindexing) {
+ public static TextSnippet retrieveTextSnippet(final URLMetadataRow.Components comp, final TreeSet<byte[]> queryhashes, final boolean fetchOnline, final boolean pre, final int snippetMaxLength, final int timeout, final int maxDocLen, final boolean reindexing) {
// heise = "0OQUNU3JSs05"
final yacyURL url = comp.url();
if (queryhashes.size() == 0) {
@@ -406,7 +406,7 @@ public class plasmaSnippetCache {
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 Set<String> remainingHashes = (tsr == null) ? queryhashes : (Set<String>) tsr[1];
+ final TreeSet<byte[]> remainingHashes = (tsr == null) ? queryhashes : (TreeSet<byte[]>) tsr[1];
// compute snippet from media
//String audioline = computeMediaSnippet(document.getAudiolinks(), queryhashes);
@@ -567,12 +567,12 @@ public class plasmaSnippetCache {
@SuppressWarnings("unchecked")
private static Object[] /*{String - the snippet, Set - remaining hashes}*/
- computeTextSnippet(final Iterator<StringBuilder> sentences, final Set<String> queryhashes, int maxLength) {
+ computeTextSnippet(final Iterator<StringBuilder> sentences, final TreeSet<byte[]> queryhashes, int maxLength) {
try {
if (sentences == null) return null;
if ((queryhashes == null) || (queryhashes.size() == 0)) return null;
- Iterator<String> j;
- HashMap<String, Integer> hs;
+ Iterator<byte[]> j;
+ TreeMap<byte[], Integer> hs;
StringBuilder sentence;
final TreeMap<Integer, StringBuilder> os = new TreeMap<Integer, StringBuilder>();
int uniqCounter = 9999;
@@ -589,14 +589,14 @@ public class plasmaSnippetCache {
}
String result;
- Set<String> remaininghashes;
+ TreeSet<byte[]> remaininghashes;
while (os.size() > 0) {
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 = (Set<String>) tsr[1];
+ remaininghashes = (TreeSet<byte[]>) tsr[1];
if (remaininghashes.size() == 0) {
// we have found the snippet
return new Object[]{result, remaininghashes};
@@ -626,18 +626,18 @@ public class plasmaSnippetCache {
}
private static Object[] /*{String - the snippet, Set - remaining hashes}*/
- computeTextSnippet(String sentence, final Set<String> queryhashes, final int maxLength) {
+ computeTextSnippet(String sentence, final TreeSet<byte[]> queryhashes, final int maxLength) {
try {
if (sentence == null) return null;
if ((queryhashes == null) || (queryhashes.size() == 0)) return null;
- String hash;
+ byte[] hash;
// find all hashes that appear in the sentence
- final HashMap<String, Integer> hs = hashSentence(sentence);
- final Iterator<String> j = queryhashes.iterator();
+ final TreeMap<byte[], Integer> hs = hashSentence(sentence);
+ final Iterator<byte[]> j = queryhashes.iterator();
Integer pos;
int p, minpos = sentence.length(), maxpos = -1;
- final HashSet<String> remainingHashes = new HashSet<String>();
+ final TreeSet<byte[]> remainingHashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
while (j.hasNext()) {
hash = j.next();
pos = hs.get(hash);
@@ -694,7 +694,7 @@ public class plasmaSnippetCache {
}
}
- public static ArrayList<MediaSnippet> retrieveMediaSnippets(final yacyURL url, final Set<String> queryhashes, final int mediatype, final boolean fetchOnline, final int timeout, final boolean reindexing) {
+ public static ArrayList<MediaSnippet> retrieveMediaSnippets(final yacyURL url, final TreeSet<byte[]> queryhashes, final int mediatype, final boolean fetchOnline, final int timeout, final boolean reindexing) {
if (queryhashes.size() == 0) {
Log.logFine("snippet fetch", "no query hashes given for url " + url);
return new ArrayList<MediaSnippet>();
@@ -711,7 +711,7 @@ public class plasmaSnippetCache {
return a;
}
- public static ArrayList<MediaSnippet> computeMediaSnippets(final plasmaParserDocument document, final Set<String> queryhashes, final int mediatype) {
+ public static ArrayList<MediaSnippet> computeMediaSnippets(final plasmaParserDocument document, final TreeSet<byte[]> queryhashes, final int mediatype) {
if (document == null) return new ArrayList<MediaSnippet>();
Map<yacyURL, String> media = null;
@@ -724,7 +724,7 @@ public class plasmaSnippetCache {
Map.Entry<yacyURL, String> entry;
yacyURL url;
String desc;
- Set<String> s;
+ TreeSet<byte[]> s;
final ArrayList<MediaSnippet> result = new ArrayList<MediaSnippet>();
while (i.hasNext()) {
entry = i.next();
@@ -744,7 +744,7 @@ public class plasmaSnippetCache {
return result;
}
- public static ArrayList<MediaSnippet> computeImageSnippets(final plasmaParserDocument document, final Set<String> queryhashes) {
+ public static ArrayList<MediaSnippet> computeImageSnippets(final plasmaParserDocument document, final TreeSet<byte[]> queryhashes) {
final TreeSet<htmlFilterImageEntry> images = new TreeSet<htmlFilterImageEntry>();
images.addAll(document.getImages().values()); // iterates images in descending size order!
@@ -754,7 +754,7 @@ public class plasmaSnippetCache {
htmlFilterImageEntry ientry;
yacyURL url;
String desc;
- Set<String> s;
+ TreeSet<byte[]> s;
final ArrayList<MediaSnippet> result = new ArrayList<MediaSnippet>();
while (i.hasNext()) {
ientry = i.next();
@@ -776,14 +776,14 @@ public class plasmaSnippetCache {
return result;
}
- private static Set<String> removeAppearanceHashes(final String sentence, final Set<String> queryhashes) {
+ private static TreeSet<byte[]> removeAppearanceHashes(final String sentence, final TreeSet<byte[]> queryhashes) {
// remove all hashes that appear in the sentence
if (sentence == null) return queryhashes;
- final HashMap<String, Integer> hs = hashSentence(sentence);
- final Iterator<String> j = queryhashes.iterator();
- String hash;
+ final TreeMap<byte[], Integer> hs = hashSentence(sentence);
+ final Iterator<byte[]> j = queryhashes.iterator();
+ byte[] hash;
Integer pos;
- final Set<String> remaininghashes = new HashSet<String>();
+ final TreeSet<byte[]> remaininghashes = new TreeSet<byte[]>(Base64Order.enhancedCoder);
while (j.hasNext()) {
hash = j.next();
pos = hs.get(hash);
@@ -794,25 +794,25 @@ public class plasmaSnippetCache {
return remaininghashes;
}
- private static HashMap<String, Integer> hashSentence(final String sentence) {
+ private static TreeMap<byte[], Integer> hashSentence(final String sentence) {
// generates a word-wordPos mapping
- final HashMap<String, Integer> map = new HashMap<String, Integer>();
+ final TreeMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Base64Order.enhancedCoder);
final Enumeration<StringBuilder> words = Condenser.wordTokenizer(sentence, "UTF-8");
int pos = 0;
StringBuilder word;
- String hash;
+ byte[] hash;
while (words.hasMoreElements()) {
word = words.nextElement();
hash = Word.word2hash(new String(word));
- if (!map.containsKey(hash)) map.put(hash, Integer.valueOf(pos)); // dont overwrite old values, that leads to too far word distances
+ 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;
}
return map;
}
- private static boolean containsAllHashes(final String sentence, final Set<String> queryhashes) {
- final HashMap<String, Integer> m = hashSentence(sentence);
- final Iterator<String> i = queryhashes.iterator();
+ private static boolean containsAllHashes(final String sentence, final Set<byte[]> queryhashes) {
+ final TreeMap<byte[], Integer> m = hashSentence(sentence);
+ final Iterator<byte[]> i = queryhashes.iterator();
while (i.hasNext()) {
if (!(m.containsKey(i.next()))) return false;
}
diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java
index 1ff7e501b..126e0b9fe 100644
--- a/source/de/anomic/plasma/plasmaSwitchboard.java
+++ b/source/de/anomic/plasma/plasmaSwitchboard.java
@@ -189,9 +189,12 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
public static long lastPPMUpdate = System.currentTimeMillis()- 30000;
// colored list management
- public static TreeSet<String> badwords = null;
- public static TreeSet<String> blueList = null;
- public static TreeSet<String> stopwords = null;
+ public static TreeSet<String> badwords = null;
+ public static TreeSet<String> blueList = null;
+ public static TreeSet<String> stopwords = null;
+ public static TreeSet<byte[]> badwordHashes = null;
+ public static TreeSet<byte[]> blueListHashes = null;
+ public static TreeSet<byte[]> stopwordHashes = null;
public static Blacklist urlBlacklist = null;
public static wikiParser wikiParser = null;
@@ -234,7 +237,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
public long indexedPages = 0;
public double requestedQueries = 0d;
public double totalQPM = 0d;
- public TreeMap<String, String> clusterhashes; // map of peerhash(String)/alternative-local-address as ip:port or only ip (String) or null if address in seed should be used
+ public TreeMap<byte[], String> clusterhashes; // map of peerhash(String)/alternative-local-address as ip:port or only ip (String) or null if address in seed should be used
public URLLicense licensedURLs;
public List<Pattern> networkWhitelist, networkBlacklist;
public Dispatcher dhtDispatcher;
@@ -362,6 +365,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
final String f = getConfig(plasmaSwitchboardConstants.LIST_BLUE, plasmaSwitchboardConstants.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);
this.log.logConfig("loaded blue-list from file " + plasmaBlueListFile.getName() + ", " +
blueList.size() + " entries, " +
ppRamString(plasmaBlueListFile.length()/1024));
@@ -404,6 +408,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
if (badwords == null) {
final File badwordsFile = new File(rootPath, plasmaSwitchboardConstants.LIST_BADWORDS_DEFAULT);
badwords = SetTools.loadList(badwordsFile, NaturalOrder.naturalComparator);
+ badwordHashes = Word.words2hashes(badwords);
this.log.logConfig("loaded badwords from file " + badwordsFile.getName() +
", " + badwords.size() + " entries, " +
ppRamString(badwordsFile.length()/1024));
@@ -413,6 +418,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
if (stopwords == null) {
final File stopwordsFile = new File(rootPath, plasmaSwitchboardConstants.LIST_STOPWORDS_DEFAULT);
stopwords = SetTools.loadList(stopwordsFile, NaturalOrder.naturalComparator);
+ stopwordHashes = Word.words2hashes(stopwords);
this.log.logConfig("loaded stopwords from file " + stopwordsFile.getName() + ", " +
stopwords.size() + " entries, " +
ppRamString(stopwordsFile.length()/1024));
@@ -1180,12 +1186,15 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
}
}
- public void processSurrogate(String s) {
+ public boolean processSurrogate(String s) {
File surrogateFile = new File(this.surrogatesInPath, s);
File outfile = new File(this.surrogatesOutPath, s);
+ if (!surrogateFile.exists() || !surrogateFile.canWrite() || !surrogateFile.canRead()) return false;
+ if (outfile.exists()) return false;
+ boolean moved = false;
try {
SurrogateReader reader = new SurrogateReader(new BufferedInputStream(new FileInputStream(surrogateFile)));
- Thread readerThread = new Thread(reader);
+ Thread readerThread = new Thread(reader, "Surrogate-Reader " + surrogateFile.getAbsolutePath());
readerThread.start();
Surrogate surrogate;
QueueEntry queueentry;
@@ -1208,8 +1217,9 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
} catch (IOException e) {
e.printStackTrace();
} finally {
- surrogateFile.renameTo(outfile);
+ moved = surrogateFile.renameTo(outfile);
}
+ return moved;
}
public boolean deQueueProcess() {
@@ -1732,7 +1742,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
log.logInfo("Sending crawl receipt for '" + queueEntry.url().toNormalform(false, true) + "' to " + initiatorPeer.getName());
if (clusterhashes != null) initiatorPeer.setAlternativeAddress(clusterhashes.get(initiatorPeer.hash));
// start a thread for receipt sending to avoid a blocking here
- new Thread(new receiptSending(initiatorPeer, newEntry)).start();
+ new Thread(new receiptSending(initiatorPeer, newEntry), "sending receipt to " + initiatorPeer.hash).start();
}
}
@@ -1964,9 +1974,9 @@ public final class plasmaSwitchboard extends serverAbstractSwitch<IndexingStack.
} else if (MemoryControl.available() < 1024*1024*25) {
log.logInfo("dhtTransferJob: no selection, too less memory available : " + (MemoryControl.available() / 1024 / 1024) + " MB");
} else {
- String startHash = PeerSelection.selectTransferStart();
- log.logInfo("dhtTransferJob: selected " + startHash + " as start hash");
- String limitHash = PeerSelection.limitOver(this.webIndex.peers(), startHash);
+ byte[] startHash = PeerSelection.selectTransferStart();
+ log.logInfo("dhtTransferJob: selected " + new String(startHash) + " as start hash");
+ byte[] limitHash = PeerSelection.limitOver(this.webIndex.peers(), startHash);
log.logInfo("dhtTransferJob: selected " + limitHash + " as limit hash");
try {
boolean enqueued = this.dhtDispatcher.selectContainersEnqueueToCloud(
diff --git a/source/de/anomic/plasma/plasmaWordIndex.java b/source/de/anomic/plasma/plasmaWordIndex.java
index 28538b0de..e98379c29 100644
--- a/source/de/anomic/plasma/plasmaWordIndex.java
+++ b/source/de/anomic/plasma/plasmaWordIndex.java
@@ -462,7 +462,7 @@ public final class plasmaWordIndex {
outlinksSame, outlinksOther,
wprop.flags);
try {
- this.index.add(Word.word2hash(word), ientry);
+ this.index.add(Word.word2hash(word), ientry); // TODO: remove getBytes()
} catch (IOException e) {
e.printStackTrace();
}
@@ -596,21 +596,21 @@ public final class plasmaWordIndex {
}
@SuppressWarnings("unchecked")
- public HashMap<String, ReferenceContainer<WordReference>>[] localSearchContainers(
- final TreeSet<String> queryHashes,
- final TreeSet<String> excludeHashes,
+ public HashMap<byte[], ReferenceContainer<WordReference>>[] localSearchContainers(
+ final TreeSet<byte[]> queryHashes,
+ final TreeSet<byte[]> excludeHashes,
final Set<String> urlselection) {
// search for the set of hashes and return a map of of wordhash:indexContainer containing the seach result
// retrieve entities that belong to the hashes
- HashMap<String, ReferenceContainer<WordReference>> inclusionContainers =
+ HashMap<byte[], ReferenceContainer<WordReference>> inclusionContainers =
(queryHashes.size() == 0) ?
- new HashMap<String, ReferenceContainer<WordReference>>(0) :
+ new HashMap<byte[], ReferenceContainer<WordReference>>(0) :
getContainers(queryHashes, urlselection);
- if ((inclusionContainers.size() != 0) && (inclusionContainers.size() < queryHashes.size())) inclusionContainers = new HashMap<String, ReferenceContainer<WordReference>>(0); // prevent that only a subset is returned
- final HashMap<String, ReferenceContainer<WordReference>> exclusionContainers =
+ if ((inclusionContainers.size() != 0) && (inclusionContainers.size() < queryHashes.size())) inclusionContainers = new HashMap<byte[], ReferenceContainer<WordReference>>(0); // prevent that only a subset is returned
+ final HashMap<byte[], ReferenceContainer<WordReference>> exclusionContainers =
(inclusionContainers.size() == 0) ?
- new HashMap<String, ReferenceContainer<WordReference>>(0) :
+ new HashMap<byte[], ReferenceContainer<WordReference>>(0) :
getContainers(excludeHashes, urlselection);
return new HashMap[]{inclusionContainers, exclusionContainers};
}
@@ -622,12 +622,12 @@ public final class plasmaWordIndex {
* @param urlselection
* @return map of wordhash:indexContainer
*/
- private HashMap<String, ReferenceContainer<WordReference>> getContainers(final Set<String> wordHashes, final Set<String> urlselection) {
+ private HashMap<byte[], ReferenceContainer<WordReference>> getContainers(final TreeSet<byte[]> wordHashes, final Set<String> urlselection) {
// retrieve entities that belong to the hashes
- final HashMap<String, ReferenceContainer<WordReference>> containers = new HashMap<String, ReferenceContainer<WordReference>>(wordHashes.size());
- String singleHash;
+ final HashMap<byte[], ReferenceContainer<WordReference>> containers = new HashMap<byte[], ReferenceContainer<WordReference>>(wordHashes.size());
+ byte[] singleHash;
ReferenceContainer<WordReference> singleContainer;
- final Iterator<String> i = wordHashes.iterator();
+ final Iterator<byte[]> i = wordHashes.iterator();
while (i.hasNext()) {
// get next word hash:
@@ -642,7 +642,7 @@ public final class plasmaWordIndex {
}
// check result
- if ((singleContainer == null || singleContainer.size() == 0)) return new HashMap<String, ReferenceContainer<WordReference>>(0);
+ if ((singleContainer == null || singleContainer.size() == 0)) return new HashMap<byte[], ReferenceContainer<WordReference>>(0);
containers.put(singleHash, singleContainer);
}
@@ -650,21 +650,21 @@ public final class plasmaWordIndex {
}
// The Cleaner class was provided as "UrldbCleaner" by Hydrox
- public synchronized ReferenceCleaner getReferenceCleaner(final String startHash) {
+ public synchronized ReferenceCleaner getReferenceCleaner(final byte[] startHash) {
return new ReferenceCleaner(startHash);
}
public class ReferenceCleaner extends Thread {
- private final String startHash;
+ private final byte[] startHash;
private boolean run = true;
private boolean pause = false;
public int rwiCountAtStart = 0;
- public String wordHashNow = "";
- public String lastWordHash = "";
+ public byte[] wordHashNow = null;
+ public byte[] lastWordHash = null;
public int lastDeletionCounter = 0;
- public ReferenceCleaner(final String startHash) {
+ public ReferenceCleaner(final byte[] startHash) {
this.startHash = startHash;
this.rwiCountAtStart = index().size();
}
diff --git a/source/de/anomic/server/serverObjects.java b/source/de/anomic/server/serverObjects.java
index b64dcc36b..626009772 100644
--- a/source/de/anomic/server/serverObjects.java
+++ b/source/de/anomic/server/serverObjects.java
@@ -152,6 +152,9 @@ public class serverObjects extends HashMap<String, String> implements Cloneable
public String putHTML(final String key, final String value) {
return put(key, htmlFilterCharacterCoding.unicode2html(value, true));
}
+ public String putHTML(final String key, final byte[] value) {
+ return putHTML(key, new String(value));
+ }
/**
* Like {@link #putHTML(String, String)} but takes an extra argument defining, if the returned
diff --git a/source/de/anomic/xml/SurrogateReader.java b/source/de/anomic/xml/SurrogateReader.java
index 13bcaddf2..09d86c48c 100644
--- a/source/de/anomic/xml/SurrogateReader.java
+++ b/source/de/anomic/xml/SurrogateReader.java
@@ -30,7 +30,8 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
-import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -49,7 +50,7 @@ public class SurrogateReader extends DefaultHandler implements Runnable, Iterato
private boolean parsingValue;
private Surrogate surrogate;
private String elementName;
- private LinkedBlockingQueue<Surrogate> surrogates;
+ private BlockingQueue<Surrogate> surrogates;
private SAXParser saxParser;
private InputStream stream;
private boolean isrunning;
@@ -59,7 +60,7 @@ public class SurrogateReader extends DefaultHandler implements Runnable, Iterato
this.parsingValue = false;
this.surrogate = null;
this.elementName = null;
- this.surrogates = new LinkedBlockingQueue<Surrogate>();
+ this.surrogates = new ArrayBlockingQueue<Surrogate>(3);
this.stream = stream;
final SAXParserFactory factory = SAXParserFactory.newInstance();
try {
@@ -102,15 +103,21 @@ public class SurrogateReader extends DefaultHandler implements Runnable, Iterato
if (tag == null) return;
if ("document".equals(tag)) {
//System.out.println("A Title: " + this.surrogate.title());
- this.surrogates.add(this.surrogate);
- //System.out.println("B Title: " + this.surrogate.title());
- this.surrogate = null;
- this.buffer.setLength(0);
- this.parsingValue = false;
+ try {
+ this.surrogates.put(this.surrogate);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ //System.out.println("B Title: " + this.surrogate.title());
+ this.surrogate = null;
+ this.buffer.setLength(0);
+ this.parsingValue = false;
+ }
} else if ("element".equals(tag)) {
this.buffer.setLength(0);
this.parsingValue = false;
} else if ("value".equals(tag)) {
+ //System.out.println("BUFFER-SIZE=" + buffer.length());
final String value = buffer.toString().trim();
if (this.elementName != null) {
this.surrogate.put(this.elementName, value);
@@ -149,7 +156,7 @@ public class SurrogateReader extends DefaultHandler implements Runnable, Iterato
try {
sr = new SurrogateReader(new BufferedInputStream(new FileInputStream(f)));
- Thread t = new Thread(sr);
+ Thread t = new Thread(sr, "Surrogate-Reader " + f.getAbsolutePath());
t.start();
Surrogate s;
System.out.println("1");
diff --git a/source/de/anomic/yacy/dht/Dispatcher.java b/source/de/anomic/yacy/dht/Dispatcher.java
index 0c32f73cf..64a58a5d3 100755
--- a/source/de/anomic/yacy/dht/Dispatcher.java
+++ b/source/de/anomic/yacy/dht/Dispatcher.java
@@ -27,10 +27,10 @@ package de.anomic.yacy.dht;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.TreeMap;
import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.text.BufferedIndex;
@@ -80,7 +80,7 @@ public class Dispatcher {
// a cloud is a cache for the objects that wait to be transmitted
// the String-key is the primary target as contained in the Entry
- private HashMap<String, Transmission.Chunk> transmissionCloud;
+ private TreeMap<byte[], Transmission.Chunk> transmissionCloud;
// the backend is used to store the remaining indexContainers in case that the object is closed
private BufferedIndex<WordReference> backend;
@@ -104,7 +104,7 @@ public class Dispatcher {
final boolean gzipBody,
final int timeout
) {
- this.transmissionCloud = new HashMap<String, Transmission.Chunk>();
+ this.transmissionCloud = new TreeMap<byte[], Transmission.Chunk>(Base64Order.enhancedCoder);
this.backend = backend;
this.seeds = seeds;
this.log = new Log("INDEX TRANSFER DISPATCHER");
@@ -146,8 +146,8 @@ public class Dispatcher {
* @throws IOException
*/
private ArrayList<ReferenceContainer<WordReference>> selectContainers(
- final String hash,
- final String limitHash,
+ final byte[] hash,
+ final byte[] limitHash,
final int maxContainerCount,
final int maxReferenceCount,
final int maxtime) throws IOException {
@@ -161,8 +161,8 @@ public class Dispatcher {
}
private ArrayList<ReferenceContainer<WordReference>> selectContainers(
- final String hash,
- final String limitHash,
+ final byte[] hash,
+ final byte[] limitHash,
final int maxContainerCount,
final int maxReferenceCount,
final int maxtime,
@@ -183,7 +183,7 @@ public class Dispatcher {
(System.currentTimeMillis() < timeout) &&
((container = indexContainerIterator.next()) != null) &&
((containers.size() == 0) ||
- (Base64Order.enhancedComparator.compare(container.getTermHash(), limitHash) < 0))
+ (Base64Order.enhancedCoder.compare(container.getTermHash(), limitHash) < 0))
) {
if (container.size() == 0) continue;
@@ -260,7 +260,7 @@ public class Dispatcher {
private void enqueueContainersToCloud(final ArrayList<ReferenceContainer<WordReference>>[] containers) {
if (transmissionCloud == null) return;
ReferenceContainer<WordReference> lastContainer;
- String primaryTarget;
+ byte[] primaryTarget;
Transmission.Chunk entry;
for (int vertical = 0; vertical < containers.length; vertical++) {
// the 'new' primary target is the word hash of the last container
@@ -288,8 +288,8 @@ public class Dispatcher {
}
public synchronized boolean selectContainersEnqueueToCloud(
- final String hash,
- final String limitHash,
+ final byte[] hash,
+ final byte[] limitHash,
final int maxContainerCount,
final int maxReferenceCount,
final int maxtime) throws IOException {
@@ -328,9 +328,9 @@ public class Dispatcher {
*/
public boolean dequeueContainer() {
if (this.indexingTransmissionProcessor.queueSize() > indexingTransmissionProcessor.concurrency()) return false;
- String maxtarget = "";
+ byte[] maxtarget = null;
int maxsize = -1;
- for (Map.Entry<String, Transmission.Chunk> chunk: this.transmissionCloud.entrySet()) {
+ for (Map.Entry<byte[], Transmission.Chunk> chunk: this.transmissionCloud.entrySet()) {
if (chunk.getValue().containersSize() > maxsize) {
maxsize = chunk.getValue().containersSize();
maxtarget = chunk.getKey();
@@ -378,7 +378,7 @@ public class Dispatcher {
// removes all entries from the dispatcher and puts them back to a RAMRI
if (indexingTransmissionProcessor != null) this.indexingTransmissionProcessor.announceShutdown();
if (this.transmissionCloud != null) {
- for (Map.Entry<String, Transmission.Chunk> e : this.transmissionCloud.entrySet()) {
+ for (Map.Entry<byte[], Transmission.Chunk> e : this.transmissionCloud.entrySet()) {
for (ReferenceContainer<WordReference> i : e.getValue()) try {this.backend.add(i);} catch (IOException e1) {}
}
this.transmissionCloud.clear();
diff --git a/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java b/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java
index a04ac6294..83aa0da09 100755
--- a/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java
+++ b/source/de/anomic/yacy/dht/FlatWordPartitionScheme.java
@@ -40,17 +40,17 @@ public class FlatWordPartitionScheme implements PartitionScheme {
return 1;
}
- public long dhtPosition(String wordHash, String urlHash) {
+ public long dhtPosition(byte[] wordHash, String urlHash) {
// the urlHash has no relevance here
// normalized to Long.MAX_VALUE
return Base64Order.enhancedCoder.cardinal(wordHash);
}
- public final long dhtDistance(final String word, final String urlHash, final yacySeed peer) {
- return dhtDistance(word, urlHash, peer.hash);
+ public final long dhtDistance(final byte[] word, final String urlHash, final yacySeed peer) {
+ return dhtDistance(word, urlHash, peer.hash.getBytes());
}
- private final long dhtDistance(final String from, final String urlHash, final String to) {
+ private final long dhtDistance(final byte[] from, final String urlHash, final byte[] to) {
// the dht distance is a positive value between 0 and 1
// if the distance is small, the word more probably belongs to the peer
assert to != null;
@@ -60,11 +60,11 @@ public class FlatWordPartitionScheme implements PartitionScheme {
return dhtDistance(fromPos, toPos);
}
- public long dhtPosition(String wordHash, int verticalPosition) {
+ public long dhtPosition(byte[] wordHash, int verticalPosition) {
return dhtPosition(wordHash, null);
}
- public long[] dhtPositions(String wordHash) {
+ public long[] dhtPositions(byte[] wordHash) {
long[] l = new long[1];
l[1] = dhtPosition(wordHash, null);
return l;
@@ -80,11 +80,11 @@ public class FlatWordPartitionScheme implements PartitionScheme {
(Long.MAX_VALUE - fromPos) + toPos + 1;
}
- public static String positionToHash(final long l) {
+ public static byte[] positionToHash(final long l) {
// transform the position of a peer position into a close peer hash
String s = new String(Base64Order.enhancedCoder.uncardinal(l));
while (s.length() < 12) s += "A";
- return s;
+ return s.getBytes();
}
}
diff --git a/source/de/anomic/yacy/dht/PartitionScheme.java b/source/de/anomic/yacy/dht/PartitionScheme.java
index 97da1e317..212bcaa20 100755
--- a/source/de/anomic/yacy/dht/PartitionScheme.java
+++ b/source/de/anomic/yacy/dht/PartitionScheme.java
@@ -60,15 +60,15 @@ public interface PartitionScheme {
public int verticalPartitions();
- public long dhtPosition(final String wordHash, final String urlHash);
+ public long dhtPosition(final byte[] wordHash, final String urlHash);
- public long dhtPosition(final String wordHash, final int verticalPosition);
+ public long dhtPosition(final byte[] wordHash, final int verticalPosition);
public int verticalPosition(final String urlHash);
- public long[] dhtPositions(final String wordHash);
+ public long[] dhtPositions(final byte[] wordHash);
- public long dhtDistance(final String word, final String urlHash, final yacySeed peer);
+ public long dhtDistance(final byte[] word, final String urlHash, final yacySeed peer);
}
diff --git a/source/de/anomic/yacy/dht/PeerSelection.java b/source/de/anomic/yacy/dht/PeerSelection.java
index efdad912b..6f680f55b 100755
--- a/source/de/anomic/yacy/dht/PeerSelection.java
+++ b/source/de/anomic/yacy/dht/PeerSelection.java
@@ -51,7 +51,7 @@ public class PeerSelection {
public static void selectDHTPositions(
final yacySeedDB seedDB,
- String wordhash,
+ byte[] wordhash,
int redundancy,
HashMap<String, yacySeed> regularSeeds,
ScoreCluster<String> ranking) {
@@ -80,7 +80,7 @@ public class PeerSelection {
private static int verifiedOwn = 0;
private static int verifiedNotOwn = 0;
- public static boolean shallBeOwnWord(final yacySeedDB seedDB, final String wordhash, String urlhash, int redundancy, PartitionScheme scheme) {
+ public static boolean shallBeOwnWord(final yacySeedDB seedDB, final byte[] wordhash, String urlhash, int redundancy, PartitionScheme scheme) {
// the guessIfOwnWord is a fast method that should only fail in case that a 'true' may be incorrect, but a 'false' shall always be correct
if (guessIfOwnWord(seedDB, wordhash, urlhash)) {
// this case must be verified, because it can be wrong.
@@ -117,19 +117,19 @@ public class PeerSelection {
}
- public static boolean guessIfOwnWord(final yacySeedDB seedDB, final String wordhash, final String urlhash) {
+ public static boolean guessIfOwnWord(final yacySeedDB seedDB, final byte[] wordhash, final String urlhash) {
if (seedDB == null) return false;
int connected = seedDB.sizeConnected();
if (connected == 0) return true;
final long target = seedDB.scheme.dhtPosition(wordhash, urlhash);
- final long mypos = seedDB.scheme.dhtPosition(seedDB.mySeed().hash, urlhash);
+ final long mypos = seedDB.scheme.dhtPosition(seedDB.mySeed().hash.getBytes(), urlhash);
long distance = FlatWordPartitionScheme.dhtDistance(target, mypos);
if (distance <= 0) return false;
if (distance <= Long.MAX_VALUE / connected * 2) return true;
return false;
}
- public static boolean verifyIfOwnWord(final yacySeedDB seedDB, String wordhash, String urlhash, int redundancy) {
+ public static boolean verifyIfOwnWord(final yacySeedDB seedDB, byte[] wordhash, String urlhash, int redundancy) {
String myHash = seedDB.mySeed().hash;
wordhash = FlatWordPartitionScheme.positionToHash(seedDB.scheme.dhtPosition(wordhash, urlhash));
Iterator<yacySeed> dhtEnum = getAcceptRemoteIndexSeeds(seedDB, wordhash, redundancy, true);
@@ -139,19 +139,19 @@ public class PeerSelection {
return false;
}
- public static String selectTransferStart() {
- return Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(Long.toString(System.currentTimeMillis()))).substring(2, 2 + yacySeedDB.commonHashLength);
+ public static byte[] selectTransferStart() {
+ return Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(Long.toString(System.currentTimeMillis()))).substring(2, 2 + yacySeedDB.commonHashLength).getBytes();
}
- public static String limitOver(final yacySeedDB seedDB, final String startHash) {
+ public static byte[] limitOver(final yacySeedDB seedDB, final byte[] startHash) {
Iterator<yacySeed> seeds = getAcceptRemoteIndexSeeds(seedDB, startHash, 1, false);
- if (seeds.hasNext()) return seeds.next().hash;
+ if (seeds.hasNext()) return seeds.next().hash.getBytes();
return null;
}
public static ArrayList<yacySeed> getAcceptRemoteIndexSeedsList(
yacySeedDB seedDB,
- final String starthash,
+ final byte[] starthash,
int max,
boolean alsoMyOwn) {
final Iterator<yacySeed> seedIter = PeerSelection.getAcceptRemoteIndexSeeds(seedDB, starthash, max, alsoMyOwn);
@@ -169,7 +169,7 @@ public class PeerSelection {
* @param alsoMyOwn
* @return
*/
- public static Iterator<yacySeed> getAcceptRemoteIndexSeeds(yacySeedDB seedDB, final String starthash, int max, boolean alsoMyOwn) {
+ public static Iterator<yacySeed> getAcceptRemoteIndexSeeds(yacySeedDB seedDB, final byte[] starthash, int max, boolean alsoMyOwn) {
return new acceptRemoteIndexSeedEnum(seedDB, starthash, Math.min(max, seedDB.sizeConnected()), alsoMyOwn);
}
@@ -182,7 +182,7 @@ public class PeerSelection {
private int remaining;
private boolean alsoMyOwn;
- public acceptRemoteIndexSeedEnum(yacySeedDB seedDB, final String starthash, int max, boolean alsoMyOwn) {
+ public acceptRemoteIndexSeedEnum(yacySeedDB seedDB, final byte[] starthash, int max, boolean alsoMyOwn) {
this.seedDB = seedDB;
this.se = getDHTSeeds(seedDB, starthash, yacyVersion.YACY_HANDLES_COLLECTION_INDEX);
this.remaining = max;
@@ -243,7 +243,7 @@ public class PeerSelection {
* @param minVersion
* @return
*/
- private static Iterator<yacySeed> getDHTSeeds(yacySeedDB seedDB, final String firstHash, final float minVersion) {
+ private static Iterator<yacySeed> getDHTSeeds(yacySeedDB seedDB, final byte[] firstHash, final float minVersion) {
// enumerates seed-type objects: all seeds with starting point in the middle, rotating at the end/beginning
return new seedDHTEnum(seedDB, firstHash, minVersion);
}
@@ -255,7 +255,7 @@ public class PeerSelection {
float minVersion;
yacySeedDB seedDB;
- public seedDHTEnum(yacySeedDB seedDB, final String firstHash, final float minVersion) {
+ public seedDHTEnum(yacySeedDB seedDB, final byte[] firstHash, final float minVersion) {
this.seedDB = seedDB;
this.steps = seedDB.sizeConnected();
this.minVersion = minVersion;
diff --git a/source/de/anomic/yacy/dht/Transmission.java b/source/de/anomic/yacy/dht/Transmission.java
index 44b8b9538..d490ed2c5 100644
--- a/source/de/anomic/yacy/dht/Transmission.java
+++ b/source/de/anomic/yacy/dht/Transmission.java
@@ -69,7 +69,7 @@ public class Transmission {
}
public Chunk newChunk(
- String primaryTarget,
+ byte[] primaryTarget,
final ArrayList<yacySeed> targets,
final Row payloadrow) {
return new Chunk(primaryTarget, targets, payloadrow);
@@ -86,7 +86,7 @@ public class Transmission {
* - a set of yacy seeds which will shrink as the containers are transmitted to them
* - a counter that gives the number of sucessful and unsuccessful transmissions so far
*/
- private String primaryTarget;
+ private byte[] primaryTarget;
private ReferenceContainerCache<WordReference> containers;
private HashMap<String, URLMetadataRow> references;
private HashSet<String> badReferences;
@@ -102,7 +102,7 @@ public class Transmission {
* @param payloadrow
*/
public Chunk(
- String primaryTarget,
+ byte[] primaryTarget,
final ArrayList<yacySeed> targets,
final Row payloadrow) {
super();
@@ -154,7 +154,7 @@ public class Transmission {
return this.containers.size();
}
- public String primaryTarget() {
+ public byte[] primaryTarget() {
return this.primaryTarget;
}
@@ -195,7 +195,7 @@ public class Transmission {
log.logInfo("Transfer of chunk to myself-target");
return true;
}
- log.logInfo("starting new index transmission request to " + this.primaryTarget);
+ log.logInfo("starting new index transmission request to " + new String(this.primaryTarget));
long start = System.currentTimeMillis();
final String error = yacyClient.transferIndex(target, this.containers, this.references, gzipBody4Transfer, timeout4Transfer);
if (error == null) {
@@ -204,7 +204,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.getTermHash()) + " .. " + this.primaryTarget + "]" +
+ " words [" + ((firstContainer == null) ? null : 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 b883b783b..bc68ab5cd 100755
--- a/source/de/anomic/yacy/dht/VerticalWordPartitionScheme.java
+++ b/source/de/anomic/yacy/dht/VerticalWordPartitionScheme.java
@@ -54,7 +54,7 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
* @param urlHash, the hash of a reference
* @return a double in the range 0 .. 1.0 (including 0, excluding 1.0), the DHT position
*/
- public final long dhtPosition(final String wordHash, final String urlHash) {
+ public final long dhtPosition(final byte[] wordHash, final String urlHash) {
// this creates 1^^e different positions for the same word hash (according to url hash)
assert wordHash != null;
assert urlHash != null;
@@ -68,10 +68,10 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
// in case that the partitionExpoent is 1, only one bit is taken from the urlHash,
// which means that the partition is in two parts.
// With partitionExponent = 2 it is divided in four parts and so on.
- return (FlatWordPartitionScheme.std.dhtPosition(wordHash, null) & partitionMask) | (FlatWordPartitionScheme.std.dhtPosition(urlHash, null) & ~partitionMask);
+ return (FlatWordPartitionScheme.std.dhtPosition(wordHash, null) & partitionMask) | (FlatWordPartitionScheme.std.dhtPosition(urlHash.getBytes(), null) & ~partitionMask);
}
- public final long dhtPosition(final String wordHash, final int verticalPosition) {
+ public final long dhtPosition(final byte[] wordHash, final int verticalPosition) {
assert wordHash != null;
if (partitionExponent == 0) return FlatWordPartitionScheme.std.dhtPosition(wordHash, null);
long partitionMask = (1L << (Long.SIZE - 1 - partitionExponent)) - 1L;
@@ -83,7 +83,7 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
assert urlHash != null;
if (urlHash == null || partitionExponent < 1) return 0;
assert partitionExponent > 0;
- return (int) (FlatWordPartitionScheme.std.dhtPosition(urlHash, null) >> (Long.SIZE - 1 - partitionExponent)); // take only the top-<partitionExponent> bits
+ return (int) (FlatWordPartitionScheme.std.dhtPosition(urlHash.getBytes(), null) >> (Long.SIZE - 1 - partitionExponent)); // take only the top-<partitionExponent> bits
}
/**
@@ -93,7 +93,7 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
* @param partitions, the number of partitions of the DHT
* @return a vector of long values, the possible DHT positions
*/
- public final long[] dhtPositions(final String wordHash) {
+ public final long[] dhtPositions(final byte[] wordHash) {
assert wordHash != null;
int partitions = 1 << partitionExponent;
long[] l = new long[partitions];
@@ -105,11 +105,11 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
return l;
}
- public final long dhtDistance(final String word, final String urlHash, final yacySeed peer) {
- return dhtDistance(word, urlHash, peer.hash);
+ public final long dhtDistance(final byte[] word, final String urlHash, final yacySeed peer) {
+ return dhtDistance(word, urlHash, peer.hash.getBytes());
}
- private final long dhtDistance(final String from, final String urlHash, final String to) {
+ private final long dhtDistance(final byte[] from, final String urlHash, final byte[] to) {
// the dht distance is a positive value between 0 and 1
// if the distance is small, the word more probably belongs to the peer
assert to != null;
@@ -132,10 +132,10 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
// the horizontal and vertical position calculation
String urlHash = args[1];
partitionExponent = Integer.parseInt(args[2]);
- dhtl = partition.dhtPosition(wordHash, urlHash);
+ dhtl = partition.dhtPosition(wordHash.getBytes(), urlHash);
} else {
// only a horizontal position calculation
- dhtl = FlatWordPartitionScheme.std.dhtPosition(wordHash, null);
+ dhtl = FlatWordPartitionScheme.std.dhtPosition(wordHash.getBytes(), null);
}
//System.out.println("DHT Double = " + dhtd);
System.out.println("DHT Long = " + dhtl);
@@ -155,7 +155,7 @@ public class VerticalWordPartitionScheme implements PartitionScheme {
System.out.println();
*/
System.out.print("all " + (1 << partitionExponent) + " DHT positions from long : ");
- long[] l = partition.dhtPositions(wordHash);
+ long[] l = partition.dhtPositions(wordHash.getBytes());
for (int i = 0; i < l.length; i++) {
if (i > 0) System.out.print(", ");
System.out.print(FlatWordPartitionScheme.positionToHash(l[i]));
diff --git a/source/de/anomic/yacy/yacyClient.java b/source/de/anomic/yacy/yacyClient.java
index e8a3871d7..abdcd21fc 100644
--- a/source/de/anomic/yacy/yacyClient.java
+++ b/source/de/anomic/yacy/yacyClient.java
@@ -529,7 +529,7 @@ public final class yacyClient {
final int words = wordhashes.length() / yacySeedDB.commonHashLength;
final ReferenceContainer<WordReference>[] container = new ReferenceContainer[words];
for (int i = 0; i < words; i++) {
- container[i] = ReferenceContainer.emptyContainer(plasmaWordIndex.wordReferenceFactory, wordhashes.substring(i * yacySeedDB.commonHashLength, (i + 1) * yacySeedDB.commonHashLength), count);
+ container[i] = ReferenceContainer.emptyContainer(plasmaWordIndex.wordReferenceFactory, wordhashes.substring(i * yacySeedDB.commonHashLength, (i + 1) * yacySeedDB.commonHashLength).getBytes(), count);
}
// insert results to containers
@@ -1077,7 +1077,7 @@ public final class yacyClient {
/*final yacyCore core =*/ new yacyCore(sb);
sb.loadSeedLists();
final yacySeed target = sb.webIndex.peers().getConnected(args[1]);
- final String wordhashe = Word.word2hash("test");
+ final byte[] wordhashe = Word.word2hash("test");
//System.out.println("permission=" + permissionMessage(args[1]));
final httpRequestHeader reqHeader = new httpRequestHeader();
@@ -1089,7 +1089,7 @@ public final class yacyClient {
"&myseed=" + sb.webIndex.peers().mySeed() .genSeedStr(null) +
"&count=10" +
"&resource=global" +
- "&query=" + wordhashe +
+ "&query=" + new String(wordhashe) +
"&network.unit.name=" + plasmaSwitchboard.getSwitchboard().getConfig(plasmaSwitchboardConstants.NETWORK_NAME, yacySeed.DFLT_NETWORK_UNIT),
reqHeader, 10000, target.getHexHash() + ".yacyh");
final HashMap<String, String> result = FileUtils.table(content, "UTF-8");
diff --git a/source/de/anomic/yacy/yacyCore.java b/source/de/anomic/yacy/yacyCore.java
index 161a4daa1..c827df363 100644
--- a/source/de/anomic/yacy/yacyCore.java
+++ b/source/de/anomic/yacy/yacyCore.java
@@ -305,24 +305,24 @@ public class yacyCore {
// getting a list of peers to contact
if (sb.webIndex.peers().mySeed().get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN).equals(yacySeed.PEERTYPE_VIRGIN)) {
if (attempts > PING_INITIAL) { attempts = PING_INITIAL; }
- final Map<String, String> ch = plasmaSwitchboard.getSwitchboard().clusterhashes;
+ final Map<byte[], String> ch = plasmaSwitchboard.getSwitchboard().clusterhashes;
seeds = PeerSelection.seedsByAge(sb.webIndex.peers(), true, attempts - ((ch == null) ? 0 : ch.size())); // best for fast connection
// add also all peers from cluster if this is a public robinson cluster
if (ch != null) {
- final Iterator<Map.Entry<String, String>> i = ch.entrySet().iterator();
- String hash;
- Map.Entry<String, String> entry;
+ final Iterator<Map.Entry<byte[], String>> i = ch.entrySet().iterator();
+ byte[] hash;
+ Map.Entry<byte[], String> entry;
yacySeed seed;
while (i.hasNext()) {
entry = i.next();
hash = entry.getKey();
seed = seeds.get(hash);
if (seed == null) {
- seed = sb.webIndex.peers().get(hash);
+ seed = sb.webIndex.peers().get(new String(hash));
if (seed == null) continue;
}
seed.setAlternativeAddress(entry.getValue());
- seeds.put(hash, seed);
+ seeds.put(new String(hash), seed);
}
}
} else {
diff --git a/source/de/anomic/yacy/yacySearch.java b/source/de/anomic/yacy/yacySearch.java
index 87879e749..218218c03 100644
--- a/source/de/anomic/yacy/yacySearch.java
+++ b/source/de/anomic/yacy/yacySearch.java
@@ -47,8 +47,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import de.anomic.crawler.ResultURLs;
import de.anomic.data.Blacklist;
@@ -130,10 +130,10 @@ public class yacySearch extends Thread {
}
}
- public static String set2string(final Set<String> hashes) {
+ public static String set2string(final TreeSet<byte[]> hashes) {
String wh = "";
- final Iterator<String> iter = hashes.iterator();
- while (iter.hasNext()) { wh = wh + iter.next(); }
+ final Iterator<byte[]> iter = hashes.iterator();
+ while (iter.hasNext()) { wh = wh + new String(iter.next()); }
return wh;
}
@@ -149,14 +149,14 @@ public class yacySearch extends Thread {
return targetPeer;
}
- private static yacySeed[] selectClusterPeers(final yacySeedDB seedDB, final TreeMap<String, String> peerhashes) {
- final Iterator<Map.Entry<String, String>> i = peerhashes.entrySet().iterator();
+ private static yacySeed[] selectClusterPeers(final yacySeedDB seedDB, final TreeMap<byte[], String> peerhashes) {
+ final Iterator<Map.Entry<byte[], String>> i = peerhashes.entrySet().iterator();
final ArrayList<yacySeed> l = new ArrayList<yacySeed>();
- Map.Entry<String, String> entry;
+ Map.Entry<byte[], String> entry;
yacySeed s;
while (i.hasNext()) {
entry = i.next();
- s = seedDB.get(entry.getKey()); // should be getConnected; get only during testing time
+ s = seedDB.get(new String(entry.getKey())); // should be getConnected; get only during testing time
if (s != null) {
s.setAlternativeAddress(entry.getValue());
l.add(s);
@@ -170,7 +170,7 @@ public class yacySearch extends Thread {
//return (yacySeed[]) l.toArray();
}
- private static yacySeed[] selectSearchTargets(final yacySeedDB seedDB, final Set<String> wordhashes, int seedcount, int redundancy) {
+ private static yacySeed[] selectSearchTargets(final yacySeedDB seedDB, final TreeSet<byte[]> 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
@@ -185,7 +185,7 @@ public class yacySearch extends Thread {
final HashMap<String, yacySeed> matchingSeeds = new HashMap<String, yacySeed>();
yacySeed seed;
Iterator<yacySeed> dhtEnum;
- Iterator<String> iter = wordhashes.iterator();
+ Iterator<byte[]> iter = wordhashes.iterator();
while (iter.hasNext()) {
PeerSelection.selectDHTPositions(seedDB, iter.next(), redundancy, regularSeeds, ranking);
}
@@ -228,9 +228,9 @@ public class yacySearch extends Thread {
seedcount = Math.min(ranking.size(), seedcount);
final yacySeed[] result = new yacySeed[seedcount + matchingSeeds.size()];
c = 0;
- iter = ranking.scores(false); // higher are better
- while (iter.hasNext() && c < seedcount) {
- seed = regularSeeds.get(iter.next());
+ Iterator<String> iters = ranking.scores(false); // higher are better
+ while (iters.hasNext() && c < seedcount) {
+ seed = regularSeeds.get(iters.next());
seed.selectscore = c;
Log.logInfo("PLASMA", "selectPeers/_dht_: " + seed.hash + ":" + seed.getName() + " is choice " + c);
result[c++] = seed;
@@ -257,7 +257,7 @@ public class yacySearch extends Thread {
final Blacklist blacklist,
final plasmaSearchRankingProfile rankingProfile,
final Bitfield constraint,
- final TreeMap<String, String> clusterselection) {
+ final TreeMap<byte[], String> clusterselection) {
// check own peer status
//if (wordIndex.seedDB.mySeed() == null || wordIndex.seedDB.mySeed().getPublicAddress() == null) { return null; }
@@ -292,14 +292,14 @@ public class yacySearch extends Thread {
final plasmaSearchRankingProcess containerCache,
final String targethash, final Blacklist blacklist,
final plasmaSearchRankingProfile rankingProfile,
- final Bitfield constraint, final TreeMap<String, String> clusterselection) {
+ final Bitfield constraint, final TreeMap<byte[], String> clusterselection) {
// check own peer status
if (wordIndex.peers().mySeed() == null || wordIndex.peers().mySeed().getPublicAddress() == null) { return null; }
// prepare seed targets and threads
final yacySeed targetPeer = wordIndex.peers().getConnected(targethash);
if (targetPeer == null || targetPeer.hash == null) return null;
- if (clusterselection != null) targetPeer.setAlternativeAddress(clusterselection.get(targetPeer.hash));
+ if (clusterselection != null) targetPeer.setAlternativeAddress(clusterselection.get(targetPeer.hash.getBytes()));
final yacySearch searchThread = new yacySearch(wordhashes, excludehashes, urlhashes, "", "", "en", 0, 9999, true, 0, targetPeer,
wordIndex, crawlResults, containerCache, new TreeMap<String, TreeMap<String, String>>(), blacklist, rankingProfile, constraint);
searchThread.start();
diff --git a/source/de/anomic/yacy/yacySeed.java b/source/de/anomic/yacy/yacySeed.java
index 0eb11ff6f..4630c4635 100644
--- a/source/de/anomic/yacy/yacySeed.java
+++ b/source/de/anomic/yacy/yacySeed.java
@@ -54,6 +54,7 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.order.Digest;
@@ -580,7 +581,7 @@ public class yacySeed implements Cloneable {
return serverCodings.string2set(get(PEERTAGS, ""), "|");
}
- public boolean matchPeerTags(final Set<String> searchHashes) {
+ public boolean matchPeerTags(final TreeSet<byte[]> searchHashes) {
final String peertags = get(PEERTAGS, "");
if (peertags.equals("*")) return true;
final Set<String> tags = serverCodings.string2set(peertags, "|");
@@ -676,7 +677,7 @@ public class yacySeed implements Cloneable {
return type.equals(yacySeed.PEERTYPE_SENIOR) || type.equals(yacySeed.PEERTYPE_PRINCIPAL);
}
- private static String bestGap(final yacySeedDB seedDB) {
+ private static byte[] bestGap(final yacySeedDB seedDB) {
if ((seedDB == null) || (seedDB.sizeConnected() <= 2)) {
// use random hash
return randomHash();
@@ -695,9 +696,9 @@ public class yacySeed implements Cloneable {
// find dht position and size of gap
final long gaphalf = FlatWordPartitionScheme.dhtDistance(
- FlatWordPartitionScheme.std.dhtPosition(interval.substring(0, 12), null),
- FlatWordPartitionScheme.std.dhtPosition(interval.substring(12), null)) >> 1;
- long p = FlatWordPartitionScheme.std.dhtPosition(interval.substring(0, 12), null);
+ FlatWordPartitionScheme.std.dhtPosition(interval.substring(0, 12).getBytes(), null),
+ FlatWordPartitionScheme.std.dhtPosition(interval.substring(12).getBytes(), null)) >> 1;
+ long p = FlatWordPartitionScheme.std.dhtPosition(interval.substring(0, 12).getBytes(), null);
long gappos = (Long.MAX_VALUE - p >= gaphalf) ? p + gaphalf : (p - Long.MAX_VALUE) + gaphalf;
return FlatWordPartitionScheme.positionToHash(gappos);
}
@@ -717,16 +718,16 @@ public class yacySeed implements Cloneable {
continue;
}
l = FlatWordPartitionScheme.dhtDistance(
- FlatWordPartitionScheme.std.dhtPosition(s0.hash, null),
- FlatWordPartitionScheme.std.dhtPosition(s1.hash, null));
+ FlatWordPartitionScheme.std.dhtPosition(s0.hash.getBytes(), null),
+ FlatWordPartitionScheme.std.dhtPosition(s1.hash.getBytes(), null));
gaps.put(l, s0.hash + s1.hash);
s0 = s1;
}
// compute also the last gap
if ((first != null) && (s0 != null)) {
l = FlatWordPartitionScheme.dhtDistance(
- FlatWordPartitionScheme.std.dhtPosition(s0.hash, null),
- FlatWordPartitionScheme.std.dhtPosition(first.hash, null));
+ FlatWordPartitionScheme.std.dhtPosition(s0.hash.getBytes(), null),
+ FlatWordPartitionScheme.std.dhtPosition(first.hash.getBytes(), null));
gaps.put(l, s0.hash + first.hash);
}
return gaps;
@@ -740,10 +741,10 @@ public class yacySeed implements Cloneable {
// generate a seed for the local peer
// this is the birthplace of a seed, that then will start to travel to other peers
- final String hash = bestGap(db);
+ final byte[] hash = bestGap(db);
yacyCore.log.logInfo("init: OWN SEED = " + hash);
- final yacySeed newSeed = new yacySeed(hash);
+ final yacySeed newSeed = new yacySeed(new String(hash));
// now calculate other information about the host
newSeed.dna.put(yacySeed.NAME, (name) == null ? "anonymous" : name);
@@ -758,11 +759,11 @@ public class yacySeed implements Cloneable {
//public static String randomHash() { return "zLXFf5lTteUv"; } // only for debugging
- public static String randomHash() {
+ public static byte[] randomHash() {
final String hash =
Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(Long.toString(random.nextLong()))).substring(0, 6) +
Base64Order.enhancedCoder.encode(Digest.encodeMD5Raw(Long.toString(random.nextLong()))).substring(0, 6);
- return hash;
+ return hash.getBytes();
}
public static yacySeed genRemoteSeed(final String seedStr, final String key, final boolean ownSeed) {
diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.java
index a2c792635..63eeceebd 100644
--- a/source/de/anomic/yacy/yacySeedDB.java
+++ b/source/de/anomic/yacy/yacySeedDB.java
@@ -324,7 +324,7 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
return new seedEnum(up, field, seedPotentialDB);
}
- public TreeMap<String, String> /* peer-b64-hashes/ipport */ clusterHashes(final String clusterdefinition) {
+ public TreeMap<byte[], String> /* peer-b64-hashes/ipport */ clusterHashes(final String clusterdefinition) {
// collects seeds according to cluster definition string, which consists of
// comma-separated .yacy or .yacyh-domains
// the domain may be extended by an alternative address specification of the form
@@ -334,7 +334,7 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
// address ::= (<peername>'.yacy'|<peerhexhash>'.yacyh'){'='<ip>{':'<port}}
// clusterdef ::= {address}{','address}*
final String[] addresses = (clusterdefinition.length() == 0) ? new String[0] : clusterdefinition.split(",");
- final TreeMap<String, String> clustermap = new TreeMap<String, String>(Base64Order.enhancedComparator);
+ final TreeMap<byte[], String> clustermap = new TreeMap<byte[], String>(Base64Order.enhancedCoder);
yacySeed seed;
String hash, yacydom, ipport;
int p;
@@ -354,7 +354,7 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
if (seed == null) {
yacyCore.log.logWarning("cluster peer '" + yacydom + "' was not found.");
} else {
- clustermap.put(hash, ipport);
+ clustermap.put(hash.getBytes(), ipport);
}
} else if (yacydom.endsWith(".yacy")) {
// find a peer with its name
@@ -362,7 +362,7 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
if (seed == null) {
yacyCore.log.logWarning("cluster peer '" + yacydom + "' was not found.");
} else {
- clustermap.put(seed.hash, ipport);
+ clustermap.put(seed.hash.getBytes(), ipport);
}
} else {
yacyCore.log.logWarning("cluster peer '" + addresses[i] + "' has wrong syntax. the name must end with .yacy or .yacyh");
@@ -371,19 +371,19 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
return clustermap;
}
- public Iterator<yacySeed> seedsConnected(final boolean up, final boolean rot, final String firstHash, final float minVersion) {
+ public Iterator<yacySeed> seedsConnected(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
- return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), null, seedActiveDB, minVersion);
+ return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, seedActiveDB, minVersion);
}
- public Iterator<yacySeed> seedsDisconnected(final boolean up, final boolean rot, final String firstHash, final float minVersion) {
+ public Iterator<yacySeed> seedsDisconnected(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
- return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), null, seedPassiveDB, minVersion);
+ return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, seedPassiveDB, minVersion);
}
- public Iterator<yacySeed> seedsPotential(final boolean up, final boolean rot, final String firstHash, final float minVersion) {
+ public Iterator<yacySeed> seedsPotential(final boolean up, final boolean rot, final byte[] firstHash, final float minVersion) {
// enumerates seed-type objects: all seeds sequentially without order
- return new seedEnum(up, rot, (firstHash == null) ? null : firstHash.getBytes(), null, seedPotentialDB, minVersion);
+ return new seedEnum(up, rot, (firstHash == null) ? null : firstHash, null, seedPotentialDB, minVersion);
}
public yacySeed anySeedVersion(final float minVersion) {
diff --git a/source/yacy.java b/source/yacy.java
index e7f81916c..ba070e799 100644
--- a/source/yacy.java
+++ b/source/yacy.java
@@ -35,10 +35,10 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -622,25 +622,25 @@ public final class yacy {
// load words
Log.logInfo("GEN-WORDSTAT", "loading words...");
- final HashMap<String, String> words = loadWordMap(new File(homePath, "yacy.words"));
+ final TreeMap<byte[], String> words = loadWordMap(new File(homePath, "yacy.words"));
// find all hashes
Log.logInfo("GEN-WORDSTAT", "searching all word-hash databases...");
final File dbRoot = new File(homePath, config.getProperty("dbPath"));
final enumerateFiles ef = new enumerateFiles(new File(dbRoot, "WORDS"), true, false, true, true);
File f;
- String h;
- final ScoreCluster<String> hs = new ScoreCluster<String>();
+ byte[] h;
+ final ScoreCluster<byte[]> hs = new ScoreCluster<byte[]>();
while (ef.hasMoreElements()) {
f = ef.nextElement();
- h = f.getName().substring(0, yacySeedDB.commonHashLength);
+ h = f.getName().substring(0, yacySeedDB.commonHashLength).getBytes();
hs.addScore(h, (int) f.length());
}
// list the hashes in reverse order
Log.logInfo("GEN-WORDSTAT", "listing words in reverse size order...");
String w;
- final Iterator<String> i = hs.scores(false);
+ final Iterator<byte[]> i = hs.scores(false);
while (i.hasNext()) {
h = i.next();
w = words.get(h);
@@ -676,7 +676,7 @@ public final class yacy {
if (cacheMem < 2048000) throw new OutOfMemoryError("Not enough memory available to start clean up.");
final plasmaWordIndex wordIndex = new plasmaWordIndex(networkName, log, indexPrimaryRoot, indexSecondaryRoot, 10000, false, 1, 0, false);
- final Iterator<ReferenceContainer<WordReference>> indexContainerIterator = wordIndex.index().references("AAAAAAAAAAAA", false, false);
+ final Iterator<ReferenceContainer<WordReference>> indexContainerIterator = wordIndex.index().references("AAAAAAAAAAAA".getBytes(), false, false);
long urlCounter = 0, wordCounter = 0;
long wordChunkStart = System.currentTimeMillis(), wordChunkEnd = 0;
@@ -705,7 +705,7 @@ public final class yacy {
}
if (wordCounter%500 == 0) {
- wordChunkEndHash = wordIdxContainer.getTermHash();
+ wordChunkEndHash = new String(wordIdxContainer.getTermHash());
wordChunkEnd = System.currentTimeMillis();
final long duration = wordChunkEnd - wordChunkStart;
log.logInfo(wordCounter + " words scanned " +
@@ -747,15 +747,15 @@ public final class yacy {
}
/**
- * Reads all words from the given file and creates a hashmap, where key is
+ * Reads all words from the given file and creates a treemap, where key is
* the plasma word hash and value is the word itself.
*
* @param wordlist File where the words are stored.
* @return HashMap with the hash-word - relation.
*/
- private static HashMap<String, String> loadWordMap(final File wordlist) {
+ private static TreeMap<byte[], String> loadWordMap(final File wordlist) {
// returns a hash-word - Relation
- final HashMap<String, String> wordmap = new HashMap<String, String>();
+ final TreeMap<byte[], String> wordmap = new TreeMap<byte[], String>(Base64Order.enhancedCoder);
try {
String word;
final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(wordlist)));
@@ -867,7 +867,7 @@ public final class yacy {
Iterator<ReferenceContainer<WordReference>> indexContainerIterator = null;
if (resource.equals("all")) {
WordIndex = new plasmaWordIndex("freeworld", log, indexPrimaryRoot, indexSecondaryRoot, 10000, false, 1, 0, false);
- indexContainerIterator = WordIndex.index().references(wordChunkStartHash, false, false);
+ indexContainerIterator = WordIndex.index().references(wordChunkStartHash.getBytes(), false, false);
}
int counter = 0;
ReferenceContainer<WordReference> container = null;
@@ -881,7 +881,7 @@ public final class yacy {
while (indexContainerIterator.hasNext()) {
counter++;
container = indexContainerIterator.next();
- bos.write((container.getTermHash()).getBytes());
+ bos.write(container.getTermHash());
bos.write(serverCore.CRLF);
if (counter % 500 == 0) {
log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + container.getTermHash());
@@ -898,7 +898,7 @@ public final class yacy {
while (indexContainerIterator.hasNext()) {
counter++;
container = indexContainerIterator.next();
- bos.write((container.getTermHash()).getBytes());
+ bos.write(container.getTermHash());
bos.write(serverCore.CRLF);
if (counter % 500 == 0) {
log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + container.getTermHash());