Patrick Oscar Boykin:
> what is the metric for key distance in freenet? Hamming distance?
Simple numerical distance (from Key.java):
/** Given that this Key is between Key A and Key B, determines
* whether A or B is closer. The lexicographically earlier
* key is considered closer if there is a tie.
* @return true if A is closer than B
*/
public final boolean isCloserTo_Ordered(Key A, Key B) {
int len = Math.max(val.length, Math.max(A.val.length, B.val.length));
int diff = 0;
for (int i=0; i<len; ++i) {
// incrementally compute the difference in the absolute distance
// between this and A and the absolute distance between this and B,
// which is given by (this - A) - (B - this)
diff += (at(val,i) - at(A.val,i)) - (at(B.val,i) - at(val,i));
if (diff < -1) return true;
if (diff > 1) return false;
diff *= 0x100;
}
return diff <= 0;
}
private static final int at(byte[] b, int i) {
return (i < b.length ? b[i] : 0) & 0xff;
}
_______________________________________________
freenet-tech mailing list
[EMAIL PROTECTED]
http://lists.freenetproject.org/mailman/listinfo/tech