Skip to content

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

some debugging of new kelondroFlexTable class

orbiter75ed507d3967
diff --git a/source/dbtest.java b/source/dbtest.java
index dc70e71f5..00765d224 100644
--- a/source/dbtest.java
+++ b/source/dbtest.java
@@ -69,7 +69,9 @@ public class dbtest {
}
public boolean isValid() {
- final long source = new Long(new String(this.value).trim()).longValue();
+ String s = new String(this.value).trim();
+ if (s.length() == 0) return false;
+ final long source = new Long(s).longValue();
return new String(this.key).equals(new String(randomHash(source, source)));
}
@@ -138,8 +140,9 @@ public class dbtest {
System.out.println("ENTRY=" + entryBytes.getColString(1, null));
final STEntry dbEntry = new STEntry(entryBytes.getColBytes(0), entryBytes.getColBytes(1));
if (!dbEntry.isValid()) {
- System.out.println(dbEntry);
+ System.out.println("INVALID: " + dbEntry);
} else {
+ System.out.println("_VALID_: " + dbEntry);
getTable().remove(entry.getKey());
}
}
@@ -185,7 +188,7 @@ public class dbtest {
}
if (dbe.equals("kelondroFlexTable")) {
File tablepath = new File(tablename).getParentFile();
- table = new kelondroFlexTable(tablepath, new File(tablename).getName(), new kelondroRow(new int[]{keylength, valuelength, valuelength}), true);
+ table = new kelondroFlexTable(tablepath, new File(tablename).getName(), testRow, true);
}
if (dbe.equals("mysql")) {
table = new dbTable("mysql", testRow);
diff --git a/source/de/anomic/kelondro/kelondroCollection.java b/source/de/anomic/kelondro/kelondroCollection.java
index 40073a617..d15b59d95 100644
--- a/source/de/anomic/kelondro/kelondroCollection.java
+++ b/source/de/anomic/kelondro/kelondroCollection.java
@@ -262,11 +262,11 @@ public class kelondroCollection {
//if ((this.chunkcount - this.sortbound) / (this.chunkcount + 1) * 100 > 20) sort();
// first try to find in sorted area
- int p = iterativeSearch(a, length);
+ int p = binarySearch(a, length);
if (p >= 0) return p;
// then find in unsorted area
- return binarySearch(a, length);
+ return iterativeSearch(a, length);
}
diff --git a/source/de/anomic/kelondro/kelondroFlexTable.java b/source/de/anomic/kelondro/kelondroFlexTable.java
index a47a7154f..d6ba57ae7 100644
--- a/source/de/anomic/kelondro/kelondroFlexTable.java
+++ b/source/de/anomic/kelondro/kelondroFlexTable.java
@@ -27,6 +27,7 @@ package de.anomic.kelondro;
import java.io.File;
import java.io.IOException;
+import java.util.Iterator;
public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondroIndex {
@@ -43,8 +44,13 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
indexArray.close();
*/
System.out.print("Loading " + path);
- for (int i = 0; i < super.col[0].size(); i++) {
- index.addi(super.col[0].get(i).getColBytes(0), i);
+ Iterator content = super.col[0].contentNodes();
+ kelondroRecords.Node node;
+ int i;
+ while (content.hasNext()) {
+ node = (kelondroRecords.Node) content.next();
+ i = node.handle().hashCode();
+ index.addi(node.getValueRow(), i);
if ((i % 10000) == 0) System.out.print('.');
}
index.sort(super.row().width(0));
@@ -69,6 +75,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
public kelondroRow.Entry get(byte[] key) throws IOException {
int i = index.geti(key);
+ if (i < 0) return null;
return super.get(i);
}
diff --git a/source/de/anomic/kelondro/kelondroFlexWidthArray.java b/source/de/anomic/kelondro/kelondroFlexWidthArray.java
index 2b3bbdcba..fbe1568ac 100644
--- a/source/de/anomic/kelondro/kelondroFlexWidthArray.java
+++ b/source/de/anomic/kelondro/kelondroFlexWidthArray.java
@@ -104,21 +104,23 @@ public class kelondroFlexWidthArray implements kelondroArray {
}
public kelondroRow.Entry set(int index, kelondroRow.Entry rowentry) throws IOException {
- int r = 0;
+ int c = 0;
kelondroRow.Entry e0, e1, p;
p = rowdef.newEntry();
+ int lastcol;
synchronized (col) {
- while (r < rowdef.columns()) {
- e0 = col[r].row().newEntry(
+ while (c < rowdef.columns()) {
+ lastcol = c + col[c].row().columns() - 1;
+ e0 = col[c].row().newEntry(
rowentry.bytes(),
- rowdef.colstart[r],
- rowdef.colstart[r]
- - rowdef.colstart[r + col[r].row().columns() - 1]
- + rowdef.width(r));
- e1 = col[r].set(index, e0);
- for (int i = 0; i < col[r].row().columns(); i++)
- p.setCol(r + i, e1.getColBytes(i));
- r = r + col[r].row().columns();
+ rowdef.colstart[c],
+ rowdef.colstart[lastcol] - rowdef.colstart[c]
+ + rowdef.width(lastcol));
+ e1 = col[c].set(index, e0);
+ for (int i = 0; i < col[c].row().columns(); i++) {
+ p.setCol(c + i, e1.getColBytes(i));
+ }
+ c = c + col[c].row().columns();
}
}
return p;
diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.java
index 6fdd4c25c..2fa1aa99b 100644
--- a/source/de/anomic/kelondro/kelondroRecords.java
+++ b/source/de/anomic/kelondro/kelondroRecords.java
@@ -1118,23 +1118,61 @@ public class kelondroRecords {
}
}
- public Iterator content() {
+ public Iterator contentRows() {
+ // returns an iterator of kelondroRow.Entry-objects that are not marked as 'deleted'
try {
- return new contentIterator();
+ return new contentRowIterator();
} catch (IOException e) {
return new HashSet().iterator();
}
}
- public class contentIterator implements Iterator {
+ public class contentRowIterator implements Iterator {
// iterator that iterates all kelondroRow.Entry-objects in the file
// all records that are marked as deleted are ommitted
+
+ private Iterator nodeIterator;
+
+ public contentRowIterator() throws IOException {
+ nodeIterator = contentNodes();
+ }
+
+ public boolean hasNext() {
+ return nodeIterator.hasNext();
+ }
+
+ public Object next() {
+ try {
+ return row().newEntry(((Node) nodeIterator.next()).getValueRow());
+ } catch (IOException e) {
+ throw new kelondroException(filename, e.getMessage());
+ }
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ protected Iterator contentNodes() {
+ // returns an iterator of Node-objects that are not marked as 'deleted'
+ try {
+ return new contentNodeIterator();
+ } catch (IOException e) {
+ return new HashSet().iterator();
+ }
+ }
+
+ protected class contentNodeIterator implements Iterator {
+ // iterator that iterates all Node-objects in the file
+ // all records that are marked as deleted are ommitted
// this is probably also the fastest way to iterate all objects
private HashSet markedDeleted;
private Handle pos;
- public contentIterator() throws IOException {
+ public contentNodeIterator() throws IOException {
pos = new Handle(0);
markedDeleted = new HashSet();
synchronized (USAGE) {
@@ -1158,7 +1196,7 @@ public class kelondroRecords {
Node n = new Node(pos);
pos.index++;
while ((markedDeleted.contains(pos)) && (pos.index < USAGE.allCount())) pos.index++;
- return row().newEntry(n.getValueRow());
+ return n;
} catch (IOException e) {
throw new kelondroException(filename, e.getMessage());
}
diff --git a/source/de/anomic/plasma/plasmaWordIndexAssortment.java b/source/de/anomic/plasma/plasmaWordIndexAssortment.java
index eddd95af7..a728016c4 100644
--- a/source/de/anomic/plasma/plasmaWordIndexAssortment.java
+++ b/source/de/anomic/plasma/plasmaWordIndexAssortment.java
@@ -257,7 +257,7 @@ public final class plasmaWordIndexAssortment {
}
public Iterator content() {
- return this.assortments.content();
+ return this.assortments.contentRows();
}
public int size() {