some debugging of new kelondroFlexTable class

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2190 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent f01bd25489
commit 75ed507d39

@ -69,7 +69,9 @@ public class dbtest {
} }
public boolean isValid() { 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))); 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)); System.out.println("ENTRY=" + entryBytes.getColString(1, null));
final STEntry dbEntry = new STEntry(entryBytes.getColBytes(0), entryBytes.getColBytes(1)); final STEntry dbEntry = new STEntry(entryBytes.getColBytes(0), entryBytes.getColBytes(1));
if (!dbEntry.isValid()) { if (!dbEntry.isValid()) {
System.out.println(dbEntry); System.out.println("INVALID: " + dbEntry);
} else { } else {
System.out.println("_VALID_: " + dbEntry);
getTable().remove(entry.getKey()); getTable().remove(entry.getKey());
} }
} }
@ -185,7 +188,7 @@ public class dbtest {
} }
if (dbe.equals("kelondroFlexTable")) { if (dbe.equals("kelondroFlexTable")) {
File tablepath = new File(tablename).getParentFile(); 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")) { if (dbe.equals("mysql")) {
table = new dbTable("mysql", testRow); table = new dbTable("mysql", testRow);

@ -262,11 +262,11 @@ public class kelondroCollection {
//if ((this.chunkcount - this.sortbound) / (this.chunkcount + 1) * 100 > 20) sort(); //if ((this.chunkcount - this.sortbound) / (this.chunkcount + 1) * 100 > 20) sort();
// first try to find in sorted area // first try to find in sorted area
int p = iterativeSearch(a, length); int p = binarySearch(a, length);
if (p >= 0) return p; if (p >= 0) return p;
// then find in unsorted area // then find in unsorted area
return binarySearch(a, length); return iterativeSearch(a, length);
} }

@ -27,6 +27,7 @@ package de.anomic.kelondro;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondroIndex { public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondroIndex {
@ -43,8 +44,13 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
indexArray.close(); indexArray.close();
*/ */
System.out.print("Loading " + path); System.out.print("Loading " + path);
for (int i = 0; i < super.col[0].size(); i++) { Iterator content = super.col[0].contentNodes();
index.addi(super.col[0].get(i).getColBytes(0), i); 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('.'); if ((i % 10000) == 0) System.out.print('.');
} }
index.sort(super.row().width(0)); 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 { public kelondroRow.Entry get(byte[] key) throws IOException {
int i = index.geti(key); int i = index.geti(key);
if (i < 0) return null;
return super.get(i); return super.get(i);
} }

@ -104,21 +104,23 @@ public class kelondroFlexWidthArray implements kelondroArray {
} }
public kelondroRow.Entry set(int index, kelondroRow.Entry rowentry) throws IOException { public kelondroRow.Entry set(int index, kelondroRow.Entry rowentry) throws IOException {
int r = 0; int c = 0;
kelondroRow.Entry e0, e1, p; kelondroRow.Entry e0, e1, p;
p = rowdef.newEntry(); p = rowdef.newEntry();
int lastcol;
synchronized (col) { synchronized (col) {
while (r < rowdef.columns()) { while (c < rowdef.columns()) {
e0 = col[r].row().newEntry( lastcol = c + col[c].row().columns() - 1;
e0 = col[c].row().newEntry(
rowentry.bytes(), rowentry.bytes(),
rowdef.colstart[r], rowdef.colstart[c],
rowdef.colstart[r] rowdef.colstart[lastcol] - rowdef.colstart[c]
- rowdef.colstart[r + col[r].row().columns() - 1] + rowdef.width(lastcol));
+ rowdef.width(r)); e1 = col[c].set(index, e0);
e1 = col[r].set(index, e0); for (int i = 0; i < col[c].row().columns(); i++) {
for (int i = 0; i < col[r].row().columns(); i++) p.setCol(c + i, e1.getColBytes(i));
p.setCol(r + i, e1.getColBytes(i)); }
r = r + col[r].row().columns(); c = c + col[c].row().columns();
} }
} }
return p; return p;

@ -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 { try {
return new contentIterator(); return new contentRowIterator();
} catch (IOException e) { } catch (IOException e) {
return new HashSet().iterator(); return new HashSet().iterator();
} }
} }
public class contentIterator implements Iterator { public class contentRowIterator implements Iterator {
// iterator that iterates all kelondroRow.Entry-objects in the file // iterator that iterates all kelondroRow.Entry-objects in the file
// all records that are marked as deleted are ommitted // 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 // this is probably also the fastest way to iterate all objects
private HashSet markedDeleted; private HashSet markedDeleted;
private Handle pos; private Handle pos;
public contentIterator() throws IOException { public contentNodeIterator() throws IOException {
pos = new Handle(0); pos = new Handle(0);
markedDeleted = new HashSet(); markedDeleted = new HashSet();
synchronized (USAGE) { synchronized (USAGE) {
@ -1158,7 +1196,7 @@ public class kelondroRecords {
Node n = new Node(pos); Node n = new Node(pos);
pos.index++; pos.index++;
while ((markedDeleted.contains(pos)) && (pos.index < USAGE.allCount())) pos.index++; while ((markedDeleted.contains(pos)) && (pos.index < USAGE.allCount())) pos.index++;
return row().newEntry(n.getValueRow()); return n;
} catch (IOException e) { } catch (IOException e) {
throw new kelondroException(filename, e.getMessage()); throw new kelondroException(filename, e.getMessage());
} }

@ -257,7 +257,7 @@ public final class plasmaWordIndexAssortment {
} }
public Iterator content() { public Iterator content() {
return this.assortments.content(); return this.assortments.contentRows();
} }
public int size() { public int size() {

Loading…
Cancel
Save