completed and tested kelondroFlexTable

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2166 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent b68f7dec9d
commit 6e49721762

@ -12,6 +12,7 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import de.anomic.kelondro.kelondroBase64Order; import de.anomic.kelondro.kelondroBase64Order;
import de.anomic.kelondro.kelondroFlexTable;
import de.anomic.kelondro.kelondroIndex; import de.anomic.kelondro.kelondroIndex;
import de.anomic.kelondro.kelondroSplittedTree; import de.anomic.kelondro.kelondroSplittedTree;
import de.anomic.kelondro.kelondroTree; import de.anomic.kelondro.kelondroTree;
@ -165,7 +166,7 @@ public class dbtest {
profiler.start(); profiler.start();
// create the database access // create the database access
if (dbe.equals("kelondroold")) { if (dbe.equals("kelondroTree")) {
File tablefile = new File(tablename + ".kelondro.db"); File tablefile = new File(tablename + ".kelondro.db");
if (tablefile.exists()) { if (tablefile.exists()) {
table = new kelondroTree(tablefile, buffer, kelondroTree.defaultObjectCachePercent); table = new kelondroTree(tablefile, buffer, kelondroTree.defaultObjectCachePercent);
@ -173,8 +174,7 @@ public class dbtest {
table = new kelondroTree(tablefile, buffer, kelondroTree.defaultObjectCachePercent, new int[]{keylength, valuelength, valuelength}, true); table = new kelondroTree(tablefile, buffer, kelondroTree.defaultObjectCachePercent, new int[]{keylength, valuelength, valuelength}, true);
} }
} }
if (dbe.equals("kelondroSplittedTree")) {
if (dbe.equals("kelondro")) {
File tablepath = new File(tablename).getParentFile(); File tablepath = new File(tablename).getParentFile();
table = kelondroSplittedTree.open(tablepath, tablename, kelondroBase64Order.enhancedCoder, table = kelondroSplittedTree.open(tablepath, tablename, kelondroBase64Order.enhancedCoder,
buffer, buffer,
@ -182,6 +182,10 @@ public class dbtest {
new int[]{keylength, valuelength, valuelength}, 1, 80, new int[]{keylength, valuelength, valuelength}, 1, 80,
true); true);
} }
if (dbe.equals("kelondroFlexTable")) {
File tablepath = new File(tablename).getParentFile();
table = new kelondroFlexTable(tablepath, new File(tablename).getName(), new kelondroRow(new int[]{keylength, valuelength, valuelength}), true);
}
if (dbe.equals("mysql")) { if (dbe.equals("mysql")) {
table = new dbTable("mysql"); table = new dbTable("mysql");
} }

@ -1,5 +1,30 @@
// kelondroFrexTable.java
// (C) 2006 by Michael Peter Christen; mc@anomic.de, Frankfurt a. M., Germany
// first published 01.06.2006 on http://www.anomic.de
//
// $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; package de.anomic.kelondro;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -13,22 +38,56 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
// fill the index // fill the index
this.index = new HashMap(); this.index = new HashMap();
/*
kelondroFixedWidthArray indexArray = new kelondroFixedWidthArray(new File(path, colfilename(0,0)));
for (int i = 0; i < indexArray.size(); i++) index.put(indexArray.get(i).getColBytes(0), new Integer(i));
indexArray.close();
*/
for (int i = 0; i < super.col[0].size(); i++) index.put(super.col[0].get(i).getColBytes(0), new Integer(i));
}
/*
private final static byte[] read(File source) throws IOException {
byte[] buffer = new byte[(int) source.length()];
InputStream fis = null;
try {
fis = new FileInputStream(source);
int p = 0, c;
while ((c = fis.read(buffer, p, buffer.length - p)) > 0) p += c;
} finally {
if (fis != null) try { fis.close(); } catch (Exception e) {}
} }
return buffer;
}
*/
public int columnSize(int column) { public int columnSize(int column) {
return rowdef.width(column); return rowdef.width(column);
} }
public kelondroRow.Entry get(byte[] key) throws IOException { public kelondroRow.Entry get(byte[] key) throws IOException {
return null; Integer i = (Integer) this.index.get(key);
if (i == null) return null;
return super.get(i.intValue());
} }
public byte[][] put(byte[][] row) throws IOException { public byte[][] put(byte[][] row) throws IOException {
Integer i = (Integer) this.index.get(row[0]);
if (i == null) {
i = new Integer(super.add(super.rowdef.newEntry(row)));
this.index.put(row[0], i);
return null; return null;
} else {
return super.set(i.intValue(), super.rowdef.newEntry(row)).getCols();
}
} }
public byte[][] remove(byte[] key) throws IOException { public byte[][] remove(byte[] key) throws IOException {
return null; Integer i = (Integer) this.index.get(key);
if (i == null) return null;
byte[][] r = super.get(i.intValue()).getCols();
super.remove(i.intValue());
return r;
} }
} }

