Skip to content

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

update to row/column handling

orbiterd580f582dc45
diff --git a/source/de/anomic/kelondro/kelondroColumn.java b/source/de/anomic/kelondro/kelondroColumn.java
index 0af06d6e9..586919494 100644
--- a/source/de/anomic/kelondro/kelondroColumn.java
+++ b/source/de/anomic/kelondro/kelondroColumn.java
@@ -25,17 +25,16 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
package de.anomic.kelondro;
public class kelondroColumn {
- public static int celltype_undefined = 0;
- public static int celltype_boolean = 1;
- public static int celltype_bytes = 2;
- public static int celltype_string = 3;
- public static int celltype_cardinal = 4;
- public static int celltype_real = 5;
+ public static final int celltype_undefined = 0;
+ public static final int celltype_boolean = 1;
+ public static final int celltype_bytes = 2;
+ public static final int celltype_string = 3;
+ public static final int celltype_cardinal = 4;
+ public static final int celltype_real = 5;
private int celltype, dbwidth;
private String nickname, description;
@@ -62,4 +61,5 @@ public class kelondroColumn {
public String description() {
return this.description;
}
+
}
diff --git a/source/de/anomic/kelondro/kelondroRow.java b/source/de/anomic/kelondro/kelondroRow.java
index 418d54a85..70ef11afe 100644
--- a/source/de/anomic/kelondro/kelondroRow.java
+++ b/source/de/anomic/kelondro/kelondroRow.java
@@ -27,17 +27,31 @@
package de.anomic.kelondro;
+import java.util.HashMap;
+
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 HashMap encodedFormConfiguration;
+ private int encodedFormLength;
public kelondroRow(kelondroColumn[] row) {
this.row = row;
+ this.encodedFormConfiguration = null;
+ this.encodedFormLength = -1;
}
public kelondroRow(int[] row) {
this.row = new kelondroColumn[row.length];
- for (int i = 0; i < row.length; i++) this.row[i] = new kelondroColumn(kelondroColumn.celltype_undefined, row[i], "", "");
+ for (int i = 0; i < row.length; i++) this.row[i] = new kelondroColumn(kelondroColumn.celltype_undefined, row[i], "col_" + i, "");
+ this.encodedFormConfiguration = null;
+ this.encodedFormLength = -1;
}
public int columns() {
@@ -54,4 +68,70 @@ public class kelondroRow {
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 class Entry {
+
+ private byte[][] cols;
+
+ public Entry(byte[][] cols) {
+ this.cols = cols;
+ }
+
+ public byte[] toEncodedBytesForm() {
+ byte[] b = new byte[encodedFormLength];
+ int[] format;
+ int encoder, length;
+ int p = 0;
+ for (int i = 0; i < row.length; i++) {
+ format = (int[]) encodedFormConfiguration.get(row[i].nickname());
+ encoder = format[0];
+ length = format[1];
+ switch (row[i].celltype()) {
+ case kelondroColumn.celltype_undefined:
+ throw new kelondroException("ROW", "toEncodedForm of celltype undefined not possible");
+ case kelondroColumn.celltype_boolean:
+ throw new kelondroException("ROW", "toEncodedForm of celltype boolean not yet implemented");
+ case kelondroColumn.celltype_bytes:
+ System.arraycopy(cols[i], 0, b, p, length);
+ p += length;
+ continue;
+ case kelondroColumn.celltype_string:
+ System.arraycopy(cols[i], 0, b, p, length);
+ p += length;
+ continue;
+ case kelondroColumn.celltype_cardinal:
+ if (encoder == encoder_b64e) {
+ long c = kelondroRecords.bytes2long(cols[i]);
+ System.arraycopy(kelondroBase64Order.enhancedCoder.encodeLongSmart(c, length).getBytes(), 0, b, p, length);
+ p += length;
+ continue;
+ }
+ throw new kelondroException("ROW", "toEncodedForm of celltype cardinal has no encoder (" + encoder + ")");
+ case kelondroColumn.celltype_real:
+ throw new kelondroException("ROW", "toEncodedForm of celltype real not yet implemented");
+ }
+ }
+ return b;
+ }
+ }
}