Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
better assert statements and fixes
orbiter83a0efc65ac8
diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.javaindex d1c09e103..4e4933cbb 100644--- a/source/de/anomic/kelondro/kelondroRecords.java+++ b/source/de/anomic/kelondro/kelondroRecords.java@@ -1066,6 +1066,7 @@ public class kelondroRecords {// move to next handlerepair_position = seekp;h = new Handle(entryFile.readInt(seekp));+ if (h.index == NUL) break;// double-check for already stored handles: detect loopsif (markedDeleted.contains(h)) {@@ -1332,9 +1333,9 @@ public class kelondroRecords {}public int compareTo(Object h) {- // this is needed for a treeMap- assert (index != NUL);- assert (((Handle) h).index != NUL);+ // this is needed for a TreeMap+ assert (index != NUL) : "this.index is NUL in compareTo";+ assert (((Handle) h).index != NUL) : "handle.index is NUL in compareTo";if (index < ((Handle) h).index) return -1;if (index > ((Handle) h).index) return 1;return 0;diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.javaindex c221dbbc9..aa418952e 100644--- a/source/de/anomic/kelondro/kelondroRowCollection.java+++ b/source/de/anomic/kelondro/kelondroRowCollection.java@@ -152,22 +152,22 @@ public class kelondroRowCollection {int needed = chunkcount * rowdef.objectsize();if (chunkcache.length == needed) return;byte[] newChunkcache = new byte[needed];- System.arraycopy(chunkcache, 0, newChunkcache, 0, newChunkcache.length);+ System.arraycopy(chunkcache, 0, newChunkcache, 0, Math.min(chunkcache.length, newChunkcache.length));chunkcache = newChunkcache;newChunkcache = null;}}-+ /*public void implantRows(byte[] b) {assert (b.length % rowdef.objectsize() == 0);synchronized (chunkcache) {chunkcache = b;chunkcount = b.length / rowdef.objectsize();- sortBound = chunkcount;+ sortBound = 0;lastTimeWrote = System.currentTimeMillis();}}-+ */public final long lastRead() {return lastTimeRead;}@@ -177,7 +177,8 @@ public class kelondroRowCollection {}public final kelondroRow.Entry get(int index) {- assert (index < chunkcount);+ assert (index >= 0) : "get: access with index " + index + " is below zero";+ assert (index < chunkcount) : "get: access with index " + index + " is above chunkcount " + chunkcount;byte[] a = new byte[rowdef.objectsize()];synchronized (chunkcache) {System.arraycopy(chunkcache, index * rowdef.objectsize(), a, 0, rowdef.objectsize());@@ -191,7 +192,8 @@ public class kelondroRowCollection {}public final void set(int index, byte[] a, int astart, int alength) {- assert (index < this.chunkcount);+ assert (index >= 0) : "get: access with index " + index + " is below zero";+ assert (index < chunkcount) : "get: access with index " + index + " is above chunkcount " + chunkcount;int l = Math.min(rowdef.objectsize(), Math.min(alength, a.length - astart));synchronized (chunkcache) {System.arraycopy(a, astart, chunkcache, index * rowdef.objectsize(), l);@@ -238,13 +240,13 @@ public class kelondroRowCollection {System.arraycopy(chunkcache, (pos + dist) * rowdef.objectsize(),chunkcache, pos * rowdef.objectsize(),(upBound - pos - dist) * rowdef.objectsize());- if ((pos < sortBound) && (upBound >= sortBound)) sortBound -= dist;}public final void removeShift(int p) {assert ((p >= 0) && (p < chunkcount) && (chunkcount > 0));//System.out.println("REMOVE at pos " + p + ", chunkcount=" + chunkcount + ", sortBound=" + sortBound);synchronized (chunkcache) {+ if (p < sortBound) sortBound--;removeShift(p, 1, chunkcount--);}this.lastTimeWrote = System.currentTimeMillis();@@ -253,10 +255,11 @@ public class kelondroRowCollection {public kelondroRow.Entry removeOne() {synchronized (chunkcache) {if (chunkcount == 0) return null;+ kelondroRow.Entry r = get(chunkcount - 1);if (chunkcount == sortBound) sortBound--;chunkcount--;this.lastTimeWrote = System.currentTimeMillis();- return get(chunkcount);+ return r;}}@@ -294,6 +297,7 @@ public class kelondroRowCollection {public void remove() {p--;System.arraycopy(chunkcache, (p + 1) * rowdef.objectsize(), chunkcache, p * rowdef.objectsize(), (chunkcount - p - 1) * rowdef.objectsize());+ if (chunkcount == sortBound) sortBound--;chunkcount--;}}@@ -336,7 +340,7 @@ public class kelondroRowCollection {private final void qsort(int L, int S, int R) {//System.out.println("QSORT: chunkcache.length=" + chunkcache.length + ", chunksize=" + chunksize + ", L=" + L + ", S=" + S + ", R=" + R);- assert (S <= R);+ assert (S <= R) : "S > R: S = " + S + ", R = " + R;if (L >= R - 1) return;if (S >= R) return;diff --git a/source/de/anomic/kelondro/kelondroRowSet.java b/source/de/anomic/kelondro/kelondroRowSet.javaindex cd6758df4..18fa70b88 100644--- a/source/de/anomic/kelondro/kelondroRowSet.java+++ b/source/de/anomic/kelondro/kelondroRowSet.java@@ -169,9 +169,11 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroIndInteger nxt = (Integer) removeMarker.first();removeMarker.remove(nxt);int idx = nxt.intValue();+ assert (idx < sortBound);int d = 1;while (removeMarker.size() > 0) {nxt = (Integer) removeMarker.first();+ assert (nxt.intValue() < sortBound);removeMarker.remove(nxt);super.removeShift(idx, d, nxt.intValue());idx = nxt.intValue() - d;@@ -179,6 +181,7 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd}super.removeShift(idx, d, chunkcount);chunkcount -= d;+ sortBound -= d; // there are all markers below the sortBoundremoveMarker.clear();}