- added signatures to ordering

- added storage of orderings to database
- orderings can be read from database when opening a database

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

@ -83,6 +83,22 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond
ahpla = (rfc1113compliant) ? ahpla_standard : ahpla_enhanced;
}
public static kelondroOrder bySignature(String signature) {
if (signature.equals("Bd")) return new kelondroBase64Order(false, false);
if (signature.equals("bd")) return new kelondroBase64Order(false, true);
if (signature.equals("Bu")) return new kelondroBase64Order(true, false);
if (signature.equals("du")) return new kelondroBase64Order(true, true);
return null;
}
public String signature() {
if ((!asc) && (!rfc1113compliant)) return "Bd";
if ((!asc) && ( rfc1113compliant)) return "bd";
if (( asc) && (!rfc1113compliant)) return "Bu";
if (( asc) && ( rfc1113compliant)) return "bu";
return null;
}
public char encodeByte(byte b) {
return (char) alpha[b];
}
@ -260,5 +276,6 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond
System.out.println(b64.decodeString(s[1]));
}
}
}

@ -70,8 +70,12 @@ public class kelondroDyn extends kelondroTree {
private int segmentCount;
public kelondroDyn(File file, long buffersize /*bytes*/, int key, int nodesize, boolean exitOnFail) {
this(file, buffersize, key, nodesize, new kelondroNaturalOrder(true), exitOnFail);
}
public kelondroDyn(File file, long buffersize /*bytes*/, int key, int nodesize, kelondroOrder objectOrder, boolean exitOnFail) {
// creates a new dynamic tree
super(file, buffersize, new int[] {key + counterlen, nodesize}, 1, 8, exitOnFail);
super(file, buffersize, new int[] {key + counterlen, nodesize}, objectOrder, 1, 8, exitOnFail);
this.keylen = columnSize(0) - counterlen;
this.reclen = columnSize(1);
this.segmentCacheKey = null;

@ -61,7 +61,7 @@ public class kelondroFScoreCluster {
private kelondroTree refcountDB;
private kelondroTree countrefDB;
public kelondroFScoreCluster(File refcountDBfile, File countrefDBfile, boolean exitOnFail) {
public kelondroFScoreCluster(File refcountDBfile, File countrefDBfile, kelondroOrder objectOrder, boolean exitOnFail) {
if ((refcountDBfile.exists()) && (countrefDBfile.exists())) try {
refcountDB = new kelondroTree(refcountDBfile, 0x100000L);
refcountDB.setText(0, kelondroBase64Order.enhancedCoder.encodeLong(0, countlength).getBytes()); // counter of all occurrences
@ -70,11 +70,11 @@ public class kelondroFScoreCluster {
} catch (IOException e) {
refcountDBfile.delete();
countrefDBfile.delete();
refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, 1, countlength, exitOnFail);
countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, 1, countlength, exitOnFail);
refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, objectOrder, 1, countlength, exitOnFail);
countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, objectOrder, 1, countlength, exitOnFail);
} else if ((!(refcountDBfile.exists())) && (!(countrefDBfile.exists()))) {
refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, 1, countlength, exitOnFail);
countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, 1, countlength, exitOnFail);
refcountDB = new kelondroTree(refcountDBfile, 0x100000L, new int[] {wordlength, countlength}, objectOrder, 1, countlength, exitOnFail);
countrefDB = new kelondroTree(countrefDBfile, 0x100000L, new int[] {countlength + wordlength, 4}, objectOrder, 1, countlength, exitOnFail);
} else {
if (exitOnFail) {
System.exit(-1);

@ -57,6 +57,18 @@ public class kelondroNaturalOrder extends kelondroAbstractOrder implements kelon
this.asc = ascending;
}
public static kelondroOrder bySignature(String signature) {
if (signature.equals("nd")) return new kelondroNaturalOrder(false);
if (signature.equals("nu")) return new kelondroNaturalOrder(true);
return null;
}
public String signature() {
if (!asc) return "nd";
if ( asc) return "nu";
return null;
}
public long cardinal(byte[] key) {
// returns a cardinal number in the range of 0 .. Long.MAX_VALUE
long c = 0;

@ -49,6 +49,8 @@ import java.util.Comparator;
public interface kelondroOrder extends Comparator {
public String signature(); // returns a signature String so that different orderings have different signatures
public long partition(byte[] key, int forkes);
public long cardinal(byte[] key); // returns a cardinal number in the range of 0 .. Long.MAX_VALUE

@ -72,10 +72,11 @@ public class kelondroSplittedTree implements kelondroIndex {
return true;
}
public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder order,
public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder objectOrder,
long buffersize,
int forkfactor,
int[] columns, int txtProps, int txtPropsWidth,
int[] columns,
int txtProps, int txtPropsWidth,
boolean exitOnFail) {
ktfs = new kelondroTree[forkfactor];
File f;
@ -84,31 +85,32 @@ public class kelondroSplittedTree implements kelondroIndex {
if (f.exists()) {
try {
ktfs[i] = new kelondroTree(f, buffersize/forkfactor);
this.order = ktfs[i].order();
} catch (IOException e) {
ktfs[i] = new kelondroTree(f, buffersize/forkfactor,
columns, txtProps, txtPropsWidth, exitOnFail);
columns, objectOrder, txtProps, txtPropsWidth, exitOnFail);
this.order = objectOrder;
}
} else {
ktfs[i] = new kelondroTree(f, buffersize/forkfactor,
columns, txtProps, txtPropsWidth, exitOnFail);
columns, objectOrder, txtProps, txtPropsWidth, exitOnFail);
this.order = objectOrder;
}
}
ff = forkfactor;
this.order = order;
}
public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder order,
public kelondroSplittedTree(File pathToFiles, String filenameStub, kelondroOrder objectOrder,
long buffersize, int forkfactor, int columns) throws IOException {
ktfs = new kelondroTree[forkfactor];
for (int i = 0; i < forkfactor; i++) {
ktfs[i] = new kelondroTree(dbFile(pathToFiles, filenameStub, forkfactor, columns, i),
buffersize/forkfactor);
ktfs[i] = new kelondroTree(dbFile(pathToFiles, filenameStub, forkfactor, columns, i), buffersize/forkfactor);
}
ff = forkfactor;
this.order = order;
this.order = objectOrder;
}
public static kelondroSplittedTree open(File pathToFiles, String filenameStub, kelondroOrder order,
public static kelondroSplittedTree open(File pathToFiles, String filenameStub, kelondroOrder objectOrder,
long buffersize,
int forkfactor,
int[] columns, int txtProps, int txtPropsWidth,
@ -116,9 +118,9 @@ public class kelondroSplittedTree implements kelondroIndex {
// generated a new splittet tree if it not exists or
// opens an existing one
if (existsAll(pathToFiles, filenameStub, forkfactor, columns.length)) {
return new kelondroSplittedTree(pathToFiles, filenameStub, order, buffersize, forkfactor, columns.length);
return new kelondroSplittedTree(pathToFiles, filenameStub, objectOrder, buffersize, forkfactor, columns.length);
} else {
return new kelondroSplittedTree(pathToFiles, filenameStub, order,
return new kelondroSplittedTree(pathToFiles, filenameStub, objectOrder,
buffersize,
forkfactor,
columns, txtProps, txtPropsWidth,
@ -126,7 +128,6 @@ public class kelondroSplittedTree implements kelondroIndex {
}
}
public int columns() {
return ktfs[0].columns();
}

@ -78,19 +78,19 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
private kelondroOrder objectOrder = new kelondroNaturalOrder(true);
public kelondroTree(File file, long buffersize, int key, int value, boolean exitOnFail) {
this(file, buffersize, new int[] { key, value }, 1, 8, exitOnFail);
this(file, buffersize, new int[] { key, value }, new kelondroNaturalOrder(true), 1, 8, exitOnFail);
}
public kelondroTree(kelondroRA ra, long buffersize, int key, int value, boolean exitOnFail) {
this(ra, buffersize, new int[] { key, value }, 1, 8, exitOnFail);
this(ra, buffersize, new int[] { key, value }, new kelondroNaturalOrder(true), 1, 8, exitOnFail);
}
public kelondroTree(File file, long buffersize, int[] columns, boolean exitOnFail) {
// this creates a new tree file
this(file, buffersize, columns, columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);
this(file, buffersize, columns, new kelondroNaturalOrder(true), columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);
}
public kelondroTree(File file, long buffersize, int[] columns, int txtProps, int txtPropsWidth, boolean exitOnFail) {
public kelondroTree(File file, long buffersize, int[] columns, kelondroOrder objectOrder, int txtProps, int txtPropsWidth, boolean exitOnFail) {
// this creates a new tree file
super(file, buffersize, thisOHBytes, thisOHHandles, columns, thisFHandles, txtProps, txtPropsWidth, exitOnFail);
try {
@ -100,14 +100,16 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
if (exitOnFail) System.exit(-1);
throw new RuntimeException("cannot set root handle / " + e.getMessage());
}
this.objectOrder = objectOrder;
writeOrderType();
}
public kelondroTree(kelondroRA ra, long buffersize, int[] columns, boolean exitOnFail) {
// this creates a new tree within a kelondroRA
this(ra, buffersize, columns, columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);
this(ra, buffersize, columns, new kelondroNaturalOrder(true), columns.length /* txtProps */, 80 /* txtPropWidth */, exitOnFail);
}
public kelondroTree(kelondroRA ra, long buffersize, int[] columns, int txtProps, int txtPropsWidth, boolean exitOnFail) {
public kelondroTree(kelondroRA ra, long buffersize, int[] columns, kelondroOrder objectOrder, int txtProps, int txtPropsWidth, boolean exitOnFail) {
// this creates a new tree within a kelondroRA
super(ra, buffersize, thisOHBytes, thisOHHandles, columns,
thisFHandles, txtProps, txtPropsWidth, exitOnFail);
@ -118,18 +120,44 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
if (exitOnFail) System.exit(-1);
throw new RuntimeException("cannot set root handle / " + e.getMessage());
}
this.objectOrder = objectOrder;
writeOrderType();
}
public kelondroTree(File file, long buffersize) throws IOException {
// this opens a file with an existing tree file
super(file, buffersize);
readOrderType();
}
public kelondroTree(kelondroRA ra, long buffersize) throws IOException {
// this opens a file with an existing tree in a kelondroRA
super(ra, buffersize);
readOrderType();
}
private void writeOrderType() {
try {
super.setDescription(objectOrder.signature().getBytes());
} catch (IOException e) {};
}
private void readOrderType() {
try {
byte[] d = super.getDescription();
String s = new String(d).substring(0, 2);
this.objectOrder = orderBySignature(s);
} catch (IOException e) {};
}
public static kelondroOrder orderBySignature(String signature) {
kelondroOrder oo = null;
if (oo == null) oo = kelondroNaturalOrder.bySignature(signature);
if (oo == null) oo = kelondroBase64Order.bySignature(signature);
if (oo == null) oo = new kelondroNaturalOrder(true);
return oo;
}
public void clear() throws IOException {
super.clear();
setHandle(root, null); // reset the root value

Loading…
Cancel
Save