Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

some work in the index construction zone (no effect yet)

orbiterce9dd3e76daa
diff --git a/source/de/anomic/index/indexCollectionRI.java b/source/de/anomic/index/indexCollectionRI.java
index ed425e0ac..2b70c9d15 100644
--- a/source/de/anomic/index/indexCollectionRI.java
+++ b/source/de/anomic/index/indexCollectionRI.java
@@ -18,19 +18,47 @@ public class indexCollectionRI extends indexAbstractRI implements indexRI {
collectionIndex = new kelondroCollectionIndex(
path, filenameStub, 9 /*keyLength*/,
kelondroNaturalOrder.naturalOrder, buffersize,
- 1 /*loadfactor*/, rowdef, 8 /*partitions*/);
+ 4 /*loadfactor*/, rowdef, 8 /*partitions*/);
}
public int size() {
- // TODO Auto-generated method stub
- return 0;
+ try {
+ return collectionIndex.size();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return 0;
+ }
}
public Iterator wordHashes(String startWordHash, boolean rot) {
- // TODO Auto-generated method stub
- return null;
+ return new wordHashIterator(startWordHash, rot);
}
+ public class wordHashIterator implements Iterator {
+
+ //private Iterator whi;
+
+ public wordHashIterator(String startWordHash, boolean rot) {
+
+ }
+
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Object next() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void remove() {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
public indexContainer getContainer(String wordHash, boolean deleteIfEmpty, long maxtime) {
// TODO Auto-generated method stub
return null;
diff --git a/source/de/anomic/kelondro/kelondroCollectionIndex.java b/source/de/anomic/kelondro/kelondroCollectionIndex.java
index 61d2cf4e6..fc5372705 100644
--- a/source/de/anomic/kelondro/kelondroCollectionIndex.java
+++ b/source/de/anomic/kelondro/kelondroCollectionIndex.java
@@ -116,6 +116,10 @@ public class kelondroCollectionIndex {
throw new kelondroOutOfLimitsException(maxChunks, requestedCapacity);
}
+ public int size() throws IOException {
+ return index.size();
+ }
+
public void put(byte[] key, kelondroRowCollection collection) throws IOException, kelondroOutOfLimitsException {
if (collection.size() > maxChunks) throw new kelondroOutOfLimitsException(maxChunks, collection.size());
@@ -210,12 +214,7 @@ public class kelondroCollectionIndex {
// remove array entry
array[partitionnumber].remove(rownumber);
}
-
- /*
- public Iterator collections(boolean up, boolean rotating) throws IOException {
- // Objects are of type kelondroRowCollection
- }
- */
+
public static void main(String[] args) {
System.out.println(new java.util.Date(10957 * day));
diff --git a/source/de/anomic/kelondro/kelondroFixedWidthArray.java b/source/de/anomic/kelondro/kelondroFixedWidthArray.java
index f00185985..0f3edcd3e 100644
--- a/source/de/anomic/kelondro/kelondroFixedWidthArray.java
+++ b/source/de/anomic/kelondro/kelondroFixedWidthArray.java
@@ -130,81 +130,8 @@ public class kelondroFixedWidthArray extends kelondroRecords implements kelondro
}
System.out.println("EndOfTable");
}
-
- private static void cmd(String[] args) {
- /*
- java -classpath classes de.anomic.kelondro.kelondroArray -c testarray.array 40
- java -classpath classes de.anomic.kelondro.kelondroArray -v testarray.array
-
- */
- System.out.print("kelondroArray ");
- for (int i = 0; i < args.length; i++) System.out.print(args[i] + " ");
- System.out.println("");
- try {
- if ((args.length == 3) && (args[0].equals("-c"))) {
- // create <filename> <valuelen>
- File f = new File(args[1]);
- if (f.exists()) f.delete();
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(f, new kelondroRow(new int[]{Integer.parseInt(args[2])}), 2, true);
- fm.close();
- } else
- if ((args.length == 2) && (args[0].equals("-v"))) {
- // view <filename>
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(new File(args[1]));
- fm.print();
- fm.print(true);
- fm.close();
- } else
- if ((args.length == 3) && (args[0].equals("-g"))) {
- // get <filename> <index>
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(new File(args[1]));
- kelondroRow.Entry row = fm.get(Integer.parseInt(args[2]));
- for (int j = 0; j < fm.row().columns(); j++) System.out.print(row.getColString(j, null) + " ");
- System.out.println();
- fm.close();
- } else
- if ((args.length == 4) && (args[0].equals("-s"))) {
- // set <filename> <index> <value>
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(new File(args[1]));
- kelondroRow.Entry row = fm.row().newEntry(new byte[][]{args[3].getBytes()});
- fm.set(Integer.parseInt(args[2]), row);
- fm.close();
- } else
- if ((args.length == 3) && (args[0].equals("-a"))) {
- // add <filename> <value>
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(new File(args[1]));
- kelondroRow.Entry row = fm.row().newEntry(new byte[][] {args[2].getBytes()});
- int index = fm.add(row);
- System.out.println("Added to row " + index);
- fm.close();
- } else
- if ((args.length == 3) && (args[0].equals("-d"))) {
- // delete <filename> <index>
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(new File(args[1]));
- fm.remove(Integer.parseInt(args[2]));
- fm.close();
- } else
- if ((args.length == 1) && (args[0].equals("-test"))) {
- File testfile = new File("test.array");
- if (testfile.exists()) testfile.delete();
- kelondroFixedWidthArray fm = new kelondroFixedWidthArray(testfile, new kelondroRow(new int[]{30, 50}), 9, true);
- for (int i = 0; i < 100; i++) {
- fm.set(i, fm.row().newEntry(new byte[][]{("name" + i).getBytes(), ("value" + i).getBytes()}));
- }
- fm.close();
- } else
- {
- System.err.println("usage: kelondroArray -c|-v|-s|-g [file]|[index [value]] <db-file>");
- System.err.println("( create, view, set, get)");
- System.exit(0);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
public static void main(String[] args) {
- //cmd(args);
File f = new File("d:\\\\mc\\privat\\fixtest.db");
f.delete();
kelondroFixedWidthArray k = new kelondroFixedWidthArray(f, new kelondroRow(new int[]{12, 4}), 6, true);
diff --git a/source/de/anomic/kelondro/kelondroIndex.java b/source/de/anomic/kelondro/kelondroIndex.java
index 0d3459ee7..7e1ae61c7 100644
--- a/source/de/anomic/kelondro/kelondroIndex.java
+++ b/source/de/anomic/kelondro/kelondroIndex.java
@@ -59,5 +59,6 @@ public interface kelondroIndex {
public kelondroRow.Entry get(byte[] key) throws IOException;
public kelondroRow.Entry put(kelondroRow.Entry row) throws IOException;
public kelondroRow.Entry remove(byte[] key) throws IOException;
-
+ //public Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException;
+
}
diff --git a/source/de/anomic/kelondro/kelondroRowSet.java b/source/de/anomic/kelondro/kelondroRowSet.java
index bf0a2e13b..b07f3a6d0 100644
--- a/source/de/anomic/kelondro/kelondroRowSet.java
+++ b/source/de/anomic/kelondro/kelondroRowSet.java
@@ -24,6 +24,7 @@
package de.anomic.kelondro;
+import java.io.IOException;
import java.util.TreeSet;
import java.util.Iterator;
import java.util.Random;
@@ -245,6 +246,8 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
}
private int binarySearch(byte[] key, int astart, int alength) {
+ // returns the exact position of the key if the key exists,
+ // or -1 if the key does not exist
assert (this.sortOrder != null);
int l = 0;
int rbound = this.sortBound;
@@ -260,6 +263,25 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
return -1;
}
+ private int binaryPosition(byte[] key, int astart, int alength) {
+ // returns the exact position of the key if the key exists,
+ // or a position of an entry that is greater than the key if the
+ // key does not exist
+ assert (this.sortOrder != null);
+ int l = 0;
+ int rbound = this.sortBound;
+ int p = 0;
+ int d;
+ while (l < rbound) {
+ p = l + ((rbound - l) >> 1);
+ d = compare(key, astart, alength, p);
+ if (d == 0) return p;
+ else if (d < 0) rbound = p;
+ else l = p + 1;
+ }
+ return l;
+ }
+
private int compare(byte[] a, int astart, int alength, int chunknumber) {
assert (chunknumber < chunkcount);
int l = Math.min(this.rowdef.width(0), Math.min(a.length - astart, alength));
@@ -279,6 +301,54 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
return profile;
}
+ public Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException {
+ return new rowIterator(up, rotating, firstKey);
+ }
+
+ public class rowIterator implements Iterator {
+
+ private boolean up, rot;
+ private byte[] first;
+ private int p, bound;
+
+ public rowIterator(boolean up, boolean rotating, byte[] firstKey) {
+ this.up = up;
+ this.rot = rotating;
+ this.first = firstKey;
+ this.bound = sortBound;
+ // see that all elements are sorted
+ shape();
+ if (first == null) {
+ p = 0;
+ } else {
+ p = binaryPosition(first, 0, first.length);
+ }
+ }
+
+ public boolean hasNext() {
+ if (rot) return true;
+ if (up) {
+ return p < bound;
+ } else {
+ return p >= 0;
+ }
+ }
+
+ public Object next() {
+ kelondroRow.Entry entry = get(p);
+ if (up) p++; else p--;
+ if (rot) {
+ if (p == bound) p = 0;
+ if (p < 0) p = bound - 1;
+ }
+ return entry;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
public static void main(String[] args) {
/*
String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" };