code-beautification (to be consistent with external documentation paper)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5686 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 396a4451be
commit 3b28daab40

@ -263,6 +263,16 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Cod
return c; return c;
} }
private final long cardinalI(final String key) {
// returns a cardinal number in the range of 0 .. Long.MAX_VALUE
long c = 0;
int p = 0;
while ((p < 10) && (p < key.length())) c = (c << 6) | ahpla[key.charAt(p++)];
while (p++ < 10) c = (c << 6);
c = c << 3;
return c;
}
public final byte[] uncardinal(long c) { public final byte[] uncardinal(long c) {
c = c >> 3; c = c >> 3;
byte[] b = new byte[10]; byte[] b = new byte[10];
@ -281,6 +291,14 @@ public class Base64Order extends AbstractOrder<byte[]> implements ByteOrder, Cod
return Long.MAX_VALUE - 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);
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) { private static final int sig(final int x) {
return (x > 0) ? 1 : (x < 0) ? -1 : 0; return (x > 0) ? 1 : (x < 0) ? -1 : 0;
} }

@ -43,10 +43,7 @@ public class FlatWordPartitionScheme implements PartitionScheme {
public long dhtPosition(String wordHash, String urlHash) { public long dhtPosition(String wordHash, String urlHash) {
// the urlHash has no relevance here // the urlHash has no relevance here
// normalized to Long.MAX_VALUE // normalized to Long.MAX_VALUE
long c = Base64Order.enhancedCoder.cardinal(wordHash.getBytes()); return Base64Order.enhancedCoder.cardinal(wordHash);
assert c != Long.MAX_VALUE;
if (c == Long.MAX_VALUE) return Long.MAX_VALUE - 1;
return c;
} }
public final long dhtDistance(final String word, final String urlHash, final yacySeed peer) { public final long dhtDistance(final String word, final String urlHash, final yacySeed peer) {
@ -78,8 +75,9 @@ public class FlatWordPartitionScheme implements PartitionScheme {
} }
public final static long dhtDistance(final long fromPos, final long toPos) { public final static long dhtDistance(final long fromPos, final long toPos) {
final long d = toPos - fromPos; return (toPos >= fromPos) ?
return (d >= 0) ? d : (d + Long.MAX_VALUE) + 1; toPos - fromPos :
(Long.MAX_VALUE - fromPos) + toPos + 1;
} }
public static String positionToHash(final long l) { public static String positionToHash(final long l) {

Loading…
Cancel
Save