|
|
|
@ -29,7 +29,6 @@ package net.yacy.kelondro.order;
|
|
|
|
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
|
|
|
|
import net.yacy.cora.document.ASCII;
|
|
|
|
|
import net.yacy.cora.document.UTF8;
|
|
|
|
|
import net.yacy.kelondro.index.HandleSet;
|
|
|
|
|
import net.yacy.kelondro.index.RowSpaceExceededException;
|
|
|
|
@ -66,29 +65,29 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
// then we get shorter base64 results which are also filename-compatible
|
|
|
|
|
this.rfc1113compliant = rfc1113compliant;
|
|
|
|
|
this.asc = up;
|
|
|
|
|
alpha = (rfc1113compliant) ? alpha_standard : alpha_enhanced;
|
|
|
|
|
ahpla = (rfc1113compliant) ? ahpla_standard : ahpla_enhanced;
|
|
|
|
|
ab = new byte[1 << 14];
|
|
|
|
|
this.alpha = (rfc1113compliant) ? alpha_standard : alpha_enhanced;
|
|
|
|
|
this.ahpla = (rfc1113compliant) ? ahpla_standard : ahpla_enhanced;
|
|
|
|
|
this.ab = new byte[1 << 14];
|
|
|
|
|
byte acc, bcc;
|
|
|
|
|
byte c;
|
|
|
|
|
// pre-compute comparisment results: this omits one single ahpla lookup during comparisment
|
|
|
|
|
for (final byte ac: alpha) {
|
|
|
|
|
for (final byte bc: alpha) {
|
|
|
|
|
acc = ahpla[ac];
|
|
|
|
|
bcc = ahpla[bc];
|
|
|
|
|
for (final byte ac: this.alpha) {
|
|
|
|
|
for (final byte bc: this.alpha) {
|
|
|
|
|
acc = this.ahpla[ac];
|
|
|
|
|
bcc = this.ahpla[bc];
|
|
|
|
|
c = 0;
|
|
|
|
|
if (acc > bcc) c = 1;
|
|
|
|
|
if (acc < bcc) c = -1;
|
|
|
|
|
|
|
|
|
|
ab[(ac << 7) | bc] = c;
|
|
|
|
|
|
|
|
|
|
this.ab[(ac << 7) | bc] = c;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public HandleSet getHandleSet(final int keylength, final int space) throws RowSpaceExceededException {
|
|
|
|
|
return new HandleSet(keylength, this, space);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] zero(int length) {
|
|
|
|
|
final byte[] z = new byte[length];
|
|
|
|
|
while (length > 0) {
|
|
|
|
@ -96,27 +95,27 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
}
|
|
|
|
|
return z;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Order<byte[]> clone() {
|
|
|
|
|
final Base64Order o = new Base64Order(this.asc, this.rfc1113compliant);
|
|
|
|
|
o.rotate(zero);
|
|
|
|
|
o.rotate(this.zero);
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final boolean wellformed(final byte[] a) {
|
|
|
|
|
return wellformed(a, 0, a.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final boolean wellformed(final byte[] a, final int astart, final int alength) {
|
|
|
|
|
assert (astart + alength <= a.length) : "astart = " + astart + ", alength = " + alength + ", a.length = " + a.length;
|
|
|
|
|
int b;
|
|
|
|
|
for (int i = astart + alength - 1; i >= astart; i--) {
|
|
|
|
|
b = a[i];
|
|
|
|
|
if ((b < 0) || (b >= 128) || (ahpla[b] == -1)) return false;
|
|
|
|
|
if ((b < 0) || (b >= 128) || (this.ahpla[b] == -1)) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final static ByteOrder bySignature(final String signature) {
|
|
|
|
|
if ("Bd".equals(signature)) return new Base64Order(false, false);
|
|
|
|
|
if ("bd".equals(signature)) return new Base64Order(false, true);
|
|
|
|
@ -124,41 +123,41 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
if ("bu".equals(signature)) return new Base64Order(true, true);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final String signature() {
|
|
|
|
|
if ((!asc) && (!rfc1113compliant)) return "Bd";
|
|
|
|
|
if ((!asc) && ( rfc1113compliant)) return "bd";
|
|
|
|
|
if (( asc) && (!rfc1113compliant)) return "Bu";
|
|
|
|
|
if (( asc) && ( rfc1113compliant)) return "bu";
|
|
|
|
|
if ((!this.asc) && (!this.rfc1113compliant)) return "Bd";
|
|
|
|
|
if ((!this.asc) && ( this.rfc1113compliant)) return "bd";
|
|
|
|
|
if (( this.asc) && (!this.rfc1113compliant)) return "Bu";
|
|
|
|
|
if (( this.asc) && ( this.rfc1113compliant)) return "bu";
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final char encodeByte(final byte b) {
|
|
|
|
|
return (char) alpha[b];
|
|
|
|
|
return (char) this.alpha[b];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final byte decodeByte(final byte b) {
|
|
|
|
|
return ahpla[b];
|
|
|
|
|
return this.ahpla[b];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final byte decodeByte(final char b) {
|
|
|
|
|
return ahpla[b];
|
|
|
|
|
return this.ahpla[b];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final StringBuilder encodeLongSB(long c, int length) {
|
|
|
|
|
final StringBuilder s = new StringBuilder(length);
|
|
|
|
|
s.setLength(length);
|
|
|
|
|
while (length > 0) {
|
|
|
|
|
s.setCharAt(--length, (char) alpha[(byte) (c & 0x3F)]);
|
|
|
|
|
s.setCharAt(--length, (char) this.alpha[(byte) (c & 0x3F)]);
|
|
|
|
|
c >>= 6;
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final byte[] encodeLongBA(long c, int length) {
|
|
|
|
|
byte[] s = new byte[length];
|
|
|
|
|
final byte[] s = new byte[length];
|
|
|
|
|
while (length > 0) {
|
|
|
|
|
s[--length] = alpha[(byte) (c & 0x3F)];
|
|
|
|
|
s[--length] = this.alpha[(byte) (c & 0x3F)];
|
|
|
|
|
c >>= 6;
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
@ -167,7 +166,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
public final byte[] encodeLongSubstr(long c, int length) {
|
|
|
|
|
final byte[] s = new byte[length];
|
|
|
|
|
while (length > 0) {
|
|
|
|
|
s[--length] = alpha[(byte) (c & 0x3F)];
|
|
|
|
|
s[--length] = this.alpha[(byte) (c & 0x3F)];
|
|
|
|
|
c >>= 6;
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
@ -176,22 +175,22 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
public final void encodeLong(long c, final byte[] b, final int offset, int length) {
|
|
|
|
|
assert offset + length <= b.length;
|
|
|
|
|
while (length > 0) {
|
|
|
|
|
b[--length + offset] = alpha[(byte) (c & 0x3F)];
|
|
|
|
|
b[--length + offset] = this.alpha[(byte) (c & 0x3F)];
|
|
|
|
|
c >>= 6;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final long decodeLong(String s) {
|
|
|
|
|
while (s.endsWith("=")) s = s.substring(0, s.length() - 1);
|
|
|
|
|
long c = 0;
|
|
|
|
|
for (int i = 0; i < s.length(); i++) c = (c << 6) | ahpla[s.charAt(i)];
|
|
|
|
|
for (int i = 0; i < s.length(); i++) c = (c << 6) | this.ahpla[s.charAt(i)];
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final long decodeLong(final byte[] s, final int offset, int length) {
|
|
|
|
|
while ((length > 0) && (s[offset + length - 1] == '=')) length--;
|
|
|
|
|
long c = 0;
|
|
|
|
|
for (int i = 0; i < length; i++) c = (c << 6) | ahpla[s[offset + i]];
|
|
|
|
|
for (int i = 0; i < length; i++) c = (c << 6) | this.ahpla[s[offset + i]];
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -212,7 +211,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
// we will do that by grouping each three input bytes to four output bytes.
|
|
|
|
|
public final String encode(final byte[] in) {
|
|
|
|
|
if (in == null || in.length == 0) return "";
|
|
|
|
|
int lene = in.length / 3 * 4 + 3;
|
|
|
|
|
final int lene = in.length / 3 * 4 + 3;
|
|
|
|
|
StringBuilder out = new StringBuilder(lene);
|
|
|
|
|
int pos = 0;
|
|
|
|
|
long l;
|
|
|
|
@ -223,15 +222,15 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
}
|
|
|
|
|
// now there may be remaining bytes
|
|
|
|
|
if (in.length % 3 != 0) out = out.append((in.length % 3 == 2) ? encodeLongSB((((0XffL & in[pos]) << 8) + (0XffL & in[pos + 1])) << 8, 4).substring(0, 3) : encodeLongSB((((0XffL & in[pos])) << 8) << 8, 4).substring(0, 2));
|
|
|
|
|
if (rfc1113compliant) while (out.length() % 4 > 0) out.append("=");
|
|
|
|
|
if (this.rfc1113compliant) while (out.length() % 4 > 0) out.append("=");
|
|
|
|
|
// return result
|
|
|
|
|
//assert lene == out.length() : "lene = " + lene + ", out.len = " + out.length();
|
|
|
|
|
return out.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final byte[] encodeSubstring(final byte[] in, int sublen) {
|
|
|
|
|
|
|
|
|
|
public final byte[] encodeSubstring(final byte[] in, final int sublen) {
|
|
|
|
|
if (in.length == 0) return null;
|
|
|
|
|
byte[] out = new byte[sublen];
|
|
|
|
|
final byte[] out = new byte[sublen];
|
|
|
|
|
int writepos = 0;
|
|
|
|
|
int pos = 0;
|
|
|
|
|
long l;
|
|
|
|
@ -251,9 +250,9 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
writepos += 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rfc1113compliant) while (writepos % 4 > 0 && writepos < sublen) out[writepos] = '=';
|
|
|
|
|
assert encode(in).substring(0, sublen).equals(ASCII.String(out));
|
|
|
|
|
|
|
|
|
|
if (this.rfc1113compliant) while (writepos % 4 > 0 && writepos < sublen) out[writepos] = '=';
|
|
|
|
|
//assert encode(in).substring(0, sublen).equals(ASCII.String(out));
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -266,7 +265,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
try {
|
|
|
|
|
int posIn = 0;
|
|
|
|
|
int posOut = 0;
|
|
|
|
|
if (rfc1113compliant) while (in.charAt(in.length() - 1) == '=') in = in.substring(0, in.length() - 1);
|
|
|
|
|
if (this.rfc1113compliant) while (in.charAt(in.length() - 1) == '=') in = in.substring(0, in.length() - 1);
|
|
|
|
|
final byte[] out = new byte[in.length() / 4 * 3 + (((in.length() % 4) == 0) ? 0 : in.length() % 4 - 1)];
|
|
|
|
|
long l;
|
|
|
|
|
while (posIn + 3 < in.length()) {
|
|
|
|
@ -311,7 +310,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
int p = 0;
|
|
|
|
|
byte b;
|
|
|
|
|
while ((p < 10) && (p < key.length())) {
|
|
|
|
|
b = ahpla[key.charAt(p++)];
|
|
|
|
|
b = this.ahpla[key.charAt(p++)];
|
|
|
|
|
if (b < 0) return -1;
|
|
|
|
|
c = (c << 6) | b;
|
|
|
|
|
}
|
|
|
|
@ -321,16 +320,16 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final long cardinalI(final byte[] key, int off, int len) {
|
|
|
|
|
private final long cardinalI(final byte[] key, int off, final int len) {
|
|
|
|
|
// returns a cardinal number in the range of 0 .. Long.MAX_VALUE
|
|
|
|
|
long c = 0;
|
|
|
|
|
int lim = off + Math.min(10, len);
|
|
|
|
|
int lim10 = off + 10;
|
|
|
|
|
final int lim = off + Math.min(10, len);
|
|
|
|
|
final int lim10 = off + 10;
|
|
|
|
|
byte b;
|
|
|
|
|
while (off < lim) {
|
|
|
|
|
b = key[off++];
|
|
|
|
|
if (b < 0) return -1;
|
|
|
|
|
b = ahpla[b];
|
|
|
|
|
b = this.ahpla[b];
|
|
|
|
|
if (b < 0) return -1;
|
|
|
|
|
c = (c << 6) | b;
|
|
|
|
|
}
|
|
|
|
@ -339,47 +338,47 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
assert c >= 0;
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final byte[] uncardinal(long c) {
|
|
|
|
|
c = c >> 3;
|
|
|
|
|
byte[] b = new byte[12];
|
|
|
|
|
final byte[] b = new byte[12];
|
|
|
|
|
for (int p = 9; p >= 0; p--) {
|
|
|
|
|
b[p] = alpha[(int) (c & 0x3fL)];
|
|
|
|
|
b[p] = this.alpha[(int) (c & 0x3fL)];
|
|
|
|
|
c = c >> 6;
|
|
|
|
|
}
|
|
|
|
|
b[10] = alpha[0x3f];
|
|
|
|
|
b[11] = alpha[0x3f];
|
|
|
|
|
b[10] = this.alpha[0x3f];
|
|
|
|
|
b[11] = this.alpha[0x3f];
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final long cardinal(final byte[] key) {
|
|
|
|
|
if (this.zero == null) return cardinalI(key, 0, key.length);
|
|
|
|
|
final long zeroCardinal = cardinalI(this.zero, 0, zero.length);
|
|
|
|
|
final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);
|
|
|
|
|
final long keyCardinal = cardinalI(key, 0, key.length);
|
|
|
|
|
if (keyCardinal > zeroCardinal) return keyCardinal - zeroCardinal;
|
|
|
|
|
return Long.MAX_VALUE - keyCardinal + zeroCardinal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final long cardinal(final byte[] key, int off, int len) {
|
|
|
|
|
|
|
|
|
|
public final long cardinal(final byte[] key, final int off, final int len) {
|
|
|
|
|
if (this.zero == null) return cardinalI(key, off, len);
|
|
|
|
|
final long zeroCardinal = cardinalI(this.zero, 0, zero.length);
|
|
|
|
|
final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);
|
|
|
|
|
final long keyCardinal = cardinalI(key, off, len);
|
|
|
|
|
if (keyCardinal > zeroCardinal) return keyCardinal - zeroCardinal;
|
|
|
|
|
return Long.MAX_VALUE - keyCardinal + zeroCardinal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final long cardinal(final String key) {
|
|
|
|
|
if (this.zero == null) return cardinalI(key);
|
|
|
|
|
final long zeroCardinal = cardinalI(this.zero, 0, zero.length);
|
|
|
|
|
final long zeroCardinal = cardinalI(this.zero, 0, this.zero.length);
|
|
|
|
|
final long keyCardinal = cardinalI(key);
|
|
|
|
|
if (keyCardinal > zeroCardinal) return keyCardinal - zeroCardinal;
|
|
|
|
|
return Long.MAX_VALUE - keyCardinal + zeroCardinal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int sig(final int x) {
|
|
|
|
|
return (x > 0) ? 1 : (x < 0) ? -1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final boolean equal(final byte[] a, final byte[] b) {
|
|
|
|
|
if ((a == null) && (b == null)) return true;
|
|
|
|
|
if ((a == null) || (b == null)) return false;
|
|
|
|
@ -392,7 +391,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final boolean equal(final byte[] a, int astart, final byte[] b, int bstart, int length) {
|
|
|
|
|
if ((a == null) && (b == null)) return true;
|
|
|
|
|
if ((a == null) || (b == null)) return false;
|
|
|
|
@ -401,66 +400,66 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final int compare(final byte[] a, final byte[] b) {
|
|
|
|
|
try {
|
|
|
|
|
return (asc) ?
|
|
|
|
|
((zero == null) ? compares(a, b) : compare0(a, 0, b, 0, a.length))
|
|
|
|
|
return (this.asc) ?
|
|
|
|
|
((this.zero == null) ? compares(a, b) : compare0(a, 0, b, 0, a.length))
|
|
|
|
|
:
|
|
|
|
|
((zero == null) ? compares(b, a) : compare0(b, 0, a, 0, a.length));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
((this.zero == null) ? compares(b, a) : compare0(b, 0, a, 0, a.length));
|
|
|
|
|
} catch (final Exception e) {
|
|
|
|
|
// if a or b is not well-formed, an ArrayIndexOutOfBoundsException may occur
|
|
|
|
|
// in that case we don't want that the exception makes databse functions
|
|
|
|
|
// unusable and effective creates a showstopper. In such cases we apply
|
|
|
|
|
// a different order on the objects and treat not well-formed objects
|
|
|
|
|
// as bigger as all others. If both object are not well-formed, they are
|
|
|
|
|
// compared with the natural order.
|
|
|
|
|
boolean wfa = wellformed(a);
|
|
|
|
|
boolean wfb = wellformed(b);
|
|
|
|
|
final boolean wfa = wellformed(a);
|
|
|
|
|
final boolean wfb = wellformed(b);
|
|
|
|
|
if (wfa && wfb) {
|
|
|
|
|
// uh strange. throw the exception
|
|
|
|
|
if (e instanceof ArrayIndexOutOfBoundsException) throw (ArrayIndexOutOfBoundsException) e;
|
|
|
|
|
throw new RuntimeException(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
if (wfa) return (asc) ? -1 : 1;
|
|
|
|
|
if (wfb) return (asc) ? 1 : -1;
|
|
|
|
|
return ((asc) ? 1 : -1) * NaturalOrder.naturalOrder.compare(a, b);
|
|
|
|
|
if (wfa) return (this.asc) ? -1 : 1;
|
|
|
|
|
if (wfb) return (this.asc) ? 1 : -1;
|
|
|
|
|
return ((this.asc) ? 1 : -1) * NaturalOrder.naturalOrder.compare(a, b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public final int compare(final byte[] a, final int aoffset, final byte[] b, final int boffset, final int length) {
|
|
|
|
|
try {
|
|
|
|
|
return (asc) ?
|
|
|
|
|
return (this.asc) ?
|
|
|
|
|
compare0(a, aoffset, b, boffset, length)
|
|
|
|
|
:
|
|
|
|
|
compare0(b, boffset, a, aoffset, length);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
} catch (final Exception e) {
|
|
|
|
|
// same handling as in simple compare method above
|
|
|
|
|
boolean wfa = wellformed(a, aoffset, length);
|
|
|
|
|
boolean wfb = wellformed(b, boffset, length);
|
|
|
|
|
final boolean wfa = wellformed(a, aoffset, length);
|
|
|
|
|
final boolean wfb = wellformed(b, boffset, length);
|
|
|
|
|
if (wfa && wfb) {
|
|
|
|
|
// uh strange. throw the exception
|
|
|
|
|
if (e instanceof ArrayIndexOutOfBoundsException) throw (ArrayIndexOutOfBoundsException) e;
|
|
|
|
|
throw new RuntimeException(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
if (wfa) return (asc) ? -1 : 1;
|
|
|
|
|
if (wfb) return (asc) ? 1 : -1;
|
|
|
|
|
return ((asc) ? 1 : -1) * NaturalOrder.naturalOrder.compare(a, aoffset, b, boffset, length);
|
|
|
|
|
if (wfa) return (this.asc) ? -1 : 1;
|
|
|
|
|
if (wfb) return (this.asc) ? 1 : -1;
|
|
|
|
|
return ((this.asc) ? 1 : -1) * NaturalOrder.naturalOrder.compare(a, aoffset, b, boffset, length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final int compare0(final byte[] a, final int aoffset, final byte[] b, final int boffset, final int length) {
|
|
|
|
|
if (zero == null) return compares(a, aoffset, b, boffset, length);
|
|
|
|
|
if (this.zero == null) return compares(a, aoffset, b, boffset, length);
|
|
|
|
|
|
|
|
|
|
// we have an artificial start point. check all combinations
|
|
|
|
|
final int az = compares(a, aoffset, zero, 0, Math.min(length, zero.length)); // -1 if a < z; 0 if a == z; 1 if a > z
|
|
|
|
|
final int bz = compares(b, boffset, zero, 0, Math.min(length, zero.length)); // -1 if b < z; 0 if b == z; 1 if b > z
|
|
|
|
|
final int az = compares(a, aoffset, this.zero, 0, Math.min(length, this.zero.length)); // -1 if a < z; 0 if a == z; 1 if a > z
|
|
|
|
|
final int bz = compares(b, boffset, this.zero, 0, Math.min(length, this.zero.length)); // -1 if b < z; 0 if b == z; 1 if b > z
|
|
|
|
|
if (az == bz) return compares(a, aoffset, b, boffset, length);
|
|
|
|
|
return sig(az - bz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final int compares(final byte[] a, final byte[] b) {
|
|
|
|
|
assert (ahpla.length == 128);
|
|
|
|
|
assert (this.ahpla.length == 128);
|
|
|
|
|
short i = 0;
|
|
|
|
|
final int al = a.length;
|
|
|
|
|
final int bl = b.length;
|
|
|
|
@ -476,7 +475,7 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
assert ac != 0;
|
|
|
|
|
assert bc != 0;
|
|
|
|
|
//if ((ac == 0) && (bc == 0)) return 0; // zero-terminated length
|
|
|
|
|
if (ac != bc) return ab[(ac << 7) | bc];
|
|
|
|
|
if (ac != bc) return this.ab[(ac << 7) | bc];
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
// compare length
|
|
|
|
@ -485,11 +484,11 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
// they are equal
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final int compares(final byte[] a, final int aoffset, final byte[] b, final int boffset, final int length) {
|
|
|
|
|
assert (aoffset + length <= a.length) : "a.length = " + a.length + ", aoffset = " + aoffset + ", alength = " + length;
|
|
|
|
|
assert (boffset + length <= b.length) : "b.length = " + b.length + ", boffset = " + boffset + ", blength = " + length;
|
|
|
|
|
assert (ahpla.length == 128);
|
|
|
|
|
assert (this.ahpla.length == 128);
|
|
|
|
|
short i = 0;
|
|
|
|
|
byte ac, bc;
|
|
|
|
|
//byte acc, bcc;
|
|
|
|
@ -509,12 +508,12 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Com
|
|
|
|
|
i++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return ab[(ac << 7) | bc];
|
|
|
|
|
return this.ab[(ac << 7) | bc];
|
|
|
|
|
}
|
|
|
|
|
// they are equal
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(final String[] s) {
|
|
|
|
|
// java -classpath classes de.anomic.kelondro.kelondroBase64Order
|
|
|
|
|
final Base64Order b64 = new Base64Order(true, true);
|
|
|
|
|