Skip to content

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

stub for performance enhancements for RowSet (no functional change yet)

orbiterca006c506d88
diff --git a/source/de/anomic/kelondro/index/Row.java b/source/de/anomic/kelondro/index/Row.java
index fd5feae39..493f00adc 100644
--- a/source/de/anomic/kelondro/index/Row.java
+++ b/source/de/anomic/kelondro/index/Row.java
@@ -31,8 +31,10 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.concurrent.ArrayBlockingQueue;
import de.anomic.kelondro.order.AbstractOrder;
import de.anomic.kelondro.order.Base64Order;
@@ -46,11 +48,11 @@ import de.anomic.kelondro.util.Log;
public final class Row {
- protected Column[] row;
- public int[] colstart;
- public ByteOrder objectOrder;
- public int objectsize;
- public int primaryKeyIndex, primaryKeyLength;
+ protected final Column[] row;
+ public final int[] colstart;
+ public final ByteOrder objectOrder;
+ public final int objectsize;
+ public final int primaryKeyIndex, primaryKeyLength;
protected Map<String, Object[]> nickref = null; // a mapping from nicknames to Object[2]{kelondroColumn, Integer(colstart)}
public Row(final Column[] row, final ByteOrder objectOrder, final int primaryKey) {
@@ -59,11 +61,12 @@ public final class Row {
this.row = row;
assert (objectOrder != null);
this.colstart = new int[row.length];
- this.objectsize = 0;
+ int os = 0;
for (int i = 0; i < row.length; i++) {
this.colstart[i] = this.objectsize;
- this.objectsize += this.row[i].cellwidth;
+ os+= this.row[i].cellwidth;
}
+ this.objectsize = os;
this.primaryKeyIndex = primaryKey;
this.primaryKeyLength = (primaryKey < 0) ? this.objectsize : row[primaryKeyIndex].cellwidth;
}
@@ -92,19 +95,13 @@ public final class Row {
// define columns
this.row = new Column[l.size()];
this.colstart = new int[row.length];
- this.objectsize = 0;
+ int os = 0;
for (int i = 0; i < l.size(); i++) {
this.colstart[i] = this.objectsize;
this.row[i] = l.get(i);
- this.objectsize += this.row[i].cellwidth;
+ os += this.row[i].cellwidth;
}
- this.primaryKeyIndex = primaryKey;
- this.primaryKeyLength = (primaryKey < 0) ? this.objectsize : row[primaryKeyIndex].cellwidth;
- }
-
- public final void setOrdering(final ByteOrder objectOrder, final int primaryKey) {
- assert (objectOrder != null);
- this.objectOrder = objectOrder;
+ this.objectsize = os;
this.primaryKeyIndex = primaryKey;
this.primaryKeyLength = (primaryKey < 0) ? this.objectsize : row[primaryKeyIndex].cellwidth;
}
@@ -467,6 +464,24 @@ public final class Row {
}
}
+ public final void addCol(final int column, long c) {
+ int encoder = row[column].encoder;
+ int colstrt = colstart[column];
+ int cellwidth = row[column].cellwidth;
+ long l;
+ switch (encoder) {
+ case Column.encoder_b64e:
+ l = Base64Order.enhancedCoder.decodeLong(rowinstance, offset + colstrt, cellwidth);
+ Base64Order.enhancedCoder.encodeLong(l + c, rowinstance, offset, cellwidth);
+ return;
+ case Column.encoder_b256:
+ l = NaturalOrder.decodeLong(rowinstance, offset + colstrt, cellwidth);
+ NaturalOrder.encodeLong(l + c, rowinstance, offset, cellwidth);
+ return;
+ }
+ throw new kelondroException("ROW", "addCol did not find appropriate encoding");
+ }
+
public final byte[] getCol(final String nickname, final byte[] dflt) {
if (nickref == null) genNickRef();
final Object[] ref = nickref.get(nickname);
@@ -621,6 +636,45 @@ public final class Row {
}
}
+ public final class Queue {
+
+ private final ArrayBlockingQueue<Entry> queue;
+
+ public Queue(int maxsize) {
+ this.queue = new ArrayBlockingQueue<Entry>(maxsize);
+ }
+
+ public void put(Entry e) throws InterruptedException {
+ this.queue.put(e);
+ }
+
+ public Entry take() throws InterruptedException {
+ return this.queue.take();
+ }
+
+ public Entry get(byte[] key) {
+ for (Entry e: this.queue) {
+ if (objectOrder.compare(key, e.getPrimaryKeyBytes()) == 0) {
+ return e;
+ }
+ }
+ return null;
+ }
+
+ public Entry delete(byte[] key) {
+ Iterator<Entry> i = this.queue.iterator();
+ Entry e;
+ while (i.hasNext()) {
+ e = i.next();
+ if (objectOrder.compare(key, e.getPrimaryKeyBytes()) == 0) {
+ i.remove();
+ return e;
+ }
+ }
+ return null;
+ }
+ }
+
public final static void long2bytes(long x, final byte[] b, final int offset, final int length) {
for (int i = length - 1; i >= 0; i--) {
b[offset + i] = (byte) (x & 0XFF);
diff --git a/source/de/anomic/kelondro/index/RowSet.java b/source/de/anomic/kelondro/index/RowSet.java
index 136242810..04de4f1f8 100644
--- a/source/de/anomic/kelondro/index/RowSet.java
+++ b/source/de/anomic/kelondro/index/RowSet.java
@@ -32,7 +32,6 @@ import java.util.List;
import java.util.Random;
import de.anomic.kelondro.order.Base64Order;
-import de.anomic.kelondro.order.ByteOrder;
import de.anomic.kelondro.order.CloneableIterator;
import de.anomic.kelondro.order.NaturalOrder;
@@ -64,16 +63,6 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
super(rowdef, exportedCollectionRowEnvironment);
assert rowdef.objectOrder != null;
}
-
- public void setOrdering(final ByteOrder newOrder, final int newColumn) {
- assert newOrder != null;
- if ((rowdef.objectOrder == null) ||
- (!(rowdef.objectOrder.signature().equals(newOrder.signature()))) ||
- (newColumn != rowdef.primaryKeyIndex)) {
- rowdef.setOrdering(newOrder, newColumn);
- this.sortBound = 0;
- }
- }
public static RowSet importRowSet(final DataInput is, final Row rowdef) throws IOException {
final byte[] byte6 = new byte[6];
@@ -486,7 +475,6 @@ public class RowSet extends RowCollection implements ObjectIndex, Iterable<Row.E
final String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" };
final RowSet d = new RowSet(new Row("byte[] key-10, Cardinal x-4 {b256}", NaturalOrder.naturalOrder, 0), 0);
- d.setOrdering(NaturalOrder.naturalOrder, 0);
for (int ii = 0; ii < test.length; ii++) d.add(test[ii].getBytes());
for (int ii = 0; ii < test.length; ii++) d.add(test[ii].getBytes());
d.sort();