enhancements to kelondroRow and kelondroColumn

these are changes towards a better indexURLEntry implementation
which are needed for the new database structures

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2268 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent ab1ed053f5
commit 85d575e928

@ -37,13 +37,19 @@ import de.anomic.index.indexEntryAttribute;
import de.anomic.index.indexAbstractEntry; import de.anomic.index.indexAbstractEntry;
import de.anomic.index.indexURL; import de.anomic.index.indexURL;
import de.anomic.kelondro.kelondroBase64Order; import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroColumn;
import de.anomic.kelondro.kelondroRow;
import de.anomic.plasma.plasmaWordIndex; import de.anomic.plasma.plasmaWordIndex;
public final class indexURLEntry extends indexAbstractEntry implements Cloneable, indexEntry { public final class indexURLEntry extends indexAbstractEntry implements Cloneable, indexEntry {
// an wordEntry can be filled in either of two ways: public static kelondroRow urlEntryRow = new kelondroRow(new kelondroColumn[]{
// by the discrete values of the entry new kelondroColumn(
// or by the encoded entry-string "nickname",
kelondroColumn.celltype_undefined, 4 /*cellwidth*/,
kelondroColumn.encoder_none, 0,
"description")
});
// the class instantiation can only be done by a plasmaStore method // the class instantiation can only be done by a plasmaStore method
// therefore they are all public // therefore they are all public

@ -36,12 +36,20 @@ public class kelondroColumn {
public static final int celltype_cardinal = 4; public static final int celltype_cardinal = 4;
public static final int celltype_real = 5; public static final int celltype_real = 5;
private int celltype, cellwidth; public static final int encoder_none = 0;
public static final int encoder_b64e = 1;
public static final int encoder_string = 2;
public static final int encoder_bytes = 3;
public static final int encoder_char = 4;
private int celltype, cellwidth, encoder, encodedwidth;
private String nickname, description; private String nickname, description;
public kelondroColumn(int celltype, int cellwidth, String nickname, String description) { public kelondroColumn(String nickname, int celltype, int cellwidth, int encoder, int encodedwidth, String description) {
this.celltype = celltype; this.celltype = celltype;
this.cellwidth = cellwidth; this.cellwidth = cellwidth;
this.encoder = encoder;
this.encodedwidth = encodedwidth;
this.nickname = nickname; this.nickname = nickname;
this.description = description; this.description = description;
} }
@ -54,6 +62,14 @@ public class kelondroColumn {
return this.cellwidth; return this.cellwidth;
} }
public int encoder() {
return this.encoder;
}
public int encodedwidth() {
return this.encodedwidth;
}
public String nickname() { public String nickname() {
return this.nickname; return this.nickname;
} }

