even more efficient comparator calls (less System.arraycopy for primary keys)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5715 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 65784eb656
commit b7138e5fcb

@ -294,7 +294,7 @@ public class BLOBHeapModifier extends HeapReader implements BLOB {
// read the key
final 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 blob
byte[] blob = new byte[len];

@ -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 key
final 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 index
Log.logWarning("kelondroBLOBHeap", "verification indexed access for " + heapFile.toString() + " failed, re-building index");
// this is a severe operation, it should never happen.

@ -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 key
if (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 entry
final 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;
}

@ -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 defined
public void rotate(A zero); // defines that the ordering rotates, and sets the zero point for the rotation

@ -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();

@ -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 nothing

@ -52,7 +52,11 @@ public class ReferenceContainerOrder extends AbstractOrder<ReferenceContainer> i
public 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);

Loading…
Cancel
Save