Skip to content

Commit

Permalink
integrated cell-, and row-management classes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
orbiter committed May 24, 2006
1 parent 4d8f8ba commit 899c1a5
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 24 deletions.
65 changes: 65 additions & 0 deletions source/de/anomic/kelondro/kelondroCell.java
@@ -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;
}
}
49 changes: 27 additions & 22 deletions source/de/anomic/kelondro/kelondroRecords.java
Expand Up @@ -143,7 +143,7 @@ public class kelondroRecords {
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 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 byte[] TXTPROPS[]; // array with text properties
private int TXTPROPW; // size of a single TXTPROPS element
Expand Down Expand Up @@ -264,7 +264,7 @@ private void init(kelondroRA ra, short ohbytec, short ohhandlec,
USAGE = new usageControl(0, 0, new Handle(NUL));
OHBYTEC = ohbytec;
OHHANDLEC = ohhandlec;
COLWIDTHS = columns;
ROW = new kelondroRow(columns);
HANDLES = new Handle[FHandles];
for (int i = 0; i < FHandles; i++) HANDLES[i] = new Handle(NUL);
TXTPROPS = new byte[txtProps][];
Expand All @@ -276,7 +276,7 @@ private void init(kelondroRA ra, short ohbytec, short ohhandlec,
entryFile.writeByte(POS_BUSY, 0); // unlock: default
entryFile.writeShort(POS_PORT, 4444); // default port (not used yet)
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_OHHANDLEC, OHHANDLEC);
entryFile.writeInt(POS_USEDC, this.USAGE.USEDC);
Expand All @@ -290,8 +290,8 @@ private void init(kelondroRA ra, short ohbytec, short ohhandlec,
entryFile.writeInt(POS_TXTPROPW, txtPropWidth);

// write configuration arrays
for (int i = 0; i < this.COLWIDTHS.length; i++) {
entryFile.writeInt(POS_COLWIDTHS + 4 * i, COLWIDTHS[i]);
for (int i = 0; i < this.ROW.columns(); i++) {
entryFile.writeInt(POS_COLWIDTHS + 4 * i, this.ROW.width(i));
}
for (int i = 0; i < this.HANDLES.length; i++) {
entryFile.writeInt(POS_HANDLES + 4 * i, NUL);
Expand Down Expand Up @@ -388,7 +388,7 @@ private void init(kelondroRA ra, long writeBufferSize) throws IOException {
this.OHBYTEC = entryFile.readShort(POS_OHBYTEC);
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.TXTPROPS = new byte[entryFile.readInt(POS_TXTPROPC)][];
this.TXTPROPW = entryFile.readInt(POS_TXTPROPW);
Expand All @@ -404,6 +404,7 @@ private void init(kelondroRA ra, long writeBufferSize) throws IOException {
for (int i = 0; i < COLWIDTHS.length; i++) {
COLWIDTHS[i] = entryFile.readInt(POS_COLWIDTHS + 4 * i);
}
this.ROW = new kelondroRow(COLWIDTHS);
for (int i = 0; i < HANDLES.length; i++) {
HANDLES[i] = new Handle(entryFile.readInt(POS_HANDLES + 4 * i));
}
Expand All @@ -416,9 +417,9 @@ private void init(kelondroRA ra, long writeBufferSize) throws IOException {
this.overhead = OHBYTEC + 4 * OHHANDLEC;
this.recordsize = this.overhead;
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.headchunksize = this.overhead + COLWIDTHS[0];
this.headchunksize = this.overhead + this.ROW.width(0);
this.tailchunksize = this.recordsize - this.headchunksize;
}

Expand Down Expand Up @@ -741,11 +742,11 @@ public byte[][] setValues(byte[][] row) throws IOException {

// set values
if (this.handle.index != NUL) {
setValue(row[0], COLWIDTHS[0], headChunk, overhead);
setValue(row[0], ROW.width(0), headChunk, overhead);
int offset = 0;
for (int i = 1; i < row.length; i++) {
setValue(row[i], COLWIDTHS[i], tailChunk, offset);
offset +=COLWIDTHS[i];
setValue(row[i], ROW.width(i), tailChunk, offset);
offset +=ROW.width(i);
}
}
this.headChanged = true;
Expand All @@ -755,7 +756,7 @@ public byte[][] setValues(byte[][] row) throws IOException {

public byte[] getKey() {
// read key
return trimCopy(headChunk, overhead, COLWIDTHS[0]);
return trimCopy(headChunk, overhead, ROW.width(0));
}

public byte[][] getValues() throws IOException {
Expand All @@ -768,16 +769,16 @@ public byte[][] getValues() throws IOException {
}

// create return value
byte[][] values = new byte[COLWIDTHS.length][];
byte[][] values = new byte[ROW.columns()][];

// read key
values[0] = trimCopy(headChunk, overhead, COLWIDTHS[0]);
values[0] = trimCopy(headChunk, overhead, ROW.width(0));

// read remaining values
int offset = 0;
for (int i = 1; i < COLWIDTHS.length; i++) {
values[i] = trimCopy(tailChunk, offset, COLWIDTHS[i]);
offset += COLWIDTHS[i];
for (int i = 1; i < ROW.columns(); i++) {
values[i] = trimCopy(tailChunk, offset, ROW.width(i));
offset += ROW.width(i);
}

return values;
Expand Down Expand Up @@ -1018,13 +1019,17 @@ private void printChunk(Handle handle, byte[] chunk) {
for (int j = 0; j < chunk.length; j++) System.out.print(chunk[j] + ",");
}

public synchronized kelondroRow row() {
return this.ROW;
}

public synchronized int columns() {
return this.COLWIDTHS.length;
return this.ROW.columns();
}

public synchronized int columnSize(int column) {
if ((column < 0) || (column >= this.COLWIDTHS.length)) return -1;
return this.COLWIDTHS[column];
if ((column < 0) || (column >= this.ROW.columns())) return -1;
return ROW.width(column);
}

private final long seekpos(Handle handle) {
Expand Down Expand Up @@ -1245,8 +1250,8 @@ public void print(boolean records) throws IOException {
System.out.println(" Data Offset: 0x" + Long.toHexString(POS_NODES));
System.out.println("--");
System.out.println("RECORDS");
System.out.print(" Columns : " + columns() + " columns {" + COLWIDTHS[0]);
for (int i = 1; i < columns(); i++) System.out.print(", " + COLWIDTHS[i]);
System.out.print(" Columns : " + columns() + " columns {" + ROW.width(0));
for (int i = 1; i < columns(); i++) System.out.print(", " + ROW.width(i));
System.out.println("}");
System.out.println(" Overhead : " + this.overhead + " bytes (" + OHBYTEC + " OH bytes, " + OHHANDLEC + " OH Handles)");
System.out.println(" Recordsize : " + this.recordsize + " bytes");
Expand Down
57 changes: 57 additions & 0 deletions source/de/anomic/kelondro/kelondroRow.java
@@ -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;
}

}
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroStack.java
Expand Up @@ -100,14 +100,14 @@ public static kelondroStack reset(kelondroStack stack) {
// memorize settings to this file
File f = new File(stack.filename);
long bz = stack.cacheNodeStatus()[0] * stack.cacheNodeChunkSize(true);
int[] cols = stack.COLWIDTHS;
kelondroRow row = stack.row();

// close and delete the file
try {stack.close();} catch (Exception e) {};
if (f.exists()) f.delete();

// 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 {
Expand Down

0 comments on commit 899c1a5

Please sign in to comment.