Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
even more efficient comparator calls (less System.arraycopy for primary keys)
orbiterb7138e5fcb6f
diff --git a/source/de/anomic/kelondro/blob/BLOBHeapModifier.java b/source/de/anomic/kelondro/blob/BLOBHeapModifier.javaindex 0a084d7cb..e2c40ceeb 100644--- a/source/de/anomic/kelondro/blob/BLOBHeapModifier.java+++ b/source/de/anomic/kelondro/blob/BLOBHeapModifier.java@@ -294,7 +294,7 @@ public class BLOBHeapModifier extends HeapReader implements BLOB {// read the keyfinal byte[] keyf = new byte[index.row().primaryKeyLength];file.readFully(keyf, 0, keyf.length);- assert this.ordering.compare(key, keyf) == 0;+ assert this.ordering.equal(key, keyf);// read the blobbyte[] blob = new byte[len];diff --git a/source/de/anomic/kelondro/blob/HeapReader.java b/source/de/anomic/kelondro/blob/HeapReader.javaindex bf661c08f..9cb123ccd 100644--- a/source/de/anomic/kelondro/blob/HeapReader.java+++ b/source/de/anomic/kelondro/blob/HeapReader.java@@ -76,7 +76,7 @@ public class HeapReader {pos = this.index.get(b);file.seek(pos + 4);file.readFully(b1, 0, b1.length);- if (this.ordering.compare(b, b1) != 0) {+ if (!this.ordering.equal(b, b1)) {ok = false;break;}@@ -239,7 +239,7 @@ public class HeapReader {// read the keyfinal byte[] keyf = new byte[index.row().primaryKeyLength];file.readFully(keyf, 0, keyf.length);- if (this.ordering.compare(key, keyf) != 0) {+ if (!this.ordering.equal(key, keyf)) {// verification of the indexed access failed. we must re-read the indexLog.logWarning("kelondroBLOBHeap", "verification indexed access for " + heapFile.toString() + " failed, re-building index");// this is a severe operation, it should never happen.diff --git a/source/de/anomic/kelondro/index/Row.java b/source/de/anomic/kelondro/index/Row.javaindex 77d818b85..8dae09013 100644--- a/source/de/anomic/kelondro/index/Row.java+++ b/source/de/anomic/kelondro/index/Row.java@@ -202,6 +202,10 @@ public final class Row {public int compare(final Entry a, final Entry b) {return a.compareTo(b);}++ public boolean equal(Entry a, Entry b) {+ return a.equals(b);+ }public Order<Entry> clone() {return new EntryComparator(base);@@ -324,15 +328,14 @@ public final class Row {public final int compareTo(final Entry o) {// compares only the content of the primary keyif (objectOrder == null) throw new kelondroException("objects cannot be compared, no order given");- return objectOrder.compare(this.getPrimaryKeyBytes(), (o).getPrimaryKeyBytes());+ return objectOrder.compare(this.bytes(), 0, this.getPrimaryKeyLength(), o.bytes(), 0, o.getPrimaryKeyLength());}public final boolean equals(final Entry otherEntry) {// compares the content of the complete entryfinal byte[] t = this.bytes();final byte[] o = otherEntry.bytes();- if (o.length != t.length) return false;- for (int i = 0; i < t.length; i++) {+ for (int i = 0; i < primaryKeyLength; i++) {if (t[i] != o[i]) return false;}return true;@@ -656,7 +659,7 @@ public final class Row {public Entry get(byte[] key) {for (Entry e: this.queue) {- if (objectOrder.compare(key, e.getPrimaryKeyBytes()) == 0) {+ if (objectOrder.compare(key, 0, key.length, e.bytes(), 0, e.getPrimaryKeyLength()) == 0) {return e;}}@@ -668,7 +671,7 @@ public final class Row {Entry e;while (i.hasNext()) {e = i.next();- if (objectOrder.compare(key, e.getPrimaryKeyBytes()) == 0) {+ if (objectOrder.compare(key, 0, key.length, e.bytes(), 0, e.getPrimaryKeyLength()) == 0) {i.remove();return e;}diff --git a/source/de/anomic/kelondro/order/Order.java b/source/de/anomic/kelondro/order/Order.javaindex 54025bfcb..74414d0c2 100644--- a/source/de/anomic/kelondro/order/Order.java+++ b/source/de/anomic/kelondro/order/Order.java@@ -44,6 +44,8 @@ public interface Order<A> extends Comparator<A> {public int compare(A a, A b);+ public boolean equal(A a, A b);+public A zero(); // returns the zero point of the Ordering; null if not definedpublic void rotate(A zero); // defines that the ordering rotates, and sets the zero point for the rotationdiff --git a/source/de/anomic/kelondro/table/FlexTable.java b/source/de/anomic/kelondro/table/FlexTable.javaindex bc11e4ec2..502ba4b21 100644--- a/source/de/anomic/kelondro/table/FlexTable.java+++ b/source/de/anomic/kelondro/table/FlexTable.java@@ -259,7 +259,7 @@ public class FlexTable extends FlexWidthArray implements ObjectIndex {return null;}assert oldentry != null : "overwrite of empty position " + pos + ", index management must have failed before";- assert rowdef.objectOrder.compare(oldentry.getPrimaryKeyBytes(), key) == 0 : "key and row does not match; key = " + NaturalOrder.arrayList(key, 0, key.length) + " row.key = " + NaturalOrder.arrayList(oldentry.getPrimaryKeyBytes(), 0, rowdef.primaryKeyLength);+ assert rowdef.objectOrder.equal(oldentry.getPrimaryKeyBytes(), key) : "key and row does not match; key = " + NaturalOrder.arrayList(key, 0, key.length) + " row.key = " + NaturalOrder.arrayList(oldentry.getPrimaryKeyBytes(), 0, rowdef.primaryKeyLength);super.set(pos, row);assert this.size() == index.size() : "content.size() = " + this.size() + ", index.size() = " + index.size();return oldentry;@@ -343,7 +343,7 @@ public class FlexTable extends FlexWidthArray implements ObjectIndex {return null;}assert r != null : "r == null"; // should be avoided with path above- assert rowdef.objectOrder.compare(r.getPrimaryKeyBytes(), key) == 0 : "key and row does not match; key = " + NaturalOrder.arrayList(key, 0, key.length) + " row.key = " + NaturalOrder.arrayList(r.getPrimaryKeyBytes(), 0, rowdef.primaryKeyLength);+ assert rowdef.objectOrder.equal(r.getPrimaryKeyBytes(), key) : "key and row does not match; key = " + NaturalOrder.arrayList(key, 0, key.length) + " row.key = " + NaturalOrder.arrayList(r.getPrimaryKeyBytes(), 0, rowdef.primaryKeyLength);super.remove(i);assert super.get(i) == null : "i = " + i + ", get(i) = " + NaturalOrder.arrayList(super.get(i).bytes(), 0, 12);assert this.size() == index.size() : "content.size() = " + this.size() + ", index.size() = " + index.size();diff --git a/source/de/anomic/kelondro/text/IndexCollection.java b/source/de/anomic/kelondro/text/IndexCollection.javaindex 07622da3b..85c2c4fca 100644--- a/source/de/anomic/kelondro/text/IndexCollection.java+++ b/source/de/anomic/kelondro/text/IndexCollection.java@@ -949,7 +949,7 @@ public class IndexCollection implements Index {}final RowSet collection = new RowSet(this.payloadrow, arrayrow); // FIXME: this does not yet work with different rowdef in case of several rowdef.objectsize()- if ((!(index.row().objectOrder.wellformed(indexkey))) || (index.row().objectOrder.compare(arraykey, indexkey) != 0)) {+ if ((!(index.row().objectOrder.wellformed(indexkey))) || (!index.row().objectOrder.equal(arraykey, indexkey))) {// check if we got the right row; this row is wrong. Fix it:index.remove(indexkey); // the wrong row cannot be fixed// store the row number in the index; this may be a double-entry, but better than nothingdiff --git a/source/de/anomic/kelondro/text/ReferenceContainerOrder.java b/source/de/anomic/kelondro/text/ReferenceContainerOrder.javaindex 78994c2a0..9184c4810 100644--- a/source/de/anomic/kelondro/text/ReferenceContainerOrder.java+++ b/source/de/anomic/kelondro/text/ReferenceContainerOrder.java@@ -52,7 +52,11 @@ public class ReferenceContainerOrder extends AbstractOrder<ReferenceContainer> ipublic int compare(final ReferenceContainer a, final ReferenceContainer b) {return this.embeddedOrder.compare(a.getWordHash().getBytes(), b.getWordHash().getBytes());}-++ public boolean equal(ReferenceContainer a, ReferenceContainer b) {+ return this.embeddedOrder.equal(a.getWordHash().getBytes(), b.getWordHash().getBytes());+ }+public void rotate(final ReferenceContainer zero) {this.embeddedOrder.rotate(zero.getWordHash().getBytes());this.zero = new ReferenceContainer(new String(this.embeddedOrder.zero()), zero);