Skip to content

Commit

Permalink
fix for last commit and more testing stub
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5697 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Mar 11, 2009
1 parent ca006c5 commit 84e3738
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
15 changes: 6 additions & 9 deletions source/de/anomic/kelondro/index/Column.java
Expand Up @@ -43,8 +43,11 @@ public class Column {
public static final int encoder_b256 = 2;
public static final int encoder_bytes = 3;

public int celltype, cellwidth, encoder;
public String nickname, description;
public int cellwidth;
public final String nickname;
protected final int celltype;
protected final int encoder;
protected final String description;

public Column(final String nickname, final int celltype, final int encoder, final int cellwidth, final String description) {
this.celltype = celltype;
Expand Down Expand Up @@ -169,7 +172,7 @@ public Column(String celldef) {
else if (this.celltype == celltype_boolean) this.encoder = encoder_bytes;
else if (this.celltype == celltype_binary) this.encoder = encoder_bytes;
else if (this.celltype == celltype_string) this.encoder = encoder_bytes;
else if (this.celltype == celltype_cardinal) throw new kelondroException("kelondroColumn - encoder missing for cell " + this.nickname);
else throw new kelondroException("kelondroColumn - encoder missing for cell " + this.nickname);
}
} else {
if (this.celltype == celltype_cardinal) throw new kelondroException("kelondroColumn - encoder missing for cell " + this.nickname);
Expand All @@ -188,12 +191,6 @@ public Column(String celldef) {
}
}

public void setAttributes(final String nickname, final int celltype, final int encoder) {
this.celltype = celltype;
this.encoder = encoder;
this.nickname = nickname;
}

public String toString() {
final StringBuilder s = new StringBuilder();
switch (celltype) {
Expand Down
18 changes: 18 additions & 0 deletions source/de/anomic/kelondro/index/IntegerHandleIndex.java
Expand Up @@ -34,6 +34,7 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
Expand All @@ -42,8 +43,10 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import de.anomic.kelondro.order.Base64Order;
import de.anomic.kelondro.order.ByteOrder;
import de.anomic.kelondro.order.CloneableIterator;
import de.anomic.yacy.dht.FlatWordPartitionScheme;

public class IntegerHandleIndex {

Expand Down Expand Up @@ -314,4 +317,19 @@ public IntegerHandleIndex call() throws IOException {
}

}

public static void main(String[] args) {
int count = (args.length == 0) ? 100000 : Integer.parseInt(args[0]);
IntegerHandleIndex idx = new IntegerHandleIndex(12, Base64Order.enhancedCoder, 100000);
Random r = new Random(0);
long start = System.currentTimeMillis();
try {
for (int i = 0; i < count; i++) {
idx.inc(FlatWordPartitionScheme.positionToHash(r.nextInt(count / 32)).getBytes());
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Result: " + (((long) count) * 1000L / (System.currentTimeMillis() - start)) + " inc per second; " + count + " loops.");
}
}
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/index/Row.java
Expand Up @@ -63,7 +63,7 @@ public Row(final Column[] row, final ByteOrder objectOrder, final int primaryKey
this.colstart = new int[row.length];
int os = 0;
for (int i = 0; i < row.length; i++) {
this.colstart[i] = this.objectsize;
this.colstart[i] = os;
os+= this.row[i].cellwidth;
}
this.objectsize = os;
Expand Down Expand Up @@ -97,7 +97,7 @@ public Row(String structure, final ByteOrder objectOrder, final int primaryKey)
this.colstart = new int[row.length];
int os = 0;
for (int i = 0; i < l.size(); i++) {
this.colstart[i] = this.objectsize;
this.colstart[i] = os;
this.row[i] = l.get(i);
os += this.row[i].cellwidth;
}
Expand Down
10 changes: 5 additions & 5 deletions source/de/anomic/kelondro/table/FlexTable.java
Expand Up @@ -73,7 +73,7 @@ public FlexTable(final File path, final String tablename, final Row rowdef, int
}
minimumSpace = Math.max(minimumSpace, super.size());
try {
final long neededRAM = 10 * 1024 * 104 + (long) ((super.row().column(0).cellwidth + 4) * minimumSpace * RowCollection.growfactor);
final long neededRAM = 10 * 1024 * 104 + (long) ((super.row().primaryKeyLength + 4) * minimumSpace * RowCollection.growfactor);

final File newpath = new File(path, tablename);
final File indexfile = new File(newpath, "col.000.index");
Expand Down Expand Up @@ -112,7 +112,7 @@ public FlexTable(final File path, final String tablename, final Row rowdef, int
} catch (final IOException e) {
if (resetOnFail) {
RAMIndex = true;
index = new IntegerHandleIndex(super.row().column(0).cellwidth, super.rowdef.objectOrder, 0);
index = new IntegerHandleIndex(super.row().primaryKeyLength, super.rowdef.objectOrder, 0);
} else {
throw new kelondroException(e.getMessage());
}
Expand All @@ -122,15 +122,15 @@ public FlexTable(final File path, final String tablename, final Row rowdef, int
public void clear() throws IOException {
super.reset();
RAMIndex = true;
index = new IntegerHandleIndex(super.row().column(0).cellwidth, super.rowdef.objectOrder, 0);
index = new IntegerHandleIndex(super.row().primaryKeyLength, super.rowdef.objectOrder, 0);
}

public static int staticSize(final File path, final String tablename) {
return FlexWidthArray.staticsize(path, tablename);
}

public static int staticRAMIndexNeed(final File path, final String tablename, final Row rowdef) {
return (int) ((rowdef.column(0).cellwidth + 4) * staticSize(path, tablename) * RowCollection.growfactor);
return (int) ((rowdef.primaryKeyLength + 4) * staticSize(path, tablename) * RowCollection.growfactor);
}

public boolean hasRAMIndex() {
Expand All @@ -148,7 +148,7 @@ public synchronized boolean has(final byte[] key) {
private IntegerHandleIndex initializeRamIndex(final int initialSpace) {
final int space = Math.max(super.col[0].size(), initialSpace) + 1;
if (space < 0) throw new kelondroException("wrong space: " + space);
final IntegerHandleIndex ri = new IntegerHandleIndex(super.row().column(0).cellwidth, super.rowdef.objectOrder, space);
final IntegerHandleIndex ri = new IntegerHandleIndex(super.row().primaryKeyLength, super.rowdef.objectOrder, space);
final Iterator<Node> content = super.col[0].contentNodes(-1);
Node node;
int i;
Expand Down

0 comments on commit 84e3738

Please sign in to comment.