Skip to content

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

kelondroFlex bugfix

orbiter84dfd76a6aa2
diff --git a/source/dbtest.java b/source/dbtest.java
index 20db3908f..7a0db4a2d 100644
--- a/source/dbtest.java
+++ b/source/dbtest.java
@@ -335,6 +335,8 @@ public class dbtest {
}
long aftercommand = System.currentTimeMillis();
+ // final report
+ System.out.println("Database size = " + table.size() + " unique entries.");
// finally close the database/table
if (table instanceof kelondroTree) ((kelondroTree) table).close();
@@ -414,6 +416,10 @@ final class dbTable implements kelondroIndex {
}
}
+ public int size() {
+ return 0; // *** SQL IMPLEMENTATION NEEDED ***
+ }
+
public kelondroRow row() {
return this.rowdef;
}
diff --git a/source/de/anomic/kelondro/kelondroFixedWidthArray.java b/source/de/anomic/kelondro/kelondroFixedWidthArray.java
index 793bebc16..f00185985 100644
--- a/source/de/anomic/kelondro/kelondroFixedWidthArray.java
+++ b/source/de/anomic/kelondro/kelondroFixedWidthArray.java
@@ -106,12 +106,13 @@ public class kelondroFixedWidthArray extends kelondroRecords implements kelondro
return getHandle(index).hashCode();
}
- public synchronized int add(kelondroRow.Entry rowinstance) throws IOException {
+ public synchronized int add(kelondroRow.Entry rowentry) throws IOException {
+
Node n = newNode();
- n.commit(CP_LOW);
- int index = n.handle().hashCode();
- set(index, rowinstance);
- return index;
+ n.setValueRow(rowentry.bytes());
+ n.commit(CP_NONE);
+
+ return n.handle().hashCode();
}
public synchronized void remove(int index) throws IOException {
@@ -203,7 +204,24 @@ public class kelondroFixedWidthArray extends kelondroRecords implements kelondro
}
public static void main(String[] args) {
- cmd(args);
+ //cmd(args);
+ File f = new File("d:\\\\mc\\privat\\fixtest.db");
+ f.delete();
+ kelondroFixedWidthArray k = new kelondroFixedWidthArray(f, new kelondroRow(new int[]{12, 4}), 6, true);
+ try {
+ k.set(3, k.row().newEntry(new byte[][]{
+ "test123".getBytes(), "abcd".getBytes()}));
+ k.add(k.row().newEntry(new byte[][]{
+ "test456".getBytes(), "efgh".getBytes()}));
+ k.close();
+
+ k = new kelondroFixedWidthArray(f);
+ System.out.println(k.get(2).toString());
+ System.out.println(k.get(3).toString());
+ System.out.println(k.get(4).toString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/source/de/anomic/kelondro/kelondroFlexTable.java b/source/de/anomic/kelondro/kelondroFlexTable.java
index e42450ab6..2eb31bbbe 100644
--- a/source/de/anomic/kelondro/kelondroFlexTable.java
+++ b/source/de/anomic/kelondro/kelondroFlexTable.java
@@ -43,7 +43,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
for (int i = 0; i < indexArray.size(); i++) index.put(indexArray.get(i).getColBytes(0), new Integer(i));
indexArray.close();
*/
- System.out.print("Loading " + path);
+ System.out.print("*** Loading " + path);
Iterator content = super.col[0].contentNodes();
kelondroRecords.Node node;
int i;
@@ -51,11 +51,17 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
node = (kelondroRecords.Node) content.next();
i = node.handle().hashCode();
index.addi(node.getValueRow(), i);
- if ((i % 10000) == 0) System.out.print('.');
+ if ((i % 10000) == 0) {
+ System.out.print('.');
+ System.out.flush();
+ }
}
+ System.out.print(" -ordering- ");
+ System.out.flush();
this.index.setOrdering(kelondroNaturalOrder.naturalOrder, 0);
index.shape();
- System.out.println(index.size() + " index entries initialized and sorted");
+ System.out.println(" -done-");
+ System.out.println(index.size() + " index entries initialized and sorted from " + super.col[0].size() + " keys.");
}
/*
diff --git a/source/de/anomic/kelondro/kelondroFlexWidthArray.java b/source/de/anomic/kelondro/kelondroFlexWidthArray.java
index fb4151af9..713f23c7e 100644
--- a/source/de/anomic/kelondro/kelondroFlexWidthArray.java
+++ b/source/de/anomic/kelondro/kelondroFlexWidthArray.java
@@ -192,4 +192,25 @@ public class kelondroFlexWidthArray implements kelondroArray {
System.out.println("EndOfTable");
}
+
+ public static void main(String[] args) {
+ File f = new File("d:\\\\mc\\privat\\");
+ try {
+ kelondroFlexWidthArray k = new kelondroFlexWidthArray(f, "flextest", new kelondroRow(new int[]{12, 4}), true);
+
+ k.set(3, k.row().newEntry(new byte[][]{
+ "test123".getBytes(), "abcd".getBytes()}));
+ k.add(k.row().newEntry(new byte[][]{
+ "test456".getBytes(), "efgh".getBytes()}));
+ k.close();
+
+ k = new kelondroFlexWidthArray(f, "flextest", new kelondroRow(new int[]{12, 4}), true);
+ System.out.println(k.get(2).toString());
+ System.out.println(k.get(3).toString());
+ System.out.println(k.get(4).toString());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
}
diff --git a/source/de/anomic/kelondro/kelondroIndex.java b/source/de/anomic/kelondro/kelondroIndex.java
index c20bb3b2a..c4aabeef5 100644
--- a/source/de/anomic/kelondro/kelondroIndex.java
+++ b/source/de/anomic/kelondro/kelondroIndex.java
@@ -54,6 +54,8 @@ import java.io.IOException;
public interface kelondroIndex {
+ public int size();
+
public kelondroRow row();
public kelondroRow.Entry get(byte[] key) throws IOException;
diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.java
index d71864253..f7b983f67 100644
--- a/source/de/anomic/kelondro/kelondroRecords.java
+++ b/source/de/anomic/kelondro/kelondroRecords.java
@@ -536,8 +536,8 @@ public class kelondroRecords {
private Handle handle = null; // index of the entry, by default NUL means undefined
private byte[] headChunk = null; // contains ohBytes, ohHandles and the key value
private byte[] tailChunk = null; // contains all values except the key value
- private boolean headChanged = false;
- private boolean tailChanged = false;
+ private boolean headChanged = true;
+ private boolean tailChanged = true;
private Node() throws IOException {
// create a new empty node and reserve empty space in file for it
@@ -548,8 +548,8 @@ public class kelondroRecords {
// create empty chunks
this.headChunk = new byte[headchunksize];
this.tailChunk = new byte[tailchunksize];
- for (int i = 0; i < headchunksize; i++) this.headChunk[i] = 0;
- for (int i = 0; i < tailchunksize; i++) this.tailChunk[i] = 0;
+ for (int i = headchunksize - 1; i >= 0; i--) this.headChunk[i] = 0;
+ for (int i = tailchunksize - 1; i >= 0; i--) this.tailChunk[i] = 0;
}
private Node(Handle handle) throws IOException {
diff --git a/source/de/anomic/kelondro/kelondroRow.java b/source/de/anomic/kelondro/kelondroRow.java
index f98741812..c45cc71fc 100644
--- a/source/de/anomic/kelondro/kelondroRow.java
+++ b/source/de/anomic/kelondro/kelondroRow.java
@@ -285,6 +285,17 @@ public class kelondroRow {
}
return b;
}
+
+ public String toString() {
+ StringBuffer b = new StringBuffer();
+ b.append('{');
+ for (int i = 0; i < columns(); i++) {
+ b.append(getColString(i, null));
+ if (i < columns() - 1) b.append(", ");
+ }
+ b.append('}');
+ return new String(b);
+ }
}
public final static void long2bytes(long x, byte[] b, int offset, int length) {
diff --git a/source/de/anomic/kelondro/kelondroSplittedTree.java b/source/de/anomic/kelondro/kelondroSplittedTree.java
index 2fd41fa0e..16bcd525d 100644
--- a/source/de/anomic/kelondro/kelondroSplittedTree.java
+++ b/source/de/anomic/kelondro/kelondroSplittedTree.java
@@ -132,6 +132,10 @@ public class kelondroSplittedTree implements kelondroIndex {
for (int i = 0; i < ktfs.length; i++) ktfs[i].close();
}
+ public int size() {
+ return ktfs[0].size();
+ }
+
public kelondroRow row() {
return ktfs[0].row();
}