Skip to content

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

tests/fixes

orbiterd083b15c4be3
diff --git a/source/de/anomic/kelondro/kelondroRow.java b/source/de/anomic/kelondro/kelondroRow.java
index fc27990b3..f98741812 100644
--- a/source/de/anomic/kelondro/kelondroRow.java
+++ b/source/de/anomic/kelondro/kelondroRow.java
@@ -141,8 +141,9 @@ public class kelondroRow {
this.rowinstance = rowinstance;
} else {
this.rowinstance = new byte[objectsize];
- System.arraycopy(rowinstance, 0, this.rowinstance, 0, rowinstance.length);
- for (int i = rowinstance.length; i < objectsize; i++) this.rowinstance[i] = 0;
+ int ll = Math.min(objectsize, rowinstance.length);
+ System.arraycopy(rowinstance, 0, this.rowinstance, 0, ll);
+ for (int i = ll; i < objectsize; i++) this.rowinstance[i] = 0;
}
}
diff --git a/source/de/anomic/kelondro/kelondroRowBufferedSet.java b/source/de/anomic/kelondro/kelondroRowBufferedSet.java
index f2d23dc2f..50dc7828c 100644
--- a/source/de/anomic/kelondro/kelondroRowBufferedSet.java
+++ b/source/de/anomic/kelondro/kelondroRowBufferedSet.java
@@ -109,6 +109,14 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
}
}
+ public void add(byte[] a) {
+ this.add(super.rowdef.newEntry(a));
+ }
+
+ public void add(kelondroRow.Entry a) {
+ this.put(a);
+ }
+
public kelondroRow.Entry get(byte[] key) {
synchronized (buffer) {
kelondroRow.Entry entry = (kelondroRow.Entry) buffer.get(key);
@@ -170,8 +178,8 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" };
kelondroRowBufferedSet c = new kelondroRowBufferedSet(new kelondroRow(new int[]{10, 3}));
c.setOrdering(kelondroNaturalOrder.naturalOrder, 0);
- for (int i = 0; i < test.length; i++) c.add(test[i].getBytes(), 0, 10);
- for (int i = 0; i < test.length; i++) c.add(test[i].getBytes(), 0, 10);
+ for (int i = 0; i < test.length; i++) c.add(test[i].getBytes());
+ for (int i = 0; i < test.length; i++) c.add(test[i].getBytes());
c.sort();
c.remove("fuenf".getBytes());
Iterator i = c.elements();
@@ -201,7 +209,7 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
for (long k = 0; k < 60000; k++) {
t = System.currentTimeMillis();
w = "a" + Long.toString(rand.nextLong());
- c.add(w.getBytes(), 0, 10);
+ c.add(w.getBytes());
if (k % 10000 == 0)
System.out.println("added " + k + " entries in " +
((t - start) / 1000) + " seconds, " +
@@ -225,7 +233,7 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
for (long k = 0; k < 60000; k++) {
t = System.currentTimeMillis();
w = "a" + Long.toString(rand.nextLong());
- if (c.get(w.getBytes()) == null) c.add(w.getBytes(), 0, 10); else d++;
+ if (c.get(w.getBytes()) == null) c.add(w.getBytes()); else d++;
if (k % 10000 == 0)
System.out.println("added " + k + " entries in " +
((t - start) / 1000) + " seconds, " +
diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.java
index 411653f28..760fcbd94 100644
--- a/source/de/anomic/kelondro/kelondroRowCollection.java
+++ b/source/de/anomic/kelondro/kelondroRowCollection.java
@@ -108,11 +108,15 @@ public class kelondroRowCollection {
this.lastTimeWrote = System.currentTimeMillis();
}
- public final void add(kelondroRow.Entry a) {
+ public void add(kelondroRow.Entry a) {
add(a.bytes(), 0, a.bytes().length);
}
- public final void add(byte[] a, int astart, int alength) {
+ public void add(byte[] a) {
+ add(a, 0, a.length);
+ }
+
+ private final void add(byte[] a, int astart, int alength) {
int l = Math.min(rowdef.objectsize(), Math.min(alength, a.length - astart));
synchronized (chunkcache) {
ensureSize(chunkcount + 1);
diff --git a/source/de/anomic/kelondro/kelondroRowSet.java b/source/de/anomic/kelondro/kelondroRowSet.java
index 775d5a964..56cf54d2a 100644
--- a/source/de/anomic/kelondro/kelondroRowSet.java
+++ b/source/de/anomic/kelondro/kelondroRowSet.java
@@ -175,8 +175,8 @@ public class kelondroRowSet extends kelondroRowCollection {
String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" };
kelondroRowSet c = new kelondroRowSet(new kelondroRow(new int[]{10, 3}));
c.setOrdering(kelondroNaturalOrder.naturalOrder, 0);
- for (int i = 0; i < test.length; i++) c.add(test[i].getBytes(), 0, 10);
- for (int i = 0; i < test.length; i++) c.add(test[i].getBytes(), 0, 10);
+ for (int i = 0; i < test.length; i++) c.add(test[i].getBytes());
+ for (int i = 0; i < test.length; i++) c.add(test[i].getBytes());
c.sort();
c.remove("fuenf".getBytes(), 0, 5);
Iterator i = c.elements();
@@ -206,7 +206,7 @@ public class kelondroRowSet extends kelondroRowCollection {
for (long k = 0; k < 60000; k++) {
t = System.currentTimeMillis();
w = "a" + Long.toString(rand.nextLong());
- c.add(w.getBytes(), 0, 10);
+ c.add(w.getBytes());
if (k % 10000 == 0)
System.out.println("added " + k + " entries in " +
((t - start) / 1000) + " seconds, " +
@@ -230,7 +230,7 @@ public class kelondroRowSet extends kelondroRowCollection {
for (long k = 0; k < 60000; k++) {
t = System.currentTimeMillis();
w = "a" + Long.toString(rand.nextLong());
- if (c.get(w.getBytes(), 0, 10) == null) c.add(w.getBytes(), 0, 10); else d++;
+ if (c.get(w.getBytes(), 0, 10) == null) c.add(w.getBytes()); else d++;
if (k % 10000 == 0)
System.out.println("added " + k + " entries in " +
((t - start) / 1000) + " seconds, " +