Skip to content

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

small speed enhancement using a column factory

Michael Peter Christen6f8a2fef1f0f
diff --git a/source/net/yacy/kelondro/index/Column.java b/source/net/yacy/kelondro/index/Column.java
index 9584a3bf9..0138deef9 100644
--- a/source/net/yacy/kelondro/index/Column.java
+++ b/source/net/yacy/kelondro/index/Column.java
@@ -31,7 +31,7 @@ import java.io.Serializable;
import net.yacy.kelondro.util.kelondroException;
-public final class Column implements Serializable {
+public final class Column implements Cloneable, Serializable {
private static final long serialVersionUID=6558500565023465301L;
@@ -60,7 +60,7 @@ public final class Column implements Serializable {
this.nickname = nickname;
this.description = description;
}
-
+
public Column(String celldef) {
// define column with column syntax
// example: <UDate-3>
@@ -196,6 +196,24 @@ public final class Column implements Serializable {
}
}
+ /**
+ * th clone method is useful to produce a similiar column with a different cell width
+ * @return the cloned Column
+ */
+ public Object clone() {
+ return new Column(this.nickname, this.celltype, this.encoder, this.cellwidth, this.description);
+ }
+
+ /**
+ * a column width may change when the object was not yet used.
+ * this applies to clones of Column objects which are used as Column producers
+ * @param cellwidth
+ */
+ public void setCellwidth(int cellwidth) {
+ assert this.celltype == celltype_string || this.celltype == celltype_binary;
+ this.cellwidth = cellwidth;
+ }
+
@Override
public final String toString() {
final StringBuilder s = new StringBuilder(20);
diff --git a/source/net/yacy/kelondro/index/RowCollection.java b/source/net/yacy/kelondro/index/RowCollection.java
index 8bb208240..c9f792d26 100644
--- a/source/net/yacy/kelondro/index/RowCollection.java
+++ b/source/net/yacy/kelondro/index/RowCollection.java
@@ -169,10 +169,10 @@ public class RowCollection implements Sortable<Row.Entry>, Iterable<Row.Entry>,
return (int) (time / day) - 10957;
}
- private static Column exportColumn0, exportColumn1, exportColumn2, exportColumn3, exportColumn4;
+ private static Column exportColumn0, exportColumn1, exportColumn2, exportColumn3, exportColumn4, collectionColumnProducer;
protected static final long exportOverheadSize = 14;
-
+
private static Row exportRow(final int chunkcachelength) {
/*
return new Row(
@@ -191,15 +191,17 @@ public class RowCollection implements Sortable<Row.Entry>, Iterable<Row.Entry>,
if (exportColumn2 == null) exportColumn2 = new Column("short lastwrote-2 {b256}");
if (exportColumn3 == null) exportColumn3 = new Column("byte[] orderkey-2");
if (exportColumn4 == null) exportColumn4 = new Column("int orderbound-4 {b256}");
+ if (collectionColumnProducer == null) collectionColumnProducer = new Column("byte[] collection-1");
/*
* because of a strange bug these objects cannot be initialized as normal
* static final. If I try that, they are not initialized and are assigned null. why?
*/
- final StringBuilder colName = new StringBuilder(30);
- colName.append("byte[] collection-").append(Integer.toString(chunkcachelength));
+
+ Column collectionColumn = (Column) collectionColumnProducer.clone();
+ collectionColumn.setCellwidth(chunkcachelength);
final Row er = new Row(new Column[]{
exportColumn0, exportColumn1, exportColumn2, exportColumn3, exportColumn4,
- new Column(colName.toString())
+ collectionColumn
},
NaturalOrder.naturalOrder
);