- Add kad lib, from i2p.zzz.kademlia branch (without the history),

which is a rewrite of the netdb kad
- Drop now-unused SHA1Comparator
- Efficiency tweak to NodeInfoComparator
This commit is contained in:
zzz
2012-06-22 17:39:41 +00:00
parent 5883b7344e
commit d5a1e0b1c6
7 changed files with 1119 additions and 35 deletions

View File

@@ -0,0 +1,27 @@
package net.i2p.kademlia;
import java.util.Comparator;
import net.i2p.data.DataHelper;
import net.i2p.data.SimpleDataStructure;
/**
* Help sort Hashes in relation to a base key using the XOR metric
*
*/
class XORComparator<T extends SimpleDataStructure> implements Comparator<T> {
private final byte[] _base;
/**
* @param target key to compare distances with
*/
public XORComparator(T target) {
_base = target.getData();
}
public int compare(T lhs, T rhs) {
byte lhsDelta[] = DataHelper.xor(lhs.getData(), _base);
byte rhsDelta[] = DataHelper.xor(rhs.getData(), _base);
return DataHelper.compareTo(lhsDelta, rhsDelta);
}
}