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

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

@ -18,17 +18,45 @@ public class indexCollectionRI extends indexAbstractRI implements indexRI {
collectionIndex = new kelondroCollectionIndex( collectionIndex = new kelondroCollectionIndex(
path, filenameStub, 9 /*keyLength*/, path, filenameStub, 9 /*keyLength*/,
kelondroNaturalOrder.naturalOrder, buffersize, kelondroNaturalOrder.naturalOrder, buffersize,
1 /*loadfactor*/, rowdef, 8 /*partitions*/); 4 /*loadfactor*/, rowdef, 8 /*partitions*/);
} }
public int size() { public int size() {
// TODO Auto-generated method stub try {
return 0; return collectionIndex.size();
} catch (IOException e) {
e.printStackTrace();
return 0;
}
} }
public Iterator wordHashes(String startWordHash, boolean rot) { public Iterator wordHashes(String startWordHash, boolean rot) {
// TODO Auto-generated method stub return new wordHashIterator(startWordHash, rot);
return null; }
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) { public indexContainer getContainer(String wordHash, boolean deleteIfEmpty, long maxtime) {

@ -116,6 +116,10 @@ public class kelondroCollectionIndex {
throw new kelondroOutOfLimitsException(maxChunks, requestedCapacity); throw new kelondroOutOfLimitsException(maxChunks, requestedCapacity);
} }
public int size() throws IOException {
return index.size();
}
public void put(byte[] key, kelondroRowCollection collection) throws IOException, kelondroOutOfLimitsException { public void put(byte[] key, kelondroRowCollection collection) throws IOException, kelondroOutOfLimitsException {
if (collection.size() > maxChunks) throw new kelondroOutOfLimitsException(maxChunks, collection.size()); if (collection.size() > maxChunks) throw new kelondroOutOfLimitsException(maxChunks, collection.size());
@ -211,11 +215,6 @@ public class kelondroCollectionIndex {
array[partitionnumber].remove(rownumber); array[partitionnumber].remove(rownumber);
} }
/*
public Iterator collections(boolean up, boolean rotating) throws IOException {
// Objects are of type kelondroRowCollection
}
*/
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(new java.util.Date(10957 * day)); System.out.println(new java.util.Date(10957 * day));

@ -131,80 +131,7 @@ public class kelondroFixedWidthArray extends kelondroRecords implements kelondro
System.out.println("EndOfTable"); 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) { public static void main(String[] args) {
//cmd(args);
File f = new File("d:\\\\mc\\privat\\fixtest.db"); File f = new File("d:\\\\mc\\privat\\fixtest.db");
f.delete(); f.delete();
kelondroFixedWidthArray k = new kelondroFixedWidthArray(f, new kelondroRow(new int[]{12, 4}), 6, true); kelondroFixedWidthArray k = new kelondroFixedWidthArray(f, new kelondroRow(new int[]{12, 4}), 6, true);

@ -59,5 +59,6 @@ public interface kelondroIndex {
public kelondroRow.Entry get(byte[] key) throws IOException; public kelondroRow.Entry get(byte[] key) throws IOException;
public kelondroRow.Entry put(kelondroRow.Entry row) throws IOException; public kelondroRow.Entry put(kelondroRow.Entry row) throws IOException;
public kelondroRow.Entry remove(byte[] key) throws IOException; public kelondroRow.Entry remove(byte[] key) throws IOException;
//public Iterator rows(boolean up, boolean rotating, byte[] firstKey) throws IOException;
} }

@ -24,6 +24,7 @@
package de.anomic.kelondro; package de.anomic.kelondro;
import java.io.IOException;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
@ -245,6 +246,8 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
} }
private int binarySearch(byte[] key, int astart, int alength) { 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); assert (this.sortOrder != null);
int l = 0; int l = 0;
int rbound = this.sortBound; int rbound = this.sortBound;
@ -260,6 +263,25 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
return -1; 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) { private int compare(byte[] a, int astart, int alength, int chunknumber) {
assert (chunknumber < chunkcount); assert (chunknumber < chunkcount);
int l = Math.min(this.rowdef.width(0), Math.min(a.length - astart, alength)); 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; 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) { public static void main(String[] args) {
/* /*
String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" }; String[] test = { "eins", "zwei", "drei", "vier", "fuenf", "sechs", "sieben", "acht", "neun", "zehn" };

Loading…
Cancel
Save