fixed a problem / possible bug with ordering implementation (did not rotate always)

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

@ -63,25 +63,13 @@ public abstract class kelondroAbstractOrder implements kelondroOrder {
return cardinal(key) / d; return cardinal(key) / d;
} }
public int compareI(byte[] a, byte[] b) {
if (zero == null) return compare(a, b);
// we have an artificial start point. check all combinations
int az = compare(a, zero); // -1 if a < z; 0 if a == z; 1 if a > z
int bz = compare(b, zero); // -1 if b < z; 0 if b == z; 1 if b > z
if ((az == 0) && (bz == 0)) return 0;
if (az == 0) return -1;
if (bz == 0) return 1;
if (az == bz) return compare(a, b);
return bz;
}
public int compare(Object a, Object b) { public int compare(Object a, Object b) {
if ((a instanceof byte[]) && (b instanceof byte[])) { if ((a instanceof byte[]) && (b instanceof byte[])) {
return compareI((byte[]) a, (byte[]) b); return compare((byte[]) a, (byte[]) b);
} else if ((a instanceof Node) && (b instanceof Node)) { } else if ((a instanceof Node) && (b instanceof Node)) {
return compareI(((Node) a).getKey(), ((Node) b).getKey()); return compare(((Node) a).getKey(), ((Node) b).getKey());
} else if ((a instanceof String) && (b instanceof String)) { } else if ((a instanceof String) && (b instanceof String)) {
return compareI(((String) a).getBytes(), ((String) b).getBytes()); return compare(((String) a).getBytes(), ((String) b).getBytes());
} else } else
throw new IllegalArgumentException("Object type or Object type combination not supported: a=" + a + ", b=" + b); throw new IllegalArgumentException("Object type or Object type combination not supported: a=" + a + ", b=" + b);
} }

@ -246,13 +246,29 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond
} }
public int compare(byte[] a, byte[] b) { public int compare(byte[] a, byte[] b) {
return (asc) ? compare0(a, b) : compare0(b, a);
}
public int compare0(byte[] a, byte[] b) {
if (zero == null) return compares(a, b);
// we have an artificial start point. check all combinations
int az = compares(a, zero); // -1 if a < z; 0 if a == z; 1 if a > z
int bz = compares(b, zero); // -1 if b < z; 0 if b == z; 1 if b > z
if ((az == 0) && (bz == 0)) return 0;
if (az == 0) return -1;
if (bz == 0) return 1;
if (az == bz) return compares(a, b);
return bz;
}
public int compares(byte[] a, byte[] b) {
int i = 0; int i = 0;
final int al = a.length; final int al = a.length;
final int bl = b.length; final int bl = b.length;
final int len = (al > bl) ? bl : al; final int len = (al > bl) ? bl : al;
while (i < len) { while (i < len) {
if (ahpla[a[i]] > ahpla[b[i]]) return (asc) ? 1 : -1; if (ahpla[a[i]] > ahpla[b[i]]) return 1;
if (ahpla[a[i]] < ahpla[b[i]]) return (asc) ? -1 : 1; if (ahpla[a[i]] < ahpla[b[i]]) return -1;
// else the bytes are equal and it may go on yet undecided // else the bytes are equal and it may go on yet undecided
i++; i++;
} }
@ -260,8 +276,8 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond
if ((i == al) && (i < bl) && (b[i] == 0)) return 0; if ((i == al) && (i < bl) && (b[i] == 0)) return 0;
if ((i == bl) && (i < al) && (a[i] == 0)) return 0; if ((i == bl) && (i < al) && (a[i] == 0)) return 0;
// no, decide by length // no, decide by length
if (al > bl) return (asc) ? 1 : -1; if (al > bl) return 1;
if (al < bl) return (asc) ? -1 : 1; if (al < bl) return -1;
// no, they are equal // no, they are equal
return 0; return 0;
} }

@ -115,7 +115,19 @@ public class kelondroNaturalOrder extends kelondroAbstractOrder implements kelon
// two arrays are also equal if one array is a subset of the other's array // two arrays are also equal if one array is a subset of the other's array
// with filled-up char(0)-values // with filled-up char(0)-values
public int compare(byte[] a, byte[] b) { public int compare(byte[] a, byte[] b) {
return (asc) ? compares(a, b) : compares(b, a); return (asc) ? compare0(a, b) : compare0(b, a);
}
public int compare0(byte[] a, byte[] b) {
if (zero == null) return compares(a, b);
// we have an artificial start point. check all combinations
int az = compares(a, zero); // -1 if a < z; 0 if a == z; 1 if a > z
int bz = compares(b, zero); // -1 if b < z; 0 if b == z; 1 if b > z
if ((az == 0) && (bz == 0)) return 0;
if (az == 0) return -1;
if (bz == 0) return 1;
if (az == bz) return compares(a, b);
return bz;
} }
public static final int compares(byte[] a, byte[] b) { public static final int compares(byte[] a, byte[] b) {
@ -124,10 +136,8 @@ public class kelondroNaturalOrder extends kelondroAbstractOrder implements kelon
final int bl = b.length; final int bl = b.length;
final int len = (al > bl) ? bl : al; final int len = (al > bl) ? bl : al;
while (i < len) { while (i < len) {
if (a[i] > b[i]) if (a[i] > b[i]) return 1;
return 1; if (a[i] < b[i]) return -1;
if (a[i] < b[i])
return -1;
// else the bytes are equal and it may go on yet undecided // else the bytes are equal and it may go on yet undecided
i++; i++;
} }

Loading…
Cancel
Save