integrated cell-, and row-management classes

this will be used for automatic export features

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2141 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent 4d8f8ba384
commit 899c1a5df5

@ -0,0 +1,65 @@
// kelondroCell.java
// (C) 2006 by Michael Peter Christen; mc@anomic.de, Frankfurt a. M., Germany
// first published 24.05.2006 on http://www.anomic.de
//
// This is a part of the kelondro database,
// which is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
// $LastChangedRevision: 1986 $
// $LastChangedBy: orbiter $
//
// 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
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 kelondroCell {
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;
private int celltype, dbwidth;
private String nickname, description;
public kelondroCell(int celltype, int dbwidth, String nickname, String description) {
this.celltype = celltype;
this.dbwidth = dbwidth;
this.nickname = nickname;
this.description = description;
}
public int celltype() {
return this.celltype;
}
public int dbwidth() {
return this.dbwidth;
}
public String nickname() {
return this.nickname;
}
public String description() {
return this.description;
}
}

@ -143,7 +143,7 @@ public class kelondroRecords {
private usageControl USAGE; // counter for used and re-use records and pointer to free-list private usageControl USAGE; // counter for used and re-use records and pointer to free-list
private short OHBYTEC; // number of extra bytes in each node private short OHBYTEC; // number of extra bytes in each node
private short OHHANDLEC; // number of handles in each node private short OHHANDLEC; // number of handles in each node
protected int COLWIDTHS[]; // array with widths of columns private kelondroRow ROW; // array with widths of columns
private Handle HANDLES[]; // array with handles private Handle HANDLES[]; // array with handles
private byte[] TXTPROPS[]; // array with text properties private byte[] TXTPROPS[]; // array with text properties
private int TXTPROPW; // size of a single TXTPROPS element private int TXTPROPW; // size of a single TXTPROPS element
@ -264,7 +264,7 @@ public class kelondroRecords {
USAGE = new usageControl(0, 0, new Handle(NUL)); USAGE = new usageControl(0, 0, new Handle(NUL));
OHBYTEC = ohbytec; OHBYTEC = ohbytec;
OHHANDLEC = ohhandlec; OHHANDLEC = ohhandlec;
COLWIDTHS = columns; ROW = new kelondroRow(columns);
HANDLES = new Handle[FHandles]; HANDLES = new Handle[FHandles];
for (int i = 0; i < FHandles; i++) HANDLES[i] = new Handle(NUL); for (int i = 0; i < FHandles; i++) HANDLES[i] = new Handle(NUL);
TXTPROPS = new byte[txtProps][]; TXTPROPS = new byte[txtProps][];
@ -276,7 +276,7 @@ public class kelondroRecords {
entryFile.writeByte(POS_BUSY, 0); // unlock: default entryFile.writeByte(POS_BUSY, 0); // unlock: default
entryFile.writeShort(POS_PORT, 4444); // default port (not used yet) entryFile.writeShort(POS_PORT, 4444); // default port (not used yet)
entryFile.write(POS_DESCR, "--AnomicRecords file structure--".getBytes()); entryFile.write(POS_DESCR, "--AnomicRecords file structure--".getBytes());
entryFile.writeShort(POS_COLUMNS, this.COLWIDTHS.length); entryFile.writeShort(POS_COLUMNS, this.ROW.columns());
entryFile.writeShort(POS_OHBYTEC, OHBYTEC); entryFile.writeShort(POS_OHBYTEC, OHBYTEC);
entryFile.writeShort(POS_OHHANDLEC, OHHANDLEC); entryFile.writeShort(POS_OHHANDLEC, OHHANDLEC);
entryFile.writeInt(POS_USEDC, this.USAGE.USEDC); entryFile.writeInt(POS_USEDC, this.USAGE.USEDC);
@ -290,8 +290,8 @@ public class kelondroRecords {
entryFile.writeInt(POS_TXTPROPW, txtPropWidth); entryFile.writeInt(POS_TXTPROPW, txtPropWidth);
// write configuration arrays // write configuration arrays
for (int i = 0; i < this.COLWIDTHS.length; i++) { for (int i = 0; i < this.ROW.columns(); i++) {
entryFile.writeInt(POS_COLWIDTHS + 4 * i, COLWIDTHS[i]); entryFile.writeInt(POS_COLWIDTHS + 4 * i, this.ROW.width(i));
} }
for (int i = 0; i < this.HANDLES.length; i++) { for (int i = 0; i < this.HANDLES.length; i++) {
entryFile.writeInt(POS_HANDLES + 4 * i, NUL); entryFile.writeInt(POS_HANDLES + 4 * i, NUL);
@ -388,7 +388,7 @@ public class kelondroRecords {
this.OHBYTEC = entryFile.readShort(POS_OHBYTEC); this.OHBYTEC = entryFile.readShort(POS_OHBYTEC);
this.OHHANDLEC = entryFile.readShort(POS_OHHANDLEC); this.OHHANDLEC = entryFile.readShort(POS_OHHANDLEC);
this.COLWIDTHS = new int[entryFile.readShort(POS_COLUMNS)]; int[] COLWIDTHS = new int[entryFile.readShort(POS_COLUMNS)];
this.HANDLES = new Handle[entryFile.readInt(POS_INTPROPC)]; this.HANDLES = new Handle[entryFile.readInt(POS_INTPROPC)];
this.TXTPROPS = new byte[entryFile.readInt(POS_TXTPROPC)][]; this.TXTPROPS = new byte[entryFile.readInt(POS_TXTPROPC)][];
this.TXTPROPW = entryFile.readInt(POS_TXTPROPW); this.TXTPROPW = entryFile.readInt(POS_TXTPROPW);
@ -404,6 +404,7 @@ public class kelondroRecords {
for (int i = 0; i < COLWIDTHS.length; i++) { for (int i = 0; i < COLWIDTHS.length; i++) {
COLWIDTHS[i] = entryFile.readInt(POS_COLWIDTHS + 4 * i); COLWIDTHS[i] = entryFile.readInt(POS_COLWIDTHS + 4 * i);
} }
this.ROW = new kelondroRow(COLWIDTHS);
for (int i = 0; i < HANDLES.length; i++) { for (int i = 0; i < HANDLES.length; i++) {
HANDLES[i] = new Handle(entryFile.readInt(POS_HANDLES + 4 * i)); HANDLES[i] = new Handle(entryFile.readInt(POS_HANDLES + 4 * i));
} }
@ -416,9 +417,9 @@ public class kelondroRecords {
this.overhead = OHBYTEC + 4 * OHHANDLEC; this.overhead = OHBYTEC + 4 * OHHANDLEC;
this.recordsize = this.overhead; this.recordsize = this.overhead;
this.objectsize = 0; this.objectsize = 0;
for (int i = 0; i < COLWIDTHS.length; i++) this.objectsize += COLWIDTHS[i]; for (int i = 0; i < this.ROW.columns(); i++) this.objectsize += this.ROW.width(i);
this.recordsize = this.overhead + this.objectsize; this.recordsize = this.overhead + this.objectsize;
this.headchunksize = this.overhead + COLWIDTHS[0]; this.headchunksize = this.overhead + this.ROW.width(0);
this.tailchunksize = this.recordsize - this.headchunksize; this.tailchunksize = this.recordsize - this.headchunksize;
} }
@ -741,11 +742,11 @@ public class kelondroRecords {
// set values // set values
if (this.handle.index != NUL) { if (this.handle.index != NUL) {
setValue(row[0], COLWIDTHS[0], headChunk, overhead); setValue(row[0], ROW.width(0), headChunk, overhead);
int offset = 0; int offset = 0;
for (int i = 1; i < row.length; i++) { for (int i = 1; i < row.length; i++) {
setValue(row[i], COLWIDTHS[i], tailChunk, offset); setValue(row[i], ROW.width(i), tailChunk, offset);
offset +=COLWIDTHS[i]; offset +=ROW.width(i);
} }
} }
this.headChanged = true; this.headChanged = true;
@ -755,7 +756,7 @@ public class kelondroRecords {
public byte[] getKey() { public byte[] getKey() {
// read key // read key
return trimCopy(headChunk, overhead, COLWIDTHS[0]); return trimCopy(headChunk, overhead, ROW.width(0));
} }
public byte[][] getValues() throws IOException { public byte[][] getValues() throws IOException {
@ -768,16 +769,16 @@ public class kelondroRecords {
} }
// create return value // create return value
byte[][] values = new byte[COLWIDTHS.length][]; byte[][] values = new byte[ROW.columns()][];
// read key // read key
values[0] = trimCopy(headChunk, overhead, COLWIDTHS[0]); values[0] = trimCopy(headChunk, overhead, ROW.width(0));
// read remaining values // read remaining values
int offset = 0; int offset = 0;
for (int i = 1; i < COLWIDTHS.length; i++) { for (int i = 1; i < ROW.columns(); i++) {
values[i] = trimCopy(tailChunk, offset, COLWIDTHS[i]); values[i] = trimCopy(tailChunk, offset, ROW.width(i));
offset += COLWIDTHS[i]; offset += ROW.width(i);
} }
return values; return values;
@ -1018,13 +1019,17 @@ public class kelondroRecords {
for (int j = 0; j < chunk.length; j++) System.out.print(chunk[j] + ","); for (int j = 0; j < chunk.length; j++) System.out.print(chunk[j] + ",");
} }
public synchronized kelondroRow row() {
return this.ROW;
}
public synchronized int columns() { public synchronized int columns() {
return this.COLWIDTHS.length; return this.ROW.columns();
} }
public synchronized int columnSize(int column) { public synchronized int columnSize(int column) {
if ((column < 0) || (column >= this.COLWIDTHS.length)) return -1; if ((column < 0) || (column >= this.ROW.columns())) return -1;
return this.COLWIDTHS[column]; return ROW.width(column);
} }
private final long seekpos(Handle handle) { private final long seekpos(Handle handle) {
@ -1245,8 +1250,8 @@ public class kelondroRecords {
System.out.println(" Data Offset: 0x" + Long.toHexString(POS_NODES)); System.out.println(" Data Offset: 0x" + Long.toHexString(POS_NODES));
System.out.println("--"); System.out.println("--");
System.out.println("RECORDS"); System.out.println("RECORDS");
System.out.print(" Columns : " + columns() + " columns {" + COLWIDTHS[0]); System.out.print(" Columns : " + columns() + " columns {" + ROW.width(0));
for (int i = 1; i < columns(); i++) System.out.print(", " + COLWIDTHS[i]); for (int i = 1; i < columns(); i++) System.out.print(", " + ROW.width(i));
System.out.println("}"); System.out.println("}");
System.out.println(" Overhead : " + this.overhead + " bytes (" + OHBYTEC + " OH bytes, " + OHHANDLEC + " OH Handles)"); System.out.println(" Overhead : " + this.overhead + " bytes (" + OHBYTEC + " OH bytes, " + OHHANDLEC + " OH Handles)");
System.out.println(" Recordsize : " + this.recordsize + " bytes"); System.out.println(" Recordsize : " + this.recordsize + " bytes");

@ -0,0 +1,57 @@
// kelondroRow.java
// (C) 2006 by Michael Peter Christen; mc@anomic.de, Frankfurt a. M., Germany
// first published 24.05.2006 on http://www.anomic.de
//
// This is a part of the kelondro database,
// which is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
// $LastChangedRevision: 1986 $
// $LastChangedBy: orbiter $
//
// 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
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 kelondroRow {
private kelondroCell[] row;
public kelondroRow(kelondroCell[] row) {
this.row = row;
}
public kelondroRow(int[] row) {
this.row = new kelondroCell[row.length];
for (int i = 0; i < row.length; i++) this.row[i] = new kelondroCell(kelondroCell.celltype_undefined, row[i], "", "");
}
public int columns() {
return this.row.length;
}
public int width(int row) {
return this.row[row].dbwidth();
}
public int[] widths() {
int[] w = new int[this.row.length];
for (int i = 0; i < this.row.length; i++) w[i] = row[i].dbwidth();
return w;
}
}

@ -100,14 +100,14 @@ public final class kelondroStack extends kelondroRecords {
// memorize settings to this file // memorize settings to this file
File f = new File(stack.filename); File f = new File(stack.filename);
long bz = stack.cacheNodeStatus()[0] * stack.cacheNodeChunkSize(true); long bz = stack.cacheNodeStatus()[0] * stack.cacheNodeChunkSize(true);
int[] cols = stack.COLWIDTHS; kelondroRow row = stack.row();
// close and delete the file // close and delete the file
try {stack.close();} catch (Exception e) {}; try {stack.close();} catch (Exception e) {};
if (f.exists()) f.delete(); if (f.exists()) f.delete();
// re-open a database with same settings as before // re-open a database with same settings as before
return new kelondroStack(f, bz, cols, true); return new kelondroStack(f, bz, row.widths(), true);
} }
public class Counter implements Iterator { public class Counter implements Iterator {

Loading…
Cancel
Save