@ -40,12 +40,19 @@ public class kelondroFlexWidthArray implements kelondroArray {
col = new kelondroFixedWidthArray[rowdef.columns()]; col = new kelondroFixedWidthArray[rowdef.columns()];
String check = ""; String check = "";
for (int i = 0; i < rowdef.columns(); i++) { for (int i = 0; i < rowdef.columns(); i++) {
col = null; col[i] = null;
check += '_'; check += '_';
} }
// open existing files // open existing files
String[] files = path.list(); File tabledir = new File(path, tablename + ".table");
if (tabledir.exists()) {
if (!(tabledir.isDirectory())) throw new IOException("path " + tabledir.toString() + " must be a directory");
} else {
tabledir.mkdirs();
tabledir.mkdir();
}
String[] files = tabledir.list();
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
if ((files[i].startsWith("col.") && (files[i].endsWith(".list")))) { if ((files[i].startsWith("col.") && (files[i].endsWith(".list")))) {
int colstart = Integer.parseInt(files[i].substring(4, 7)); int colstart = Integer.parseInt(files[i].substring(4, 7));
@ -55,7 +62,7 @@ public class kelondroFlexWidthArray implements kelondroArray {
for (int j = colstart; j <= colend; j++) columns[j-colstart] = rowdef.width(j); for (int j = colstart; j <= colend; j++) columns[j-colstart] = rowdef.width(j);
col[colstart] = new kelondroFixedWidthArray(new File(path, files[i]), columns, 0, true); col[colstart] = new kelondroFixedWidthArray(new File(path, files[i]), columns, 0, true);
*/ */
col[colstart] = new kelondroFixedWidthArray(new File(path, files[i])); col[colstart] = new kelondroFixedWidthArray(new File(tabledir, files[i]));
for (int j = colstart; j <= colend; j++) check = check.substring(0, j) + "X" + check.substring(j + 1); for (int j = colstart; j <= colend; j++) check = check.substring(0, j) + "X" + check.substring(j + 1);
} }
} }
@ -64,14 +71,17 @@ public class kelondroFlexWidthArray implements kelondroArray {
int p, q; int p, q;
while ((p = check.indexOf('_')) >= 0) { while ((p = check.indexOf('_')) >= 0) {
q = p; q = p;
if (p != 0) while ((check.charAt(q) == '_') && (q <= check.length() - 1)) q++; if (p != 0) {
while ((q <= check.length() - 1) && (check.charAt(q) == '_')) q++;
q--;
}
// create new array file // create new array file
int columns[] = new int[q - p + 1]; int columns[] = new int[q - p + 1];
for (int j = p; j <= q; j++) { for (int j = p; j <= q; j++) {
columns[j - p] = rowdef.width(j); columns[j - p] = rowdef.width(j);
check = check.substring(0, j) + "X" + check.substring(j + 1); check = check.substring(0, j) + "X" + check.substring(j + 1);
} }
col[p] = new kelondroFixedWidthArray(new File(path, colfilename(p, q)), columns, 0, true); col[p] = new kelondroFixedWidthArray(new File(tabledir, colfilename(p, q)), columns, 16, true);
} }
} }
@ -92,55 +102,73 @@ public class kelondroFlexWidthArray implements kelondroArray {
return rowdef.columns(); return rowdef.columns();
} }
public synchronized kelondroRow.Entry set(int index, kelondroRow.Entry rowentry) throws IOException { public kelondroRow.Entry set(int index, kelondroRow.Entry rowentry) throws IOException {
int r = 0; int r = 0;
kelondroRow.Entry e0, e1, p; kelondroRow.Entry e0, e1, p;
p = rowdef.newEntry(); p = rowdef.newEntry();
synchronized (col) {
while (r < rowdef.columns()) { while (r < rowdef.columns()) {
e0 = col[r].row().newEntry(rowentry.bytes(), rowdef.colstart[r], rowdef.colstart[r] - rowdef.colstart[r + col[r].columns() - 1] + rowdef.width(r)); e0 = col[r].row().newEntry(
rowentry.bytes(),
rowdef.colstart[r],
rowdef.colstart[r]
- rowdef.colstart[r + col[r].columns() - 1]
+ rowdef.width(r));
e1 = col[r].set(index, e0); e1 = col[r].set(index, e0);
for (int i = 0; i < col[r].columns(); i++) for (int i = 0; i < col[r].columns(); i++)
p.setCol(r + i, e1.getColBytes(i)); p.setCol(r + i, e1.getColBytes(i));
r = r + col[r].columns(); r = r + col[r].columns();
} }
}
return p; return p;
} }
public synchronized kelondroRow.Entry get(int index) throws IOException { public kelondroRow.Entry get(int index) throws IOException {
int r = 0; int r = 0;
kelondroRow.Entry e, p; kelondroRow.Entry e, p;
p = rowdef.newEntry(); p = rowdef.newEntry();
synchronized (col) {
while (r < rowdef.columns()) { while (r < rowdef.columns()) {
e = col[r].get(index); e = col[r].get(index);
for (int i = 0; i < col[r].columns(); i++) for (int i = 0; i < col[r].columns(); i++)
p.setCol(r + i, e.getColBytes(i)); p.setCol(r + i, e.getColBytes(i));
r = r + col[r].columns(); r = r + col[r].columns();
} }
}
return p; return p;
} }
public synchronized int add(kelondroRow.Entry rowentry) throws IOException { public int add(kelondroRow.Entry rowentry) throws IOException {
kelondroRow.Entry e; kelondroRow.Entry e;
int index = -1;
e = col[0].row().newEntry(rowentry.bytes(), rowdef.colstart[0], rowdef.colstart[0] - rowdef.colstart[col[0].columns() - 1] + rowdef.width(0)); synchronized (col) {
int index = col[0].add(e); e = col[0].row().newEntry(rowentry.bytes(), 0, rowdef.width(0));
index = col[0].add(e);
int r = col[0].columns(); int r = col[0].columns();
while (r < rowdef.columns()) { while (r < rowdef.columns()) {
e = col[r].row().newEntry(rowentry.bytes(), rowdef.colstart[r], rowdef.colstart[r] - rowdef.colstart[r + col[r].columns() - 1] + rowdef.width(r)); e = col[r].row().newEntry(
rowentry.bytes(),
rowdef.colstart[r],
rowdef.colstart[r + col[r].columns() - 1]
+ rowdef.width(r + col[r].columns() - 1)
- rowdef.colstart[r]);
col[r].set(index, e); col[r].set(index, e);
r = r + col[r].columns(); r = r + col[r].columns();
} }
}
return index; return index;
} }
public synchronized void remove(int index) throws IOException { public void remove(int index) throws IOException {
int r = 0; int r = 0;
synchronized (col) {
while (r < rowdef.columns()) { while (r < rowdef.columns()) {
col[r].remove(index); col[r].remove(index);
r = r + col[r].columns(); r = r + col[r].columns();
} }
} }
}
public void print() throws IOException { public void print() throws IOException {
System.out.println("PRINTOUT of table, length=" + size()); System.out.println("PRINTOUT of table, length=" + size());

@ -119,7 +119,7 @@ public class kelondroRow {
public Entry newEntry(byte[] rowinstance, int start, int length) { public Entry newEntry(byte[] rowinstance, int start, int length) {
if (rowinstance == null) return null; if (rowinstance == null) return null;
return new Entry(rowinstance); return new Entry(rowinstance, start, length);
} }
public Entry newEntry(byte[][] cells) { public Entry newEntry(byte[][] cells) {

Loading…
Cancel
Save