@ -28,19 +28,11 @@
package de.anomic.kelondro; package de.anomic.kelondro;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.HashMap;
public class kelondroRow { public class kelondroRow {
public static final int encoder_b64e = 0;
public static final int encoder_string = 1;
public static final int encoder_bytes = 2;
public static final int encoder_char = 3;
private kelondroColumn[] row; private kelondroColumn[] row;
protected int[] colstart; protected int[] colstart;
private HashMap encodedFormConfiguration;
private int encodedFormLength; private int encodedFormLength;
private int objectsize; private int objectsize;
@ -48,25 +40,26 @@ public class kelondroRow {
this.row = row; this.row = row;
this.colstart = new int[row.length]; this.colstart = new int[row.length];
this.objectsize = 0; this.objectsize = 0;
this.encodedFormLength = 0;
for (int i = 0; i < row.length; i++) { for (int i = 0; i < row.length; i++) {
this.colstart[i] = this.objectsize; this.colstart[i] = this.objectsize;
this.objectsize += row[i].cellwidth(); this.objectsize += this.row[i].cellwidth();
this.encodedFormLength += this.row[i].encodedwidth();
} }
this.encodedFormConfiguration = null;
this.encodedFormLength = -1;
} }
public kelondroRow(int[] row) { public kelondroRow(int[] rowi) {
this.row = new kelondroColumn[row.length]; this.row = new kelondroColumn[rowi.length];
this.colstart = new int[row.length]; this.colstart = new int[rowi.length];
this.objectsize = 0; this.objectsize = 0;
for (int i = 0; i < row.length; i++) { this.encodedFormLength = 0;
this.row[i] = new kelondroColumn(kelondroColumn.celltype_undefined, row[i], "col_" + i, ""); for (int i = 0; i < rowi.length; i++) {
this.row[i] = new kelondroColumn("col_" + i, kelondroColumn.celltype_undefined, rowi[i], kelondroColumn.encoder_none, rowi[i], "");
this.colstart[i] = this.objectsize; this.colstart[i] = this.objectsize;
this.objectsize += row[i]; this.objectsize += this.row[i].cellwidth();
this.encodedFormLength += this.row[i].encodedwidth();
} }
this.encodedFormConfiguration = null;
this.encodedFormLength = -1;
} }
public int columns() { public int columns() {
@ -87,27 +80,6 @@ public class kelondroRow {
return w; return w;
} }
private static int encoderCode(String encoderName) {
if (encoderName.equals("b54e")) return encoder_b64e;
if (encoderName.equals("string")) return encoder_string;
if (encoderName.equals("char")) return encoder_char;
return -1;
}
public void configureEncodedForm(String[][] configuration) {
encodedFormConfiguration = new HashMap();
String nick;
int encoder, length;
this.encodedFormLength = 0;
for (int i = 0; i < configuration.length; i++) {
nick = configuration[i][0];
encoder = encoderCode(configuration[i][1]);
length = Integer.parseInt(configuration[i][2]);
encodedFormConfiguration.put(nick, new int[]{encoder, length});
this.encodedFormLength += length;
}
}
public Entry newEntry() { public Entry newEntry() {
return new Entry(); return new Entry();
} }
@ -194,26 +166,6 @@ public class kelondroRow {
kelondroBase64Order.enhancedCoder.encodeLong(cell, rowinstance, colstart[column], row[column].cellwidth()); kelondroBase64Order.enhancedCoder.encodeLong(cell, rowinstance, colstart[column], row[column].cellwidth());
} }
/*
public byte[][] getCols() {
byte[][] values = new byte[row.length][];
int length, offset;
for (int i = 0; i < row.length; i++) {
length = row[i].cellwidth();
offset = colstart[i];
while ((length > 0) && (rowinstance[offset + length - 1] == 0)) length--;
if (length == 0) {
values[i] = null;
} else {
values[i] = new byte[length];
System.arraycopy(rowinstance, offset, values[i], 0, length);
}
}
return values;
}
*/
public String getColString(int column, String encoding) { public String getColString(int column, String encoding) {
int length = row[column].cellwidth(); int length = row[column].cellwidth();
int offset = colstart[column]; int offset = colstart[column];
@ -251,31 +203,29 @@ public class kelondroRow {
public byte[] toEncodedBytesForm() { public byte[] toEncodedBytesForm() {
byte[] b = new byte[encodedFormLength]; byte[] b = new byte[encodedFormLength];
int[] format; int encoder, encodedwidth;
int encoder, length;
int p = 0; int p = 0;
for (int i = 0; i < row.length; i++) { for (int i = 0; i < row.length; i++) {
format = (int[]) encodedFormConfiguration.get(row[i].nickname()); encoder = row[i].encoder();
encoder = format[0]; encodedwidth = row[i].encodedwidth();
length = format[1];
switch (row[i].celltype()) { switch (row[i].celltype()) {
case kelondroColumn.celltype_undefined: case kelondroColumn.celltype_undefined:
throw new kelondroException("ROW", "toEncodedForm of celltype undefined not possible"); throw new kelondroException("ROW", "toEncodedForm of celltype undefined not possible");
case kelondroColumn.celltype_boolean: case kelondroColumn.celltype_boolean:
throw new kelondroException("ROW", "toEncodedForm of celltype boolean not yet implemented"); throw new kelondroException("ROW", "toEncodedForm of celltype boolean not yet implemented");
case kelondroColumn.celltype_binary: case kelondroColumn.celltype_binary:
System.arraycopy(rowinstance, colstart[i], b, p, length); System.arraycopy(rowinstance, colstart[i], b, p, encodedwidth);
p += length; p += encodedwidth;
continue; continue;
case kelondroColumn.celltype_string: case kelondroColumn.celltype_string:
System.arraycopy(rowinstance, colstart[i], b, p, length); System.arraycopy(rowinstance, colstart[i], b, p, encodedwidth);
p += length; p += encodedwidth;
continue; continue;
case kelondroColumn.celltype_cardinal: case kelondroColumn.celltype_cardinal:
if (encoder == encoder_b64e) { if (encoder == kelondroColumn.encoder_b64e) {
long c = bytes2long(rowinstance, colstart[i]); long c = bytes2long(rowinstance, colstart[i]);
System.arraycopy(kelondroBase64Order.enhancedCoder.encodeLongSmart(c, length).getBytes(), 0, b, p, length); System.arraycopy(kelondroBase64Order.enhancedCoder.encodeLongSmart(c, encodedwidth).getBytes(), 0, b, p, encodedwidth);
p += length; p += encodedwidth;
continue; continue;
} }
throw new kelondroException("ROW", "toEncodedForm of celltype cardinal has no encoder (" + encoder + ")"); throw new kelondroException("ROW", "toEncodedForm of celltype cardinal has no encoder (" + encoder + ")");

@ -83,11 +83,11 @@ public class yacyNewsDB {
} }
public static final kelondroRow rowdef = new kelondroRow(new kelondroColumn[]{ public static final kelondroRow rowdef = new kelondroRow(new kelondroColumn[]{
new kelondroColumn(kelondroColumn.celltype_string, yacyNewsRecord.idLength(), "newsid", "id = created + originator"), new kelondroColumn("newsid", kelondroColumn.celltype_string, yacyNewsRecord.idLength(), kelondroColumn.encoder_string, yacyNewsRecord.idLength(), "id = created + originator"),
new kelondroColumn(kelondroColumn.celltype_string, yacyNewsRecord.categoryStringLength, "category", ""), new kelondroColumn("category", kelondroColumn.celltype_string, yacyNewsRecord.categoryStringLength, kelondroColumn.encoder_string, yacyNewsRecord.categoryStringLength, ""),
new kelondroColumn(kelondroColumn.celltype_string, yacyCore.universalDateShortPattern.length(), "received", ""), new kelondroColumn("received", kelondroColumn.celltype_string, yacyCore.universalDateShortPattern.length(), kelondroColumn.encoder_string, yacyCore.universalDateShortPattern.length(), ""),
new kelondroColumn(kelondroColumn.celltype_string, 2, "", ""), new kelondroColumn("", kelondroColumn.celltype_string, 2, kelondroColumn.encoder_string, 2, ""),
new kelondroColumn(kelondroColumn.celltype_string, attributesMaxLength, "", ""), new kelondroColumn("", kelondroColumn.celltype_string, attributesMaxLength, kelondroColumn.encoder_string, attributesMaxLength, ""),
}); });
private static kelondroTree createDB(File path, int bufferkb) { private static kelondroTree createDB(File path, int bufferkb) {
@ -184,18 +184,6 @@ public class yacyNewsDB {
); );
} }
/*
private static yacyNewsRecord b2r(byte[][] b) {
if (b == null) return null;
return new yacyNewsRecord(
new String(b[0]),
new String(b[1]),
(b[2] == null) ? null : yacyCore.parseUniversalDate(new String(b[2]), serverDate.UTCDiffString()),
(int) kelondroBase64Order.enhancedCoder.decodeLong(new String(b[3])),
serverCodings.string2map(new String(b[4]))
);
}
*/
private kelondroRow.Entry r2b(yacyNewsRecord r) { private kelondroRow.Entry r2b(yacyNewsRecord r) {
if (r == null) return null; if (r == null) return null;
String attributes = r.attributes().toString(); String attributes = r.attributes().toString();

@ -77,8 +77,8 @@ public class yacyNewsQueue {
} }
public static final kelondroRow rowdef = new kelondroRow(new kelondroColumn[]{ public static final kelondroRow rowdef = new kelondroRow(new kelondroColumn[]{
new kelondroColumn(kelondroColumn.celltype_string, yacyNewsRecord.idLength(), "newsid", "id = created + originator"), new kelondroColumn("newsid", kelondroColumn.celltype_string, yacyNewsRecord.idLength(), kelondroColumn.encoder_string, yacyNewsRecord.idLength(), "id = created + originator"),
new kelondroColumn(kelondroColumn.celltype_string, yacyCore.universalDateShortPattern.length(), "last touched", "") new kelondroColumn("last touched", kelondroColumn.celltype_string, yacyCore.universalDateShortPattern.length(), kelondroColumn.encoder_string, yacyCore.universalDateShortPattern.length(), "")
}); });
private static kelondroStack createStack(File path) { private static kelondroStack createStack(File path) {

Loading…
Cancel
Save