Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
completed and tested kelondroFlexTable
orbiter6e49721762c4
diff --git a/source/dbtest.java b/source/dbtest.javaindex bde548357..af7049e95 100644--- a/source/dbtest.java+++ b/source/dbtest.java@@ -12,6 +12,7 @@ import java.util.Date;import java.util.Iterator;import de.anomic.kelondro.kelondroBase64Order;+import de.anomic.kelondro.kelondroFlexTable;import de.anomic.kelondro.kelondroIndex;import de.anomic.kelondro.kelondroSplittedTree;import de.anomic.kelondro.kelondroTree;@@ -165,7 +166,7 @@ public class dbtest {profiler.start();// create the database access- if (dbe.equals("kelondroold")) {+ if (dbe.equals("kelondroTree")) {File tablefile = new File(tablename + ".kelondro.db");if (tablefile.exists()) {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);}}-- if (dbe.equals("kelondro")) {+ if (dbe.equals("kelondroSplittedTree")) {File tablepath = new File(tablename).getParentFile();table = kelondroSplittedTree.open(tablepath, tablename, kelondroBase64Order.enhancedCoder,buffer,@@ -182,6 +182,10 @@ public class dbtest {new int[]{keylength, valuelength, valuelength}, 1, 80,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")) {table = new dbTable("mysql");}diff --git a/source/de/anomic/kelondro/kelondroFlexTable.java b/source/de/anomic/kelondro/kelondroFlexTable.javaindex 8ba7bb3a7..b88353f7f 100644--- a/source/de/anomic/kelondro/kelondroFlexTable.java+++ b/source/de/anomic/kelondro/kelondroFlexTable.java@@ -1,5 +1,30 @@+// kelondroFrexTable.java+// (C) 2006 by Michael Peter Christen; [email protected], 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;+import java.io.File;import java.io.IOException;import java.util.HashMap;@@ -13,22 +38,56 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr// fill the indexthis.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) {return rowdef.width(column);}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 {- return null;+ 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;+ } else {+ return super.set(i.intValue(), super.rowdef.newEntry(row)).getCols();+ }}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;}}diff --git a/source/de/anomic/kelondro/kelondroFlexWidthArray.java b/source/de/anomic/kelondro/kelondroFlexWidthArray.javaindex 43c06e08f..9bae107e8 100644--- a/source/de/anomic/kelondro/kelondroFlexWidthArray.java+++ b/source/de/anomic/kelondro/kelondroFlexWidthArray.java@@ -40,12 +40,19 @@ public class kelondroFlexWidthArray implements kelondroArray {col = new kelondroFixedWidthArray[rowdef.columns()];String check = "";for (int i = 0; i < rowdef.columns(); i++) {- col = null;+ col[i] = null;check += '_';}// 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++) {if ((files[i].startsWith("col.") && (files[i].endsWith(".list")))) {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);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);}}@@ -64,14 +71,17 @@ public class kelondroFlexWidthArray implements kelondroArray {int p, q;while ((p = check.indexOf('_')) >= 0) {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 fileint columns[] = new int[q - p + 1];for (int j = p; j <= q; j++) {columns[j - p] = rowdef.width(j);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,53 +102,71 @@ public class kelondroFlexWidthArray implements kelondroArray {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;kelondroRow.Entry e0, e1, p;p = rowdef.newEntry();- 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));- e1 = col[r].set(index, e0);- for (int i = 0; i < col[r].columns(); i++)- p.setCol(r + i, e1.getColBytes(i));- r = r + col[r].columns();+ synchronized (col) {+ 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));+ e1 = col[r].set(index, e0);+ for (int i = 0; i < col[r].columns(); i++)+ p.setCol(r + i, e1.getColBytes(i));+ r = r + col[r].columns();+ }}return p;}- public synchronized kelondroRow.Entry get(int index) throws IOException {+ public kelondroRow.Entry get(int index) throws IOException {int r = 0;kelondroRow.Entry e, p;p = rowdef.newEntry();- while (r < rowdef.columns()) {- e = col[r].get(index);- for (int i = 0; i < col[r].columns(); i++)- p.setCol(r + i, e.getColBytes(i));- r = r + col[r].columns();+ synchronized (col) {+ while (r < rowdef.columns()) {+ e = col[r].get(index);+ for (int i = 0; i < col[r].columns(); i++)+ p.setCol(r + i, e.getColBytes(i));+ r = r + col[r].columns();+ }}return p;}- public synchronized int add(kelondroRow.Entry rowentry) throws IOException {+ public int add(kelondroRow.Entry rowentry) throws IOException {kelondroRow.Entry e;-- e = col[0].row().newEntry(rowentry.bytes(), rowdef.colstart[0], rowdef.colstart[0] - rowdef.colstart[col[0].columns() - 1] + rowdef.width(0));- int index = col[0].add(e);- int r = col[0].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));- col[r].set(index, e);- r = r + col[r].columns();+ int index = -1;+ synchronized (col) {+ e = col[0].row().newEntry(rowentry.bytes(), 0, rowdef.width(0));+ index = col[0].add(e);+ int r = col[0].columns();++ while (r < rowdef.columns()) {+ 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);+ r = r + col[r].columns();+ }}return index;}- public synchronized void remove(int index) throws IOException {+ public void remove(int index) throws IOException {int r = 0;- while (r < rowdef.columns()) {- col[r].remove(index);- r = r + col[r].columns();+ synchronized (col) {+ while (r < rowdef.columns()) {+ col[r].remove(index);+ r = r + col[r].columns();+ }}}diff --git a/source/de/anomic/kelondro/kelondroRow.java b/source/de/anomic/kelondro/kelondroRow.javaindex e97e29d79..b7b9ba187 100644--- a/source/de/anomic/kelondro/kelondroRow.java+++ b/source/de/anomic/kelondro/kelondroRow.java@@ -119,7 +119,7 @@ public class kelondroRow {public Entry newEntry(byte[] rowinstance, int start, int length) {if (rowinstance == null) return null;- return new Entry(rowinstance);+ return new Entry(rowinstance, start, length);}public Entry newEntry(byte[][] cells) {