From bb8e3f8523198c1feb336b82595bd05e6ac14f5f Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 14 Jul 2011 21:42:30 +0000 Subject: [PATCH] code cleanup git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7839 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/net/yacy/kelondro/index/Row.java | 366 +++++++------- .../yacy/kelondro/index/RowCollection.java | 470 +++++++++--------- 2 files changed, 418 insertions(+), 418 deletions(-) diff --git a/source/net/yacy/kelondro/index/Row.java b/source/net/yacy/kelondro/index/Row.java index 017c86cc9..898507300 100644 --- a/source/net/yacy/kelondro/index/Row.java +++ b/source/net/yacy/kelondro/index/Row.java @@ -10,7 +10,7 @@ // $LastChangedBy$ // // LICENSE -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or @@ -51,14 +51,14 @@ import net.yacy.kelondro.util.kelondroException; public final class Row { private final static Pattern commaPattern = Pattern.compile(","); - + protected final Column[] row; public final int[] colstart; public final ByteOrder objectOrder; public final int objectsize; public final int primaryKeyLength; protected Map nickref = null; // a mapping from nicknames to Object[2]{kelondroColumn, Integer(colstart)} - + public Row(final Column[] row, final ByteOrder objectOrder) { assert objectOrder != null; this.objectOrder = objectOrder; @@ -84,7 +84,7 @@ public final class Row { // parse pivot definition: //does not work with 'String idx-26 "id = created + originator",String cat-8,String rec-14,short dis-2 {b64e},String att-462' //structure = structure.replace('=', ','); - + // parse property part definition: int p = structure.indexOf('|'); if (p < 0) p = structure.length(); @@ -94,10 +94,10 @@ public final class Row { while (st.hasMoreTokens()) { l.add(new Column(st.nextToken())); } - + // define columns this.row = new Column[l.size()]; - this.colstart = new int[row.length]; + this.colstart = new int[this.row.length]; int os = 0; for (int i = 0; i < l.size(); i++) { this.colstart[i] = os; @@ -107,50 +107,50 @@ public final class Row { this.objectsize = os; this.primaryKeyLength = this.row[0].cellwidth; } - + public final ByteOrder getOrdering() { return this.objectOrder; } - + protected final void genNickRef() { - if (nickref != null) return; - nickref = new ConcurrentHashMap(row.length); - for (int i = 0; i < row.length; i++) nickref.put(row[i].nickname, new Object[]{row[i], Integer.valueOf(colstart[i])}); + if (this.nickref != null) return; + this.nickref = new ConcurrentHashMap(this.row.length); + for (int i = 0; i < this.row.length; i++) this.nickref.put(this.row[i].nickname, new Object[]{this.row[i], Integer.valueOf(this.colstart[i])}); } - + public final int columns() { return this.row.length; } - + public final Column column(final int col) { - return row[col]; + return this.row[col]; } - + public final int width(final int column) { return this.row[column].cellwidth; } - + public final int[] widths() { final int[] w = new int[this.row.length]; - for (int i = 0; i < this.row.length; i++) w[i] = row[i].cellwidth; + for (int i = 0; i < this.row.length; i++) w[i] = this.row[i].cellwidth; return w; } - + @Override public final String toString() { final StringBuilder s = new StringBuilder(80); - s.append(row[0].toString()); - for (int i = 1; i < row.length; i++) { + s.append(this.row[0].toString()); + for (int i = 1; i < this.row.length; i++) { s.append(", "); - s.append(row[i].toString()); + s.append(this.row[i].toString()); } return s.toString(); } - + public final Entry newEntry() { return new Entry(); } - + public final Entry newEntry(final byte[] rowinstance) { if (rowinstance == null) return null; //assert (rowinstance[0] != 0); @@ -160,14 +160,14 @@ public final class Row { } return new Entry(rowinstance, false); } - + public final Entry newEntry(final Entry oldrow, final int fromColumn) { if (oldrow == null) return null; assert (oldrow.getColBytes(0, false)[0] != 0); assert (this.objectOrder.wellformed(oldrow.getPrimaryKeyBytes(), 0, this.primaryKeyLength)); return new Entry(oldrow, fromColumn, false); } - + public final Entry newEntry(final byte[] rowinstance, final int start, final boolean clone) { if (rowinstance == null) return null; //assert (rowinstance[0] != 0); @@ -177,118 +177,118 @@ public final class Row { // the reference to the byte array does not contain the original content return new Entry(rowinstance, start, clone); } - + public final Entry newEntry(final byte[][] cells) { if (cells == null) return null; assert (cells[0][0] != 0); assert (this.objectOrder.wellformed(cells[0], 0, this.primaryKeyLength)); return new Entry(cells); } - + public final Entry newEntry(final String external, final boolean decimalCardinal) { if (external == null) return null; return new Entry(external, decimalCardinal); } - + public final EntryIndex newEntryIndex(final byte[] rowinstance, final int index) { if (rowinstance == null) return null; assert (rowinstance[0] != 0); assert (this.objectOrder.wellformed(rowinstance, 0, this.primaryKeyLength)); return new EntryIndex(rowinstance, index); } - + public static class EntryComparator extends AbstractOrder implements Order, Comparator, Cloneable { ByteOrder base; public EntryComparator(final ByteOrder baseOrder) { this.base = baseOrder; } - + public int compare(final Entry a, final Entry b) { return a.compareTo(b); } - + public boolean equal(final Entry a, final Entry b) { return a.equals(b); } public Order clone() { - return new EntryComparator(base); + return new EntryComparator(this.base); } public long cardinal(final Entry key) { - return base.cardinal(key.bytes(), 0, key.getPrimaryKeyLength()); + return this.base.cardinal(key.bytes(), 0, key.getPrimaryKeyLength()); } public String signature() { - return base.signature(); + return this.base.signature(); } public boolean wellformed(final Entry a) { - return base.wellformed(a.getPrimaryKeyBytes()); + return this.base.wellformed(a.getPrimaryKeyBytes()); } } - + public class Entry implements Comparable, Comparator { private byte[] rowinstance; private int offset; // the offset where the row starts within rowinstance - + public Entry() { - rowinstance = new byte[objectsize]; + this.rowinstance = new byte[Row.this.objectsize]; //for (int i = 0; i < objectsize; i++) this.rowinstance[i] = 0; - offset = 0; + this.offset = 0; } - + public Entry(final byte[] newrow, final boolean forceclone) { this(newrow, 0, forceclone); } - + public Entry(final Entry oldrow, final int fromColumn, final boolean forceclone) { this(oldrow.rowinstance, oldrow.offset + oldrow.colstart(fromColumn), forceclone); } - + public Entry(final byte[] newrow, final int start, final boolean forceclone) { - if ((!forceclone) && (newrow.length - start >= objectsize)) { + if (forceclone || newrow.length - start < Row.this.objectsize) { + this.rowinstance = new byte[Row.this.objectsize]; + System.arraycopy(newrow, start, this.rowinstance, 0, Row.this.objectsize); + this.offset = 0; + } else { this.rowinstance = newrow; this.offset = start; - } else { - this.rowinstance = new byte[objectsize]; - System.arraycopy(newrow, start, this.rowinstance, 0, objectsize); - this.offset = 0; } //for (int i = ll; i < objectsize; i++) this.rowinstance[i] = 0; } - + public Entry(final byte[][] cols) { - assert row.length == cols.length : "cols.length = " + cols.length + ", row.length = " + row.length; - this.rowinstance = new byte[objectsize]; + assert Row.this.row.length == cols.length : "cols.length = " + cols.length + ", row.length = " + Row.this.row.length; + this.rowinstance = new byte[Row.this.objectsize]; this.offset = 0; int ll; int cs, cw; - for (int i = 0; i < row.length; i++) { - cs = colstart[i]; - cw = row[i].cellwidth; + for (int i = 0; i < Row.this.row.length; i++) { + cs = Row.this.colstart[i]; + cw = Row.this.row[i].cellwidth; if ((i >= cols.length) || (cols[i] == null)) { for (int j = 0; j < cw; j++) this.rowinstance[cs + j] = 0; } else { //assert cols[i].length <= cw : "i = " + i + ", cols[i].length = " + cols[i].length + ", cw = " + cw; ll = Math.min(cols[i].length, cw); - System.arraycopy(cols[i], 0, rowinstance, cs, ll); + System.arraycopy(cols[i], 0, this.rowinstance, cs, ll); for (int j = ll; j < cw; j++) this.rowinstance[cs + j] = 0; } } } - + public Entry(String external, final boolean decimalCardinal) { // parse external form if (external.length() > 0 && external.charAt(0) == '{') external = external.substring(1, external.length() - 1); final String[] elts = commaPattern.split(external); - if (nickref == null) genNickRef(); + if (Row.this.nickref == null) genNickRef(); String nick; int p; - this.rowinstance = new byte[objectsize]; + this.rowinstance = new byte[Row.this.objectsize]; this.offset = 0; for (int i = 0; i < elts.length; i++) { p = elts[i].indexOf('='); @@ -296,18 +296,18 @@ public final class Row { if (p > 0) { nick = elts[i].substring(0, p).trim(); if (nick.charAt(0) == '"' && nick.charAt(nick.length() - 1) == '"') nick = nick.substring(1, nick.length() - 1); - final Object[] ref = nickref.get(nick); - Column col = (Column) ref[0]; - int clstrt = ((Integer) ref[1]).intValue(); + final Object[] ref = Row.this.nickref.get(nick); + final Column col = (Column) ref[0]; + final int clstrt = ((Integer) ref[1]).intValue(); if (p + 1 == elts[i].length()) { setCol(clstrt, col.cellwidth, null); } else { if ((decimalCardinal) && (col.celltype == Column.celltype_cardinal)) { try { - setCol(col.encoder, offset + clstrt, col.cellwidth, Long.parseLong(elts[i].substring(p + 1).trim())); + setCol(col.encoder, this.offset + clstrt, col.cellwidth, Long.parseLong(elts[i].substring(p + 1).trim())); } catch (final NumberFormatException e) { Log.logSevere("kelondroRow", "NumberFormatException for celltype_cardinal; row = " + i + ", celltype = " + col.celltype + ", encoder = " + col.encoder + ", value = '" + elts[i].substring(p + 1).trim() + "'"); - setCol(col.encoder, offset + clstrt, col.cellwidth, 0); + setCol(col.encoder, this.offset + clstrt, col.cellwidth, 0); } } else if ((decimalCardinal) && (col.celltype == Column.celltype_binary)) { assert col.cellwidth == 1; @@ -328,20 +328,20 @@ public final class Row { } protected final int colstart(final int column) { - return colstart[column]; + return Row.this.colstart[column]; } - + protected final int cellwidth(final int column) { - return row[column].cellwidth; + return Row.this.row[column].cellwidth; } - + public final int compareTo(final Entry o) { // compares only the content of the primary key - if (objectOrder == null) throw new kelondroException("objects cannot be compared, no order given"); - assert primaryKeyLength == o.getPrimaryKeyLength(); - return objectOrder.compare(this.bytes(), 0, o.bytes(), 0, primaryKeyLength); + if (Row.this.objectOrder == null) throw new kelondroException("objects cannot be compared, no order given"); + assert Row.this.primaryKeyLength == o.getPrimaryKeyLength(); + return Row.this.objectOrder.compare(bytes(), 0, o.bytes(), 0, Row.this.primaryKeyLength); } - + public int compare(final Entry o1, final Entry o2) { return o1.compareTo(o2); } @@ -353,17 +353,17 @@ public final class Row { if (obj == null) return false; if (!(obj instanceof Entry)) return false; final Entry other = (Entry) obj; - final byte[] t = this.bytes(); + final byte[] t = bytes(); final byte[] o = other.bytes(); - for (int i = 0; i < primaryKeyLength; i++) { + for (int i = 0; i < Row.this.primaryKeyLength; i++) { if (t[i] != o[i]) return false; } return true; } - + @Override public int hashCode() { - final byte[] b = this.getPrimaryKeyBytes(); + final byte[] b = getPrimaryKeyBytes(); final int len = b.length; int h = 1; for (int i = 0; i < len; i++) { @@ -371,198 +371,198 @@ public final class Row { } return h; } - + public final byte[] bytes() { - if ((offset == 0) && (rowinstance.length == objectsize)) { - return rowinstance; + if ((this.offset == 0) && (this.rowinstance.length == Row.this.objectsize)) { + return this.rowinstance; } - final byte[] tmp = new byte[objectsize]; - System.arraycopy(rowinstance, offset, tmp, 0, objectsize); + final byte[] tmp = new byte[Row.this.objectsize]; + System.arraycopy(this.rowinstance, this.offset, tmp, 0, Row.this.objectsize); return tmp; } - + public final void writeToArray(final byte[] target, final int targetOffset) { // this method shall replace the byte()s where possible, bacause it may reduce the number of new byte[] allocations - assert (targetOffset + objectsize <= target.length) : "targetOffset = " + targetOffset + ", target.length = " + target.length + ", objectsize = " + objectsize; - System.arraycopy(rowinstance, offset, target, targetOffset, objectsize); + assert (targetOffset + Row.this.objectsize <= target.length) : "targetOffset = " + targetOffset + ", target.length = " + target.length + ", objectsize = " + Row.this.objectsize; + System.arraycopy(this.rowinstance, this.offset, target, targetOffset, Row.this.objectsize); } - + public final int columns() { - return row.length; + return Row.this.row.length; } - + public final int objectsize() { - return objectsize; + return Row.this.objectsize; } - + public final boolean empty(final int column) { - return rowinstance[offset + colstart[column]] == 0; + return this.rowinstance[this.offset + Row.this.colstart[column]] == 0; } - + public final void setCol(final int column, final byte[] cell) { - setCol(colstart[column], row[column].cellwidth, cell); + setCol(Row.this.colstart[column], Row.this.row[column].cellwidth, cell); } - + public final void setCol(final int column, final char[] cell) { - final int clstrt = colstart[column]; - for (int i = 0; i < cell.length; i++) rowinstance[offset + clstrt + i] = (byte) cell[i]; - for (int i = cell.length; i < row[column].cellwidth; i++) rowinstance[offset + clstrt + i] = 0; + final int clstrt = Row.this.colstart[column]; + for (int i = 0; i < cell.length; i++) this.rowinstance[this.offset + clstrt + i] = (byte) cell[i]; + for (int i = cell.length; i < Row.this.row[column].cellwidth; i++) this.rowinstance[this.offset + clstrt + i] = 0; } - + private final void setCol(final int clstrt, int length, final byte[] cell) { if (cell == null) { - while (length-- > 0) rowinstance[offset + clstrt + length] = 0; + while (length-- > 0) this.rowinstance[this.offset + clstrt + length] = 0; } else { if (cell.length < length) { - System.arraycopy(cell, 0, rowinstance, offset + clstrt, cell.length); - while (length-- > cell.length) rowinstance[offset + clstrt + length] = 0; + System.arraycopy(cell, 0, this.rowinstance, this.offset + clstrt, cell.length); + while (length-- > cell.length) this.rowinstance[this.offset + clstrt + length] = 0; } else { //assert cell.length == length; - System.arraycopy(cell, 0, rowinstance, offset + clstrt, length); + System.arraycopy(cell, 0, this.rowinstance, this.offset + clstrt, length); } } } - + public final void setCol(final int column, final byte c) { - rowinstance[offset + colstart[column]] = c; + this.rowinstance[this.offset + Row.this.colstart[column]] = c; } - + public final void setCol(final int column, final String cell) { setCol(column, UTF8.getBytes(cell)); } - + public final void setCol(final int column, final long cell) { // uses the column definition to choose the right encoding - setCol(row[column].encoder, offset + colstart[column], row[column].cellwidth, cell); + setCol(Row.this.row[column].encoder, this.offset + Row.this.colstart[column], Row.this.row[column].cellwidth, cell); } - + private final void setCol(final int encoder, final int offset, final int length, final long cell) { switch (encoder) { case Column.encoder_none: throw new kelondroException("ROW", "setColLong has celltype none, no encoder given"); case Column.encoder_b64e: - Base64Order.enhancedCoder.encodeLong(cell, rowinstance, offset, length); + Base64Order.enhancedCoder.encodeLong(cell, this.rowinstance, offset, length); break; case Column.encoder_b256: - NaturalOrder.encodeLong(cell, rowinstance, offset, length); + NaturalOrder.encodeLong(cell, this.rowinstance, offset, length); break; case Column.encoder_bytes: throw new kelondroException("ROW", "setColLong of celltype bytes not applicable"); } } - + public final long incCol(final int column, final long c) { - final int encoder = row[column].encoder; - final int colstrt = colstart[column]; - final int cellwidth = row[column].cellwidth; + final int encoder = Row.this.row[column].encoder; + final int colstrt = Row.this.colstart[column]; + final int cellwidth = Row.this.row[column].cellwidth; long l; switch (encoder) { case Column.encoder_b64e: - l = c + Base64Order.enhancedCoder.decodeLong(rowinstance, offset + colstrt, cellwidth); - Base64Order.enhancedCoder.encodeLong(l, rowinstance, offset + colstrt, cellwidth); + l = c + Base64Order.enhancedCoder.decodeLong(this.rowinstance, this.offset + colstrt, cellwidth); + Base64Order.enhancedCoder.encodeLong(l, this.rowinstance, this.offset + colstrt, cellwidth); return l; case Column.encoder_b256: - l = c + NaturalOrder.decodeLong(rowinstance, offset + colstrt, cellwidth); - NaturalOrder.encodeLong(l, rowinstance, offset + colstrt, cellwidth); + l = c + NaturalOrder.decodeLong(this.rowinstance, this.offset + colstrt, cellwidth); + NaturalOrder.encodeLong(l, this.rowinstance, this.offset + colstrt, cellwidth); return l; } throw new kelondroException("ROW", "addCol did not find appropriate encoding"); } - + public final String getColString(final int column) { - final int clstrt = colstart[column]; - int length = row[column].cellwidth; - if (rowinstance[offset + clstrt] == 0) return null; - assert length <= rowinstance.length - offset - clstrt; - if (length > rowinstance.length - offset - clstrt) length = rowinstance.length - offset - clstrt; - while ((length > 0) && (rowinstance[offset + clstrt + length - 1] == 0)) length--; + final int clstrt = Row.this.colstart[column]; + int length = Row.this.row[column].cellwidth; + if (this.rowinstance[this.offset + clstrt] == 0) return null; + assert length <= this.rowinstance.length - this.offset - clstrt; + if (length > this.rowinstance.length - this.offset - clstrt) length = this.rowinstance.length - this.offset - clstrt; + while ((length > 0) && (this.rowinstance[this.offset + clstrt + length - 1] == 0)) length--; if (length == 0) return null; - return UTF8.String(rowinstance, offset + clstrt, length); + return UTF8.String(this.rowinstance, this.offset + clstrt, length); } - + public final long getColLong(final int column) { // uses the column definition to choose the right encoding - return getColLong(row[column].encoder, colstart[column], row[column].cellwidth); + return getColLong(Row.this.row[column].encoder, Row.this.colstart[column], Row.this.row[column].cellwidth); } - + protected final long getColLong(final int encoder, final int clstrt, final int length) { switch (encoder) { case Column.encoder_none: throw new kelondroException("ROW", "getColLong has celltype none, no encoder given"); case Column.encoder_b64e: // start - fix for badly stored parameters - if ((length >= 3) && (rowinstance[offset + clstrt] == '[') && (rowinstance[offset + clstrt + 1] == 'B') && (rowinstance[offset + clstrt + 2] == '@')) return 0; - if ((length == 2) && (rowinstance[offset + clstrt] == '[') && (rowinstance[offset + clstrt + 1] == 'B')) return 0; - if ((length == 1) && (rowinstance[offset + clstrt] == '[')) return 0; + if ((length >= 3) && (this.rowinstance[this.offset + clstrt] == '[') && (this.rowinstance[this.offset + clstrt + 1] == 'B') && (this.rowinstance[this.offset + clstrt + 2] == '@')) return 0; + if ((length == 2) && (this.rowinstance[this.offset + clstrt] == '[') && (this.rowinstance[this.offset + clstrt + 1] == 'B')) return 0; + if ((length == 1) && (this.rowinstance[this.offset + clstrt] == '[')) return 0; boolean maxvalue = true; - for (int i = 0; i < length; i++) if (rowinstance[offset + clstrt + i] != '_') {maxvalue = false; break;} + for (int i = 0; i < length; i++) if (this.rowinstance[this.offset + clstrt + i] != '_') {maxvalue = false; break;} if (maxvalue) return 0; // stop - fix for badly stored parameters - return Base64Order.enhancedCoder.decodeLong(rowinstance, offset + clstrt, length); + return Base64Order.enhancedCoder.decodeLong(this.rowinstance, this.offset + clstrt, length); case Column.encoder_b256: - return NaturalOrder.decodeLong(rowinstance, offset + clstrt, length); + return NaturalOrder.decodeLong(this.rowinstance, this.offset + clstrt, length); case Column.encoder_bytes: throw new kelondroException("ROW", "getColLong of celltype bytes not applicable"); } throw new kelondroException("ROW", "getColLong did not find appropriate encoding"); } - + public final byte getColByte(final int column) { - return rowinstance[offset + colstart[column]]; + return this.rowinstance[this.offset + Row.this.colstart[column]]; } - + public final byte[] getPrimaryKeyBytes() { - final byte[] c = new byte[primaryKeyLength]; - System.arraycopy(rowinstance, offset, c, 0, primaryKeyLength); + final byte[] c = new byte[Row.this.primaryKeyLength]; + System.arraycopy(this.rowinstance, this.offset, c, 0, Row.this.primaryKeyLength); return c; } - + public final int getPrimaryKeyLength() { - return primaryKeyLength; - } - - public final byte[] getColBytes(final int column, boolean nullIfEmpty) { - assert offset + colstart[column] + row[column].cellwidth <= rowinstance.length : - "column = " + column + ", offset = " + offset + ", colstart[column] = " + colstart[column] + ", row[column].cellwidth() = " + row[column].cellwidth + ", rowinstance.length = " + rowinstance.length; - int clstrt = colstart[column]; - final int w = row[column].cellwidth; + return Row.this.primaryKeyLength; + } + + public final byte[] getColBytes(final int column, final boolean nullIfEmpty) { + assert this.offset + Row.this.colstart[column] + Row.this.row[column].cellwidth <= this.rowinstance.length : + "column = " + column + ", offset = " + this.offset + ", colstart[column] = " + Row.this.colstart[column] + ", row[column].cellwidth() = " + Row.this.row[column].cellwidth + ", rowinstance.length = " + this.rowinstance.length; + final int clstrt = Row.this.colstart[column]; + final int w = Row.this.row[column].cellwidth; if (nullIfEmpty) { int length = w; - while (length > 0 && rowinstance[offset + clstrt + length - 1] == 0) length--; + while (length > 0 && this.rowinstance[this.offset + clstrt + length - 1] == 0) length--; if (length == 0) return null; } final byte[] c = new byte[w]; - System.arraycopy(rowinstance, offset + clstrt, c, 0, w); + System.arraycopy(this.rowinstance, this.offset + clstrt, c, 0, w); return c; } - + public final void writeToArray(final int column, final byte[] target, final int targetOffset) { // this method shall replace the getColBytes where possible, bacause it may reduce the number of new byte[] allocations - assert (targetOffset + row[column].cellwidth <= target.length) : "targetOffset = " + targetOffset + ", target.length = " + target.length + ", row[column].cellwidth() = " + row[column].cellwidth; - System.arraycopy(rowinstance, offset + colstart[column], target, targetOffset, row[column].cellwidth); + assert (targetOffset + Row.this.row[column].cellwidth <= target.length) : "targetOffset = " + targetOffset + ", target.length = " + target.length + ", row[column].cellwidth() = " + Row.this.row[column].cellwidth; + System.arraycopy(this.rowinstance, this.offset + Row.this.colstart[column], target, targetOffset, Row.this.row[column].cellwidth); } - + public final String toPropertyForm(final char propertySymbol, final boolean includeBraces, final boolean decimalCardinal, final boolean longname, final boolean quotes) { final ByteBuffer bb = new ByteBuffer(objectsize() * 2); if (includeBraces) bb.append('{'); - for (int i = 0; i < row.length; i++) { + for (int i = 0; i < Row.this.row.length; i++) { if (quotes) bb.append('"'); - bb.append((longname) ? row[i].description : row[i].nickname); + bb.append((longname) ? Row.this.row[i].description : Row.this.row[i].nickname); if (quotes) bb.append('"'); bb.append(propertySymbol); if (quotes) bb.append('"'); - if ((decimalCardinal) && (row[i].celltype == Column.celltype_cardinal)) { + if ((decimalCardinal) && (Row.this.row[i].celltype == Column.celltype_cardinal)) { bb.append(Long.toString(getColLong(i))); - } else if ((decimalCardinal) && (row[i].celltype == Column.celltype_bitfield)) { + } else if ((decimalCardinal) && (Row.this.row[i].celltype == Column.celltype_bitfield)) { bb.append((new Bitfield(getColBytes(i, true))).exportB64()); - } else if ((decimalCardinal) && (row[i].celltype == Column.celltype_binary)) { - assert row[i].cellwidth == 1 : toString(); + } else if ((decimalCardinal) && (Row.this.row[i].celltype == Column.celltype_binary)) { + assert Row.this.row[i].cellwidth == 1 : toString(); bb.append(Integer.toString((0xff & getColByte(i)))); } else { - bb.append(rowinstance, offset + colstart[i], row[i].cellwidth); + bb.append(this.rowinstance, this.offset + Row.this.colstart[i], Row.this.row[i].cellwidth); } if (quotes) bb.append('"'); - if (i < row.length - 1) { + if (i < Row.this.row.length - 1) { bb.append(','); if (longname) bb.append(' '); } @@ -571,14 +571,14 @@ public final class Row { //System.out.println("DEBUG-ROW " + bb.toString()); return bb.toString(); } - + @Override public final String toString() { return toPropertyForm('=', true, false, false, false); } - + } - + public final class EntryIndex extends Entry { private final int index; public EntryIndex(final byte[] row, final int i) { @@ -586,47 +586,47 @@ public final class Row { this.index = i; } public int index() { - return index; + return this.index; } } - + public Queue newQueue(final int maxsize) { return new Queue(maxsize); } - + public final class Queue { - + private final ArrayBlockingQueue queue; - + public Queue(final int maxsize) { this.queue = new ArrayBlockingQueue(maxsize); } - + public void put(final Entry e) throws InterruptedException { this.queue.put(e); } - + public Entry take() throws InterruptedException { return this.queue.take(); } - + public Entry get(final byte[] key) { - for (Entry e: this.queue) { + for (final Entry e: this.queue) { assert key.length == e.getPrimaryKeyLength(); - if (objectOrder.compare(key, 0, e.bytes(), 0, key.length) == 0) { + if (Row.this.objectOrder.compare(key, 0, e.bytes(), 0, key.length) == 0) { return e; } } return null; } - + public Entry delete(final byte[] key) { final Iterator i = this.queue.iterator(); Entry e; while (i.hasNext()) { e = i.next(); assert key.length == e.getPrimaryKeyLength(); - if (objectOrder.compare(key, 0, e.bytes(), 0, key.length) == 0) { + if (Row.this.objectOrder.compare(key, 0, e.bytes(), 0, key.length) == 0) { i.remove(); return e; } @@ -634,21 +634,21 @@ public final class Row { 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); x >>= 8; } } - + public final static long bytes2long(final byte[] b, final int offset, final int length) { if (b == null) return 0; long x = 0; for (int i = 0; i < length; i++) x = (x << 8) | (0xff & b[offset + i]); return x; } - + public final boolean subsumes(final Row otherRow) { // returns true, if this row has at least all columns as the other row // and possibly some more @@ -661,7 +661,7 @@ public final class Row { } return true; } - + @Override public boolean equals(final Object obj) { if (this == obj) return true; @@ -669,16 +669,16 @@ public final class Row { if (!(obj instanceof Row)) return false; final Row other = (Row) obj; if (this.objectsize != other.objectsize) return false; - if (this.columns() != other.columns()) return false; + if (columns() != other.columns()) return false; for (int i = 0; i < other.row.length; i++) { if (!(this.row[i].equals(other.row[i]))) return false; } return true; } - + @Override public int hashCode() { - return this.toString().hashCode(); + return toString().hashCode(); } - + } diff --git a/source/net/yacy/kelondro/index/RowCollection.java b/source/net/yacy/kelondro/index/RowCollection.java index af6398d26..aa16268e9 100644 --- a/source/net/yacy/kelondro/index/RowCollection.java +++ b/source/net/yacy/kelondro/index/RowCollection.java @@ -7,7 +7,7 @@ // $LastChangedBy$ // // LICENSE -// +// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or @@ -57,14 +57,14 @@ public class RowCollection implements Iterable, Cloneable { public static final long growfactorSmall100 = 120L; private static final int isortlimit = 20; private static final int availableCPU = Runtime.getRuntime().availableProcessors(); - + private static final int exp_chunkcount = 0; private static final int exp_last_read = 1; private static final int exp_last_wrote = 2; private static final int exp_order_type = 3; private static final int exp_order_bound = 4; private static final int exp_collection = 5; - + public static final ExecutorService sortingthreadexecutor = (availableCPU > 1) ? new ThreadPoolExecutor( @@ -75,7 +75,7 @@ public class RowCollection implements Iterable, Cloneable { new NamePrefixThreadFactory("sorting"), new ThreadPoolExecutor.CallerRunsPolicy()) : null; - + private static final ExecutorService partitionthreadexecutor = (availableCPU > 1) ? new ThreadPoolExecutor( @@ -86,13 +86,13 @@ public class RowCollection implements Iterable, Cloneable { new NamePrefixThreadFactory("partition"), new ThreadPoolExecutor.CallerRunsPolicy()) : null; - + protected final Row rowdef; protected byte[] chunkcache; protected int chunkcount; protected int sortBound; protected long lastTimeWrote; - + protected RowCollection(final RowCollection rc) { this.rowdef = rc.rowdef; this.chunkcache = rc.chunkcache; @@ -100,7 +100,7 @@ public class RowCollection implements Iterable, Cloneable { this.sortBound = rc.sortBound; this.lastTimeWrote = rc.lastTimeWrote; } - + protected RowCollection(final Row rowdef) { this.rowdef = rowdef; this.sortBound = 0; @@ -108,12 +108,12 @@ public class RowCollection implements Iterable, Cloneable { this.chunkcache = new byte[0]; this.chunkcount = 0; } - + public RowCollection(final Row rowdef, final int objectCount) throws RowSpaceExceededException { this(rowdef); ensureSize(objectCount); } - + protected RowCollection(final Row rowdef, final int objectCount, final byte[] cache, final int sortBound) { this.rowdef = rowdef; this.chunkcache = cache; @@ -121,11 +121,11 @@ public class RowCollection implements Iterable, Cloneable { this.sortBound = sortBound; this.lastTimeWrote = System.currentTimeMillis(); } - + protected RowCollection(final Row rowdef, final Row.Entry exportedCollectionRowEnvironment) { final int chunkcachelength = exportedCollectionRowEnvironment.cellwidth(1) - (int) exportOverheadSize; final Row.Entry exportedCollection = exportRow(chunkcachelength).newEntry(exportedCollectionRowEnvironment, 1); - + this.rowdef = rowdef; this.chunkcount = (int) exportedCollection.getColLong(exp_chunkcount); if ((this.chunkcount > chunkcachelength / rowdef.objectsize)) { @@ -144,14 +144,14 @@ public class RowCollection implements Iterable, Cloneable { if ((rowdef.objectOrder != null) && (oldOrder != null) && (!(rowdef.objectOrder.signature().equals(oldOrder.signature())))) throw new kelondroException("old collection order does not match with new order; objectOrder.signature = " + rowdef.objectOrder.signature() + ", oldOrder.signature = " + oldOrder.signature()); this.sortBound = (int) exportedCollection.getColLong(exp_order_bound); - if (sortBound > chunkcount) { - Log.logWarning("RowCollection", "corrected wrong sortBound; sortBound = " + sortBound + ", chunkcount = " + chunkcount); - this.sortBound = chunkcount; + if (this.sortBound > this.chunkcount) { + Log.logWarning("RowCollection", "corrected wrong sortBound; sortBound = " + this.sortBound + ", chunkcount = " + this.chunkcount); + this.sortBound = this.chunkcount; } - this.chunkcache = exportedCollection.getColBytes(exp_collection, false); + this.chunkcache = exportedCollection.getColBytes(exp_collection, false); } - - protected RowCollection(Row rowdef, byte[] chunkcache, int chunkcount, int sortBound, long lastTimeWrote) { + + protected RowCollection(final Row rowdef, final byte[] chunkcache, final int chunkcount, final int sortBound, final long lastTimeWrote) { this.rowdef = rowdef; this.chunkcache = new byte[chunkcache.length]; System.arraycopy(chunkcache, 0, this.chunkcache, 0, chunkcache.length); @@ -159,7 +159,7 @@ public class RowCollection implements Iterable, Cloneable { this.sortBound = sortBound; this.lastTimeWrote = lastTimeWrote; } - + public RowCollection clone() { return new RowCollection(this.rowdef, this.chunkcache, this.chunkcount, this.sortBound, this.lastTimeWrote); } @@ -169,7 +169,7 @@ public class RowCollection implements Iterable, Cloneable { this.chunkcount = 0; this.sortBound = 0; } - + /** * calculate the memory that the structure occupies in ram * @return number of bytes in use @@ -177,7 +177,7 @@ public class RowCollection implements Iterable, Cloneable { public long mem() { return this.chunkcache.length; } - + private static final Row exportMeasureRow = exportRow(0 /* no relevance */); public static final int sizeOfExportedCollectionRows(final Row.Entry exportedCollectionRowEnvironment, final int columnInEnvironment) { @@ -185,13 +185,13 @@ public class RowCollection implements Iterable, Cloneable { final int chunkcount = (int) exportedCollectionEntry.getColLong(exp_chunkcount); return chunkcount; } - + private static final long day = 1000 * 60 * 60 * 24; - + private static int daysSince2000(final long time) { return (int) (time / day) - 10957; } - + private static Column exportColumn0, exportColumn1, exportColumn2, exportColumn3, exportColumn4; protected static final long exportOverheadSize = 14; @@ -208,7 +208,7 @@ public class RowCollection implements Iterable, Cloneable { NaturalOrder.naturalOrder ); */ - + if (exportColumn0 == null) exportColumn0 = new Column("int size-4 {b256}"); if (exportColumn1 == null) exportColumn1 = new Column("short lastread-2 {b256}"); if (exportColumn2 == null) exportColumn2 = new Column("short lastwrote-2 {b256}"); @@ -218,7 +218,7 @@ public class RowCollection implements Iterable, Cloneable { * 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? */ - Row er = new Row(new Column[]{ + final Row er = new Row(new Column[]{ exportColumn0, exportColumn1, exportColumn2, exportColumn3, exportColumn4, new Column("byte[] collection-" + chunkcachelength) }, @@ -227,18 +227,18 @@ public class RowCollection implements Iterable, Cloneable { assert er.objectsize == chunkcachelength +exportOverheadSize; return er; } - + public synchronized byte[] exportCollection() { // returns null if the collection is empty sort(); // experimental; supervise CPU load //uniq(); //trim(); assert this.sortBound == this.chunkcount; // on case the collection is sorted - assert this.size() * this.rowdef.objectsize <= this.chunkcache.length : "this.size() = " + this.size() + ", objectsize = " + this.rowdef.objectsize + ", chunkcache.length = " + this.chunkcache.length; - final Row row = exportRow(this.size() * this.rowdef.objectsize); + assert size() * this.rowdef.objectsize <= this.chunkcache.length : "this.size() = " + size() + ", objectsize = " + this.rowdef.objectsize + ", chunkcache.length = " + this.chunkcache.length; + final Row row = exportRow(size() * this.rowdef.objectsize); final Row.Entry entry = row.newEntry(); - assert (sortBound <= chunkcount) : "sortBound = " + sortBound + ", chunkcount = " + chunkcount; - assert (this.chunkcount <= chunkcache.length / rowdef.objectsize) : "chunkcount = " + this.chunkcount + ", chunkcache.length = " + chunkcache.length + ", rowdef.objectsize = " + rowdef.objectsize; + assert (this.sortBound <= this.chunkcount) : "sortBound = " + this.sortBound + ", chunkcount = " + this.chunkcount; + assert (this.chunkcount <= this.chunkcache.length / this.rowdef.objectsize) : "chunkcount = " + this.chunkcount + ", chunkcache.length = " + this.chunkcache.length + ", rowdef.objectsize = " + this.rowdef.objectsize; entry.setCol(exp_chunkcount, this.chunkcount); entry.setCol(exp_last_read, daysSince2000(System.currentTimeMillis())); entry.setCol(exp_last_wrote, daysSince2000(this.lastTimeWrote)); @@ -247,7 +247,7 @@ public class RowCollection implements Iterable, Cloneable { entry.setCol(exp_collection, this.chunkcache); return entry.bytes(); } - + public void saveCollection(final File file) throws IOException { FileUtils.copy(exportCollection(), file); } @@ -255,48 +255,48 @@ public class RowCollection implements Iterable, Cloneable { public Row row() { return this.rowdef; } - + private final long neededSpaceForEnsuredSize(final int elements, final boolean forcegc) { assert elements > 0 : "elements = " + elements; - final long needed = elements * rowdef.objectsize; - if (chunkcache.length >= needed) return 0; + final long needed = elements * this.rowdef.objectsize; + if (this.chunkcache.length >= needed) return 0; assert needed > 0 : "needed = " + needed; long allocram = needed * growfactorLarge100 / 100L; - allocram -= allocram % rowdef.objectsize; + allocram -= allocram % this.rowdef.objectsize; assert allocram > 0 : "elements = " + elements + ", new = " + allocram; if (allocram <= Integer.MAX_VALUE && MemoryControl.request(allocram, false)) return allocram; allocram = needed * growfactorSmall100 / 100L; - allocram -= allocram % rowdef.objectsize; + allocram -= allocram % this.rowdef.objectsize; assert allocram >= 0 : "elements = " + elements + ", new = " + allocram; if (allocram <= Integer.MAX_VALUE && MemoryControl.request(allocram, forcegc)) return allocram; return needed; } - + private final void ensureSize(final int elements) throws RowSpaceExceededException { if (elements == 0) return; final long allocram = neededSpaceForEnsuredSize(elements, true); if (allocram == 0) return; - assert chunkcache.length < elements * rowdef.objectsize : "wrong alloc computation (1): elements * rowdef.objectsize = " + (elements * rowdef.objectsize) + ", chunkcache.length = " + chunkcache.length; - assert allocram > chunkcache.length : "wrong alloc computation (2): allocram = " + allocram + ", chunkcache.length = " + chunkcache.length; + assert this.chunkcache.length < elements * this.rowdef.objectsize : "wrong alloc computation (1): elements * rowdef.objectsize = " + (elements * this.rowdef.objectsize) + ", chunkcache.length = " + this.chunkcache.length; + assert allocram > this.chunkcache.length : "wrong alloc computation (2): allocram = " + allocram + ", chunkcache.length = " + this.chunkcache.length; if (allocram > Integer.MAX_VALUE || !MemoryControl.request(allocram + 32, true)) throw new RowSpaceExceededException(allocram + 32, "RowCollection grow"); try { final byte[] newChunkcache = new byte[(int) allocram]; // increase space - System.arraycopy(chunkcache, 0, newChunkcache, 0, chunkcache.length); - chunkcache = newChunkcache; - } catch (OutOfMemoryError e) { + System.arraycopy(this.chunkcache, 0, newChunkcache, 0, this.chunkcache.length); + this.chunkcache = newChunkcache; + } catch (final OutOfMemoryError e) { // lets try again after a forced gc() System.gc(); try { final byte[] newChunkcache = new byte[(int) allocram]; // increase space - System.arraycopy(chunkcache, 0, newChunkcache, 0, chunkcache.length); - chunkcache = newChunkcache; - } catch (OutOfMemoryError ee) { + System.arraycopy(this.chunkcache, 0, newChunkcache, 0, this.chunkcache.length); + this.chunkcache = newChunkcache; + } catch (final OutOfMemoryError ee) { throw new RowSpaceExceededException(allocram, "RowCollection grow after OutOfMemoryError " + ee.getMessage()); } } } - + /** * compute the needed memory in case of a cache extension. That is, if the cache is full and must * be copied into a new cache which is larger. In such a case the Collection needs more than the double size @@ -304,14 +304,14 @@ public class RowCollection implements Iterable, Cloneable { * @return */ protected final long memoryNeededForGrow() { - return neededSpaceForEnsuredSize(chunkcount + 1, false); + return neededSpaceForEnsuredSize(this.chunkcount + 1, false); } - + protected synchronized void trim() { - if (chunkcache.length == 0) return; - long needed = chunkcount * rowdef.objectsize; - assert needed <= chunkcache.length; - if (needed >= chunkcache.length) + if (this.chunkcache.length == 0) return; + final long needed = this.chunkcount * this.rowdef.objectsize; + assert needed <= this.chunkcache.length; + if (needed >= this.chunkcache.length) return; // in case that the growfactor causes that the cache would // grow instead of shrink, simply ignore the growfactor if (MemoryControl.available() + 1000 < needed) @@ -319,67 +319,67 @@ public class RowCollection implements Iterable, Cloneable { // This is not critical. Otherwise we provoke a serious // problem with OOM final byte[] newChunkcache = new byte[(int) needed]; - System.arraycopy(chunkcache, 0, newChunkcache, 0, Math.min(chunkcache.length, newChunkcache.length)); - chunkcache = newChunkcache; + System.arraycopy(this.chunkcache, 0, newChunkcache, 0, Math.min(this.chunkcache.length, newChunkcache.length)); + this.chunkcache = newChunkcache; } - + public final long lastWrote() { - return lastTimeWrote; + return this.lastTimeWrote; } - + protected synchronized final byte[] getKey(final int index) { assert (index >= 0) : "get: access with index " + index + " is below zero"; - assert (index < chunkcount) : "get: access with index " + index + " is above chunkcount " + chunkcount + "; sortBound = " + sortBound; - assert (index * rowdef.objectsize < chunkcache.length); - if ((chunkcache == null) || (rowdef == null)) return null; // case may appear during shutdown - if (index >= chunkcount) return null; - if ((index + 1) * rowdef.objectsize > chunkcache.length) return null; // the whole chunk does not fit into the chunkcache + assert (index < this.chunkcount) : "get: access with index " + index + " is above chunkcount " + this.chunkcount + "; sortBound = " + this.sortBound; + assert (index * this.rowdef.objectsize < this.chunkcache.length); + if ((this.chunkcache == null) || (this.rowdef == null)) return null; // case may appear during shutdown + if (index >= this.chunkcount) return null; + if ((index + 1) * this.rowdef.objectsize > this.chunkcache.length) return null; // the whole chunk does not fit into the chunkcache final byte[] b = new byte[this.rowdef.primaryKeyLength]; - System.arraycopy(chunkcache, index * rowdef.objectsize, b, 0, b.length); + System.arraycopy(this.chunkcache, index * this.rowdef.objectsize, b, 0, b.length); return b; } - + public synchronized final Row.Entry get(final int index, final boolean clone) { assert (index >= 0) : "get: access with index " + index + " is below zero"; - assert (index < chunkcount) : "get: access with index " + index + " is above chunkcount " + chunkcount + "; sortBound = " + sortBound; - assert (chunkcache != null && index * rowdef.objectsize < chunkcache.length); - assert sortBound <= chunkcount : "sortBound = " + sortBound + ", chunkcount = " + chunkcount; - if ((chunkcache == null) || (rowdef == null)) return null; // case may appear during shutdown + assert (index < this.chunkcount) : "get: access with index " + index + " is above chunkcount " + this.chunkcount + "; sortBound = " + this.sortBound; + assert (this.chunkcache != null && index * this.rowdef.objectsize < this.chunkcache.length); + assert this.sortBound <= this.chunkcount : "sortBound = " + this.sortBound + ", chunkcount = " + this.chunkcount; + if ((this.chunkcache == null) || (this.rowdef == null)) return null; // case may appear during shutdown Row.Entry entry; - final int addr = index * rowdef.objectsize; - if (index >= chunkcount) return null; - if (addr + rowdef.objectsize > chunkcache.length) return null; // the whole chunk does not fit into the chunkcache - entry = rowdef.newEntry(chunkcache, addr, clone); + final int addr = index * this.rowdef.objectsize; + if (index >= this.chunkcount) return null; + if (addr + this.rowdef.objectsize > this.chunkcache.length) return null; // the whole chunk does not fit into the chunkcache + entry = this.rowdef.newEntry(this.chunkcache, addr, clone); return entry; } - + public synchronized final void set(final int index, final Row.Entry a) throws RowSpaceExceededException { assert (index >= 0) : "set: access with index " + index + " is below zero"; ensureSize(index + 1); - byte[] column = a.bytes(); + final byte[] column = a.bytes(); assert a.cellwidth(0) == this.rowdef.primaryKeyLength; assert column.length >= this.rowdef.primaryKeyLength; final boolean sameKey = match(column, 0, index); //if (sameKey) System.out.print("$"); - a.writeToArray(chunkcache, index * rowdef.objectsize); + a.writeToArray(this.chunkcache, index * this.rowdef.objectsize); if (index >= this.chunkcount) this.chunkcount = index + 1; if (!sameKey && index < this.sortBound) this.sortBound = index; this.lastTimeWrote = System.currentTimeMillis(); } - + public final void insertUnique(final int index, final Row.Entry a) throws RowSpaceExceededException { assert (a != null); - if (index < chunkcount) { + if (index < this.chunkcount) { // make room - ensureSize(chunkcount + 1); - System.arraycopy(chunkcache, rowdef.objectsize * index, chunkcache, rowdef.objectsize * (index + 1), (chunkcount - index) * rowdef.objectsize); - chunkcount++; + ensureSize(this.chunkcount + 1); + System.arraycopy(this.chunkcache, this.rowdef.objectsize * index, this.chunkcache, this.rowdef.objectsize * (index + 1), (this.chunkcount - index) * this.rowdef.objectsize); + this.chunkcount++; } // insert entry into gap set(index, a); } - + public synchronized void addUnique(final Row.Entry row) throws RowSpaceExceededException { final byte[] r = row.bytes(); addUnique(r, 0, r.length); @@ -390,116 +390,116 @@ public class RowCollection implements Iterable, Cloneable { final Iterator i = rows.iterator(); while (i.hasNext()) addUnique(i.next()); } - + public synchronized void add(final byte[] a) throws RowSpaceExceededException { assert a.length == this.rowdef.objectsize : "a.length = " + a.length + ", objectsize = " + this.rowdef.objectsize; addUnique(a, 0, a.length); } - + private final void addUnique(final byte[] a, final int astart, final int alength) throws RowSpaceExceededException { assert (a != null); assert (astart >= 0) && (astart < a.length) : " astart = " + astart; assert (!(Log.allZero(a, astart, alength))) : "a = " + NaturalOrder.arrayList(a, astart, alength); assert (alength > 0); assert (astart + alength <= a.length); - assert alength == rowdef.objectsize : "alength =" + alength + ", rowdef.objectsize = " + rowdef.objectsize; - final int l = Math.min(rowdef.objectsize, Math.min(alength, a.length - astart)); - ensureSize(chunkcount + 1); - System.arraycopy(a, astart, chunkcache, rowdef.objectsize * chunkcount, l); - chunkcount++; + assert alength == this.rowdef.objectsize : "alength =" + alength + ", rowdef.objectsize = " + this.rowdef.objectsize; + final int l = Math.min(this.rowdef.objectsize, Math.min(alength, a.length - astart)); + ensureSize(this.chunkcount + 1); + System.arraycopy(a, astart, this.chunkcache, this.rowdef.objectsize * this.chunkcount, l); + this.chunkcount++; // if possible, increase the sortbound value to suppress unnecessary sorting if (this.chunkcount == 1) { assert this.sortBound == 0; this.sortBound = 1; } else if ( - this.sortBound + 1 == chunkcount && - this.rowdef.objectOrder.compare(chunkcache, rowdef.objectsize * (chunkcount - 2), - chunkcache, rowdef.objectsize * (chunkcount - 1), rowdef.primaryKeyLength) == -1) { - this.sortBound = chunkcount; + this.sortBound + 1 == this.chunkcount && + this.rowdef.objectOrder.compare(this.chunkcache, this.rowdef.objectsize * (this.chunkcount - 2), + this.chunkcache, this.rowdef.objectsize * (this.chunkcount - 1), this.rowdef.primaryKeyLength) == -1) { + this.sortBound = this.chunkcount; } this.lastTimeWrote = System.currentTimeMillis(); } - + protected final void addSorted(final byte[] a, final int astart, final int alength) throws RowSpaceExceededException { assert (a != null); assert (astart >= 0) && (astart < a.length) : " astart = " + astart; assert (!(Log.allZero(a, astart, alength))) : "a = " + NaturalOrder.arrayList(a, astart, alength); assert (alength > 0); assert (astart + alength <= a.length); - assert alength == rowdef.objectsize : "alength =" + alength + ", rowdef.objectsize = " + rowdef.objectsize; - final int l = Math.min(rowdef.objectsize, Math.min(alength, a.length - astart)); - ensureSize(chunkcount + 1); - System.arraycopy(a, astart, chunkcache, rowdef.objectsize * chunkcount, l); + assert alength == this.rowdef.objectsize : "alength =" + alength + ", rowdef.objectsize = " + this.rowdef.objectsize; + final int l = Math.min(this.rowdef.objectsize, Math.min(alength, a.length - astart)); + ensureSize(this.chunkcount + 1); + System.arraycopy(a, astart, this.chunkcache, this.rowdef.objectsize * this.chunkcount, l); this.chunkcount++; this.sortBound = this.chunkcount; this.lastTimeWrote = System.currentTimeMillis(); } - + public synchronized final void addAllUnique(final RowCollection c) throws RowSpaceExceededException { if (c == null) return; - assert(rowdef.objectsize == c.rowdef.objectsize); - ensureSize(chunkcount + c.size()); - System.arraycopy(c.chunkcache, 0, chunkcache, rowdef.objectsize * chunkcount, rowdef.objectsize * c.size()); - chunkcount += c.size(); + assert(this.rowdef.objectsize == c.rowdef.objectsize); + ensureSize(this.chunkcount + c.size()); + System.arraycopy(c.chunkcache, 0, this.chunkcache, this.rowdef.objectsize * this.chunkcount, this.rowdef.objectsize * c.size()); + this.chunkcount += c.size(); } - + /** * This method removes the entry at position p ensuring the order of the remaining * entries if specified by keepOrder. * Note: Keeping the order is expensive. If you want to remove more than one element in * a batch with this method, it'd be better to do the removes without order keeping and doing * the sort after all the removes are done. - * + * * @param p element at this position will be removed * @param keepOrder keep the order of remaining entries */ public synchronized final void removeRow(final int p, final boolean keepOrder) { assert p >= 0 : "p = " + p; - assert p < chunkcount : "p = " + p + ", chunkcount = " + chunkcount; - assert chunkcount > 0 : "chunkcount = " + chunkcount; - assert sortBound <= chunkcount : "sortBound = " + sortBound + ", chunkcount = " + chunkcount; - if (keepOrder && (p < sortBound)) { + assert p < this.chunkcount : "p = " + p + ", chunkcount = " + this.chunkcount; + assert this.chunkcount > 0 : "chunkcount = " + this.chunkcount; + assert this.sortBound <= this.chunkcount : "sortBound = " + this.sortBound + ", chunkcount = " + this.chunkcount; + if (keepOrder && (p < this.sortBound)) { // remove by shift (quite expensive for big collections) final int addr = p * this.rowdef.objectsize; System.arraycopy( - chunkcache, addr + this.rowdef.objectsize, - chunkcache, addr, - (chunkcount - p - 1) * this.rowdef.objectsize); - sortBound--; // this is only correct if p < sortBound, but this was already checked above + this.chunkcache, addr + this.rowdef.objectsize, + this.chunkcache, addr, + (this.chunkcount - p - 1) * this.rowdef.objectsize); + this.sortBound--; // this is only correct if p < sortBound, but this was already checked above } else { // remove by copying the top-element to the remove position - if (p != chunkcount - 1) { + if (p != this.chunkcount - 1) { System.arraycopy( - chunkcache, (chunkcount - 1) * this.rowdef.objectsize, - chunkcache, p * this.rowdef.objectsize, + this.chunkcache, (this.chunkcount - 1) * this.rowdef.objectsize, + this.chunkcache, p * this.rowdef.objectsize, this.rowdef.objectsize); } // we moved the last element to the remove position: (p+1)st element // only the first p elements keep their order (element p is already outside the order) - if (sortBound > p) sortBound = p; + if (this.sortBound > p) this.sortBound = p; } - chunkcount--; + this.chunkcount--; this.lastTimeWrote = System.currentTimeMillis(); } - + /** * removes the last entry from the collection * @return */ public synchronized Row.Entry removeOne() { - if (chunkcount == 0) return null; - final Row.Entry r = get(chunkcount - 1, true); - if (chunkcount == sortBound) sortBound--; - chunkcount--; + if (this.chunkcount == 0) return null; + final Row.Entry r = get(this.chunkcount - 1, true); + if (this.chunkcount == this.sortBound) this.sortBound--; + this.chunkcount--; this.lastTimeWrote = System.currentTimeMillis(); return r; } - + public synchronized List top(int count) { - ArrayList list = new ArrayList(); - if (chunkcount == 0) return list; + final ArrayList list = new ArrayList(); + if (this.chunkcount == 0) return list; Row.Entry entry; - int cursor = chunkcount - 1; + int cursor = this.chunkcount - 1; while (count > 0 && cursor >= 0) { entry = get(cursor, true); list.add(entry); @@ -508,23 +508,23 @@ public class RowCollection implements Iterable, Cloneable { } return list; } - + public synchronized byte[] smallestKey() { - if (chunkcount == 0) return null; - this.sort(); + if (this.chunkcount == 0) return null; + sort(); final Row.Entry r = get(0, false); final byte[] b = r.getPrimaryKeyBytes(); return b; } - + public synchronized byte[] largestKey() { - if (chunkcount == 0) return null; - this.sort(); - final Row.Entry r = get(chunkcount - 1, false); + if (this.chunkcount == 0) return null; + sort(); + final Row.Entry r = get(this.chunkcount - 1, false); final byte[] b = r.getPrimaryKeyBytes(); return b; } - + public synchronized void clear() { if (this.chunkcache.length == 0) return; this.chunkcache = new byte[0]; @@ -532,24 +532,24 @@ public class RowCollection implements Iterable, Cloneable { this.sortBound = 0; this.lastTimeWrote = System.currentTimeMillis(); } - + public int size() { return this.chunkcount; } - + public boolean isEmpty() { return this.chunkcount == 0; } - + public int sorted() { return this.sortBound; } - + public synchronized Iterator keys(final boolean keepOrderWhenRemoving) { // iterates byte[] - type entries return new keyIterator(keepOrderWhenRemoving); } - + /** * Iterator for kelondroRowCollection. * It supports remove() though it doesn't contain the order of the underlying @@ -560,25 +560,25 @@ public class RowCollection implements Iterable, Cloneable { private int p; private final boolean keepOrderWhenRemoving; - + private keyIterator(final boolean keepOrderWhenRemoving) { this.p = 0; this.keepOrderWhenRemoving = keepOrderWhenRemoving; } - + public boolean hasNext() { - return p < chunkcount; + return this.p < RowCollection.this.chunkcount; } public byte[] next() { - return getKey(p++); + return getKey(this.p++); } - + public void remove() { - p--; - removeRow(p, keepOrderWhenRemoving); + this.p--; + removeRow(this.p, this.keepOrderWhenRemoving); } - } + } /** * return an iterator for the row entries in this object @@ -587,7 +587,7 @@ public class RowCollection implements Iterable, Cloneable { // iterates kelondroRow.Entry - type entries return new rowIterator(); } - + /** * Iterator for kelondroRowCollection. * It supports remove() and keeps the order of the underlying @@ -596,40 +596,40 @@ public class RowCollection implements Iterable, Cloneable { private class rowIterator implements Iterator { private int p; - + public rowIterator() { - p = 0; + this.p = 0; } - + public boolean hasNext() { - return p < chunkcount; + return this.p < RowCollection.this.chunkcount; } public Row.Entry next() { - return get(p++, true); + return get(this.p++, true); } - + public void remove() { - p--; - removeRow(p, true); + this.p--; + removeRow(this.p, true); } } - + public synchronized final void sort() { assert (this.rowdef.objectOrder != null); if (this.sortBound == this.chunkcount) return; // this is already sorted if (this.chunkcount < isortlimit) { isort(0, this.chunkcount, new byte[this.rowdef.objectsize]); this.sortBound = this.chunkcount; - assert this.isSorted(); + assert isSorted(); return; } final byte[] swapspace = new byte[this.rowdef.objectsize]; final int p = partition(0, this.chunkcount, this.sortBound, swapspace); if (sortingthreadexecutor != null && !sortingthreadexecutor.isShutdown() && - availableCPU > 1 && + availableCPU > 1 && this.chunkcount > 8000 && p > isortlimit * 5 && this.chunkcount - p > isortlimit * 5 @@ -639,43 +639,43 @@ public class RowCollection implements Iterable, Cloneable { int p0 = -1, p1 = -1; try { part0 = partitionthreadexecutor.submit(new partitionthread(this, 0, p, 0)); - } catch (RejectedExecutionException e) { + } catch (final RejectedExecutionException e) { part0 = null; - try {p0 = new partitionthread(this, 0, p, 0).call().intValue();} catch (Exception ee) {} + try {p0 = new partitionthread(this, 0, p, 0).call().intValue();} catch (final Exception ee) {} } try { part1 = partitionthreadexecutor.submit(new partitionthread(this, p, this.chunkcount, p)); - } catch (RejectedExecutionException e) { + } catch (final RejectedExecutionException e) { part1 = null; - try {p1 = new partitionthread(this, p, this.chunkcount, p).call().intValue();} catch (Exception ee) {} + try {p1 = new partitionthread(this, p, this.chunkcount, p).call().intValue();} catch (final Exception ee) {} } try { if (part0 != null) p0 = part0.get().intValue(); Future sort0, sort1, sort2, sort3; try { sort0 = sortingthreadexecutor.submit(new qsortthread(this, 0, p0, 0)); - } catch (RejectedExecutionException e) { + } catch (final RejectedExecutionException e) { sort0 = null; - try {new qsortthread(this, 0, p0, 0).call();} catch (Exception ee) {} + try {new qsortthread(this, 0, p0, 0).call();} catch (final Exception ee) {} } try { sort1 = sortingthreadexecutor.submit(new qsortthread(this, p0, p, p0)); - } catch (RejectedExecutionException e) { + } catch (final RejectedExecutionException e) { sort1 = null; - try {new qsortthread(this, p0, p, p0).call();} catch (Exception ee) {} + try {new qsortthread(this, p0, p, p0).call();} catch (final Exception ee) {} } if (part1 != null) p1 = part1.get().intValue(); try { sort2 = sortingthreadexecutor.submit(new qsortthread(this, p, p1, p)); - } catch (RejectedExecutionException e) { + } catch (final RejectedExecutionException e) { sort2 = null; - try {new qsortthread(this, p, p1, p).call();} catch (Exception ee) {} + try {new qsortthread(this, p, p1, p).call();} catch (final Exception ee) {} } try { sort3 = sortingthreadexecutor.submit(new qsortthread(this, p1, this.chunkcount, p1)); - } catch (RejectedExecutionException e) { + } catch (final RejectedExecutionException e) { sort3 = null; - try {new qsortthread(this, p1, this.chunkcount, p1).call();} catch (Exception ee) {} + try {new qsortthread(this, p1, this.chunkcount, p1).call();} catch (final Exception ee) {} } // wait for all results if (sort0 != null) sort0.get(); @@ -709,7 +709,7 @@ public class RowCollection implements Iterable, Cloneable { final int p = partition(0, this.chunkcount, this.sortBound, swapspace); if ((sortingthreadexecutor != null) && (!sortingthreadexecutor.isShutdown()) && - (availableCPU > 1) && + (availableCPU > 1) && (this.chunkcount > 4000)) { // sort this using multi-threading final Future part = sortingthreadexecutor.submit(new qsortthread(this, 0, p, 0)); @@ -731,24 +731,24 @@ public class RowCollection implements Iterable, Cloneable { //assert this.isSorted(); } */ - + private static class qsortthread implements Callable { - private RowCollection rc; + private final RowCollection rc; int L, R, S; - + public qsortthread(final RowCollection rc, final int L, final int R, final int S) { this.rc = rc; this.L = L; this.R = R; this.S = S; } - + public Object call() throws Exception { - rc.qsort(L, R, S, new byte[rc.rowdef.objectsize]); + this.rc.qsort(this.L, this.R, this.S, new byte[this.rc.rowdef.objectsize]); return null; } } - + final void qsort(final int L, final int R, final int S, final byte[] swapspace) { if (R - L < isortlimit) { isort(L, R, swapspace); @@ -761,23 +761,23 @@ public class RowCollection implements Iterable, Cloneable { qsort(L, p, 0, swapspace); qsort(p + 1, R, 0, swapspace); } - + public static class partitionthread implements Callable { RowCollection rc; int L, R, S; - + public partitionthread(final RowCollection rc, final int L, final int R, final int S) { this.rc = rc; this.L = L; this.R = R; this.S = S; } - + public Integer call() throws Exception { - return Integer.valueOf(rc.partition(L, R, S, new byte[rc.rowdef.objectsize])); + return Integer.valueOf(this.rc.partition(this.L, this.R, this.S, new byte[this.rc.rowdef.objectsize])); } } - + /** * @param L is the first element in the sequence * @param R is the right bound of the sequence, and outside of the sequence @@ -788,7 +788,7 @@ public class RowCollection implements Iterable, Cloneable { final int partition(final int L, final int R, int S, final byte[] swapspace) { assert (L < R - 1): "L = " + L + ", R = " + R + ", S = " + S; assert (R - L >= isortlimit): "L = " + L + ", R = " + R + ", S = " + S + ", isortlimit = " + isortlimit; - + int p = L; int q = R - 1; int pivot = pivot(L, R, S); @@ -845,7 +845,7 @@ public class RowCollection implements Iterable, Cloneable { assert pivot == p; return p; } - + private final int pivot(final int L, final int R, final int S) { if (S == 0 || S < L) { // the collection has no ordering @@ -875,7 +875,7 @@ public class RowCollection implements Iterable, Cloneable { private final int picMiddle(final int a, final int b, final int c, final int d, final int e) { return picMiddle(picMiddle(a, b, c), d, e); } - + private final int picMiddle(final int a, final int b, final int c) { if (compare(a, b) > 0) { if (compare(c, a) > 0) return a; @@ -888,7 +888,7 @@ public class RowCollection implements Iterable, Cloneable { //if (c < a && a < b || a > b && c > a) return a; //if (a < b && c > b || c < b && a > b) return b; } - + /* private final int picMiddle(final int[] list, int len) { assert len % 2 != 0; @@ -904,7 +904,7 @@ public class RowCollection implements Iterable, Cloneable { if (idx == len - 1) return; list[idx] = list[len - 1]; // shift last element to front } - + private final int min(final int[] list, int len) { assert len > 0; int f = 0; @@ -913,7 +913,7 @@ public class RowCollection implements Iterable, Cloneable { } return f; } - + private final int max(final int[] list, int len) { assert len > 0; int f = 0; @@ -923,7 +923,7 @@ public class RowCollection implements Iterable, Cloneable { return f; } */ - + private final void isort(final int L, final int R, final byte[] swapspace) { for (int i = L + 1; i < R; i++) for (int j = i; j > L && compare(j - 1, j) > 0; j--) @@ -932,9 +932,9 @@ public class RowCollection implements Iterable, Cloneable { private final int swap(final int i, final int j, final int p, final byte[] swapspace) { if (i == j) return p; - System.arraycopy(chunkcache, this.rowdef.objectsize * i, swapspace, 0, this.rowdef.objectsize); - System.arraycopy(chunkcache, this.rowdef.objectsize * j, chunkcache, this.rowdef.objectsize * i, this.rowdef.objectsize); - System.arraycopy(swapspace, 0, chunkcache, this.rowdef.objectsize * j, this.rowdef.objectsize); + System.arraycopy(this.chunkcache, this.rowdef.objectsize * i, swapspace, 0, this.rowdef.objectsize); + System.arraycopy(this.chunkcache, this.rowdef.objectsize * j, this.chunkcache, this.rowdef.objectsize * i, this.rowdef.objectsize); + System.arraycopy(swapspace, 0, this.chunkcache, this.rowdef.objectsize * j, this.rowdef.objectsize); if (i == p) return j; else if (j == p) return i; else return p; } @@ -945,8 +945,8 @@ public class RowCollection implements Iterable, Cloneable { // if the collection is large and the number of deletions is also large, // then this method may run a long time with 100% CPU load which is caused // by the large number of memory movements. - if (chunkcount < 2) return; - int i = chunkcount - 2; + if (this.chunkcount < 2) return; + int i = this.chunkcount - 2; final long t = System.currentTimeMillis(); // for time-out int d = 0; try { @@ -957,7 +957,7 @@ public class RowCollection implements Iterable, Cloneable { } i--; if (System.currentTimeMillis() - t > 60000) { - Log.logWarning("RowCollection", "uniq() time-out at " + i + " (backwards) from " + chunkcount + " elements after " + (System.currentTimeMillis() - t) + " milliseconds; " + d + " deletions so far"); + Log.logWarning("RowCollection", "uniq() time-out at " + i + " (backwards) from " + this.chunkcount + " elements after " + (System.currentTimeMillis() - t) + " milliseconds; " + d + " deletions so far"); return; } } @@ -965,16 +965,16 @@ public class RowCollection implements Iterable, Cloneable { Log.logWarning("RowCollection", e.getMessage(), e); } } - + public synchronized ArrayList removeDoubles() throws RowSpaceExceededException { assert (this.rowdef.objectOrder != null); // removes double-occurrences of chunks // in contrast to uniq() this removes also the remaining, non-double entry that had a double-occurrence to the others // all removed chunks are returned in an array - this.sort(); + sort(); final ArrayList report = new ArrayList(); - if (chunkcount < 2) return report; - int i = chunkcount - 2; + if (this.chunkcount < 2) return report; + int i = this.chunkcount - 2; boolean u = true; RowCollection collection = new RowCollection(this.rowdef, 2); try { @@ -982,12 +982,12 @@ public class RowCollection implements Iterable, Cloneable { if (match(i, i + 1)) { collection.addUnique(get(i + 1, false)); removeRow(i + 1, false); - if (i + 1 < chunkcount - 1) u = false; + if (i + 1 < this.chunkcount - 1) u = false; } else if (!collection.isEmpty()) { // finish collection of double occurrences collection.addUnique(get(i + 1, false)); removeRow(i + 1, false); - if (i + 1 < chunkcount - 1) u = false; + if (i + 1 < this.chunkcount - 1) u = false; collection.trim(); report.add(collection); collection = new RowSet(this.rowdef, 2); @@ -997,15 +997,15 @@ public class RowCollection implements Iterable, Cloneable { } catch (final RuntimeException e) { Log.logWarning("kelondroRowCollection", e.getMessage(), e); } finally { - if (!u) this.sort(); + if (!u) sort(); } return report; } - + public synchronized boolean isSorted() { assert (this.rowdef.objectOrder != null); - if (chunkcount <= 1) return true; - if (chunkcount != this.sortBound) return false; + if (this.chunkcount <= 1) return true; + if (this.chunkcount != this.sortBound) return false; /* for (int i = 0; i < chunkcount - 1; i++) { //System.out.println("*" + UTF8.String(get(i).getPrimaryKeyBytes())); @@ -1017,7 +1017,7 @@ public class RowCollection implements Iterable, Cloneable { */ return true; } - + public synchronized String toString() { final StringBuilder s = new StringBuilder(80); final Iterator i = iterator(); @@ -1027,66 +1027,66 @@ public class RowCollection implements Iterable, Cloneable { } private final int compare(final int i, final int j) { - assert (chunkcount * this.rowdef.objectsize <= chunkcache.length) : "chunkcount = " + chunkcount + ", objsize = " + this.rowdef.objectsize + ", chunkcache.length = " + chunkcache.length; - assert (i >= 0) && (i < chunkcount) : "i = " + i + ", chunkcount = " + chunkcount; - assert (j >= 0) && (j < chunkcount) : "j = " + j + ", chunkcount = " + chunkcount; + assert (this.chunkcount * this.rowdef.objectsize <= this.chunkcache.length) : "chunkcount = " + this.chunkcount + ", objsize = " + this.rowdef.objectsize + ", chunkcache.length = " + this.chunkcache.length; + assert (i >= 0) && (i < this.chunkcount) : "i = " + i + ", chunkcount = " + this.chunkcount; + assert (j >= 0) && (j < this.chunkcount) : "j = " + j + ", chunkcount = " + this.chunkcount; assert (this.rowdef.objectOrder != null); if (i == j) return 0; //assert (!bugappearance(chunkcache, i * this.rowdef.objectsize + colstart, this.rowdef.primaryKeyLength)); //assert (!bugappearance(chunkcache, j * this.rowdef.objectsize + colstart, this.rowdef.primaryKeyLength)); final int c = this.rowdef.objectOrder.compare( - chunkcache, + this.chunkcache, i * this.rowdef.objectsize, - chunkcache, + this.chunkcache, j * this.rowdef.objectsize, this.rowdef.primaryKeyLength); return c; } protected synchronized int compare(final byte[] a, final int astart, final int chunknumber) { - assert (chunknumber < chunkcount); + assert (chunknumber < this.chunkcount); assert a.length - astart >= this.rowdef.primaryKeyLength; final int len = Math.min(a.length - astart, this.rowdef.primaryKeyLength); - return rowdef.objectOrder.compare(a, astart, chunkcache, chunknumber * this.rowdef.objectsize, len); + return this.rowdef.objectOrder.compare(a, astart, this.chunkcache, chunknumber * this.rowdef.objectsize, len); } - + protected final boolean match(final int i, final int j) { - assert (chunkcount * this.rowdef.objectsize <= chunkcache.length) : "chunkcount = " + chunkcount + ", objsize = " + this.rowdef.objectsize + ", chunkcache.length = " + chunkcache.length; - assert (i >= 0) && (i < chunkcount) : "i = " + i + ", chunkcount = " + chunkcount; - assert (j >= 0) && (j < chunkcount) : "j = " + j + ", chunkcount = " + chunkcount; - if (i >= chunkcount) return false; - if (j >= chunkcount) return false; + assert (this.chunkcount * this.rowdef.objectsize <= this.chunkcache.length) : "chunkcount = " + this.chunkcount + ", objsize = " + this.rowdef.objectsize + ", chunkcache.length = " + this.chunkcache.length; + assert (i >= 0) && (i < this.chunkcount) : "i = " + i + ", chunkcount = " + this.chunkcount; + assert (j >= 0) && (j < this.chunkcount) : "j = " + j + ", chunkcount = " + this.chunkcount; + if (i >= this.chunkcount) return false; + if (j >= this.chunkcount) return false; assert (this.rowdef.objectOrder != null); if (i == j) return true; int astart = i * this.rowdef.objectsize; int bstart = j * this.rowdef.objectsize; int k = this.rowdef.primaryKeyLength; while (k-- != 0) { - if (chunkcache[astart++] != chunkcache[bstart++]) return false; + if (this.chunkcache[astart++] != this.chunkcache[bstart++]) return false; } return true; } - + protected synchronized boolean match(final byte[] a, int astart, final int chunknumber) { - if (chunknumber >= chunkcount) return false; + if (chunknumber >= this.chunkcount) return false; int p = chunknumber * this.rowdef.objectsize; assert a.length - astart >= this.rowdef.primaryKeyLength; int len = Math.min(a.length - astart, this.rowdef.primaryKeyLength); while (len-- != 0) { - if (a[astart++] != chunkcache[p++]) return false; + if (a[astart++] != this.chunkcache[p++]) return false; } return true; } public synchronized void close() { - chunkcache = null; + this.chunkcache = null; } - + private static long d(final long a, final long b) { if (b == 0) return a; return a / b; } - + private static Random random = null; private static String randomHash() { return @@ -1094,12 +1094,12 @@ public class RowCollection implements Iterable, Cloneable { Base64Order.enhancedCoder.encodeLongSB(random.nextLong(), 4).toString() + Base64Order.enhancedCoder.encodeLongSB(random.nextLong(), 4).toString(); } - + public static void test(final int testsize) throws RowSpaceExceededException { final Row r = new Row(new Column[]{ new Column("hash", Column.celltype_string, Column.encoder_bytes, 12, "hash")}, Base64Order.enhancedCoder); - + RowCollection a = new RowCollection(r, testsize); a.add("AAAAAAAAAAAA".getBytes()); a.add("BBBBBBBBBBBB".getBytes()); @@ -1110,7 +1110,7 @@ public class RowCollection implements Iterable, Cloneable { System.out.println(del + "rows double"); final Iterator j = a.iterator(); while (j.hasNext()) System.out.println(UTF8.String(j.next().bytes())); - + System.out.println("kelondroRowCollection test with size = " + testsize); a = new RowCollection(r, testsize); long t0 = System.nanoTime(); @@ -1122,7 +1122,7 @@ public class RowCollection implements Iterable, Cloneable { a.uniq(); long t1 = System.nanoTime(); System.out.println("create a : " + (t1 - t0) + " nanoseconds, " + d(testsize, (t1 - t0)) + " entries/nanoseconds; a.size() = " + a.size()); - + final RowCollection c = new RowCollection(r, testsize); random = new Random(0); t0 = System.nanoTime(); @@ -1198,18 +1198,18 @@ public class RowCollection implements Iterable, Cloneable { System.out.println(); if (sortingthreadexecutor != null) sortingthreadexecutor.shutdown(); } - + public static void main(final String[] args) { //test(1000); try { test(50000); - } catch (RowSpaceExceededException e) { + } catch (final RowSpaceExceededException e) { e.printStackTrace(); } //test(100000); //test(1000000); - - /* + + /* System.out.println(new java.util.Date(10957 * day)); System.out.println(new java.util.Date(0)); System.out.println(daysSince2000(System.currentTimeMillis()));