diff --git a/source/de/anomic/kelondro/kelondroBase64Order.java b/source/de/anomic/kelondro/kelondroBase64Order.java index 5af455596..2d7d8c35b 100644 --- a/source/de/anomic/kelondro/kelondroBase64Order.java +++ b/source/de/anomic/kelondro/kelondroBase64Order.java @@ -48,15 +48,17 @@ package de.anomic.kelondro; import java.util.Comparator; +import de.anomic.server.logging.serverLog; + public class kelondroBase64Order extends kelondroAbstractOrder implements kelondroOrder, kelondroCoding, Comparator { private static final char[] alpha_standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); private static final char[] alpha_enhanced = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".toCharArray(); - private static final byte[] ahpla_standard = new byte[256]; - private static final byte[] ahpla_enhanced = new byte[256]; + private static final byte[] ahpla_standard = new byte[128]; + private static final byte[] ahpla_enhanced = new byte[128]; static { - for (int i = 0; i < 256; i++) { + for (int i = 0; i < 128; i++) { ahpla_standard[i] = -1; ahpla_enhanced[i] = -1; } @@ -279,13 +281,28 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond } public final int compares(byte[] a, int aoffset, int alength, byte[] b, int boffset, int blength) { + assert (aoffset + alength <= a.length) : "a.length = " + a.length + ", aoffset = " + aoffset + ", alength = " + alength; + assert (boffset + blength <= b.length) : "b.length = " + b.length + ", boffset = " + boffset + ", blength = " + blength; + assert (ahpla.length == 128); int i = 0; final int al = Math.min(alength, a.length - aoffset); final int bl = Math.min(blength, b.length - boffset); final int len = (al > bl) ? bl : al; + byte ac, bc; + byte acc, bcc; while (i < len) { - if (ahpla[a[i + aoffset]] > ahpla[b[i + boffset]]) return 1; - if (ahpla[a[i + aoffset]] < ahpla[b[i + boffset]]) return -1; + assert (i + aoffset < a.length) : "i = " + i + ", aoffset = " + aoffset + ", a.length = " + a.length + ", a = " + serverLog.arrayList(a, aoffset, len); + assert (i + boffset < b.length) : "i = " + i + ", boffset = " + boffset + ", b.length = " + b.length + ", b = " + serverLog.arrayList(b, boffset, len); + ac = a[aoffset + i]; + assert (ac >= 0) && (ac < 128) : "ac = " + ac + ", a = " + serverLog.arrayList(a, aoffset, len); + bc = b[boffset + i]; + assert (bc >= 0) && (bc < 128) : "bc = " + bc + ", b = " + serverLog.arrayList(b, boffset, len); + acc = ahpla[ac]; + assert (acc >= 0) : "acc = " + acc + ", a = " + serverLog.arrayList(a, aoffset, len); + bcc = ahpla[bc]; + assert (bcc >= 0) : "bcc = " + bcc + ", b = " + serverLog.arrayList(b, boffset, len); + if (acc > bcc) return 1; + if (acc < bcc) return -1; // else the bytes are equal and it may go on yet undecided i++; } diff --git a/source/de/anomic/kelondro/kelondroFlexTable.java b/source/de/anomic/kelondro/kelondroFlexTable.java index 04aa47c61..dba762318 100644 --- a/source/de/anomic/kelondro/kelondroFlexTable.java +++ b/source/de/anomic/kelondro/kelondroFlexTable.java @@ -91,7 +91,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr node = (kelondroRecords.Node) content.next(); i = node.handle().hashCode(); indexentry = ri.row().newEntry(); - indexentry.setCol(0, node.getValueRow()); + indexentry.setCol(0, node.getKey()); indexentry.setCol(1, i); ri.addUnique(indexentry); if ((i % 10000) == 0) { diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.java index 4e4933cbb..88c4f215c 100644 --- a/source/de/anomic/kelondro/kelondroRecords.java +++ b/source/de/anomic/kelondro/kelondroRecords.java @@ -1096,10 +1096,12 @@ public class kelondroRecords { private byte[] bulk; private int bulksize; private int bulkstart; // the offset of the bulk array to the node position + private boolean fullyMarked; public contentNodeIterator(long maxInitTime) throws IOException, kelondroException { // initialize markedDeleted set of deleted Handles markedDeleted = deletedHandles(maxInitTime); + fullyMarked = (maxInitTime < 0); // seek first position according the delete node set pos = new Handle(0); @@ -1116,6 +1118,21 @@ public class kelondroRecords { } public Object next() { + // read Objects until a non-deleted Node appears + while (hasNext()) { + Node nn = next0(); + byte[] key = nn.getKey(); + if ((key == null) || ((key[0] == 0) && (key[1] == 0)) || ((key[2] == 0) && (key[3] == 0))) { + // this is an deleted node; probably not commited with dispose + if (fullyMarked) try {dispose(nn.handle);} catch (IOException e) {} // mark this now as deleted + continue; + } + return nn; + } + return null; + } + + public Node next0() { try { // see if the next record is in the bulk, and if not re-fill the bulk if ((pos.index - bulkstart) >= bulksize) { diff --git a/source/de/anomic/kelondro/kelondroRow.java b/source/de/anomic/kelondro/kelondroRow.java index 030c1df5a..979381957 100644 --- a/source/de/anomic/kelondro/kelondroRow.java +++ b/source/de/anomic/kelondro/kelondroRow.java @@ -264,11 +264,13 @@ public class kelondroRow { private void setCol(int encoding, int offset, int length, byte[] cell) { if (cell == null) { - while (length-- > 0) rowinstance[offset + length] = 0; + while (length-- >= 0) rowinstance[offset + length] = 0; } else { - System.arraycopy(cell, 0, rowinstance, offset, Math.min(cell.length, length)); if (cell.length < length) { - while (length-- > cell.length) rowinstance[offset + length] = 0; + System.arraycopy(cell, 0, rowinstance, offset, cell.length); + while (length-- >= cell.length) rowinstance[offset + length] = 0; + } else { + System.arraycopy(cell, 0, rowinstance, offset, length); } } } diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.java index aa418952e..6a33f6593 100644 --- a/source/de/anomic/kelondro/kelondroRowCollection.java +++ b/source/de/anomic/kelondro/kelondroRowCollection.java @@ -453,10 +453,13 @@ public class kelondroRowCollection { } private final int compare(int i, int j) { - assert (i < chunkcount); - assert (j < chunkcount); + assert (chunkcount * this.rowdef.objectsize() <= chunkcache.length) : "chunkcount = " + chunkcount + ", objsize = " + this.rowdef.objectsize() + ", chunkcache.length = " + chunkcache.length; + assert (i >= 0) && (i < chunkcount) : "i = " + i + ", chunkcount = " + chunkcount; + assert (j >= 0) && (j < chunkcount) : "j = " + j + ", chunkcount = " + chunkcount; if (i == j) return 0; + assert (this.sortColumn == 0) : "this.sortColumn = " + this.sortColumn; int keylength = this.rowdef.width(this.sortColumn); + assert (keylength <= 12) : "keylength = " + keylength; int colstart = this.rowdef.colstart[this.sortColumn]; int c = this.sortOrder.compare( chunkcache, diff --git a/source/de/anomic/server/logging/serverLog.java b/source/de/anomic/server/logging/serverLog.java index 81478127d..8bf535260 100644 --- a/source/de/anomic/server/logging/serverLog.java +++ b/source/de/anomic/server/logging/serverLog.java @@ -217,4 +217,12 @@ public final class serverLog { for (int i = l + n; i > n; n--) sb.insert(0, fillChar); return sb.toString(); } + + public static final String arrayList(byte[] b, int start, int length) { + StringBuffer sb = new StringBuffer(b.length * 4); + sb.append('[').append(Integer.toString((int) b[start])).append(','); + for (int i = 1; i < length; i++) sb.append(' ').append(Integer.toString((int) b[start + i])).append(','); + sb.append(']'); + return sb.toString(); + } } diff --git a/source/yacy.java b/source/yacy.java index 86e06f9c4..f03e18896 100644 --- a/source/yacy.java +++ b/source/yacy.java @@ -1325,6 +1325,12 @@ public final class yacy { */ public static void main(String args[]) { + // check assertion status + //ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); + boolean assertionenabled = false; + assert assertionenabled = true; + if (assertionenabled) System.out.println("Asserts are enabled"); + // check memory amount System.gc(); long startupMemFree = Runtime.getRuntime().freeMemory(); // the amount of free memory in the Java Virtual Machine