java.lang.Object
net.i2p.router.util.HashDistance
Utility for calculating XOR distance between router hashes.
Computes the XOR distance between two router hashes by performing a bitwise XOR operation on the hash data. Used in Kademlia-based distributed hash tables for determining key proximity and routing decisions.
Returns the result as a BigInteger to handle the full 256-bit hash space without overflow issues. The distance metric is fundamental to Kademlia DHT operations including key lookup, peer selection, and network topology analysis.
Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionstatic intCompare two XOR distances without allocating BigInteger.static BigIntegergetDistance(Hash targetKey, Hash routerInQuestion) Compute XOR distance between two hashes.
Constructor Details
HashDistance
private HashDistance()Utility class, not intended for instantiation.
Method Details
getDistance
Compute XOR distance between two hashes. Allocates a BigInteger. For comparison-only use cases, prefercompare(Hash, Hash, Hash, Hash).- Parameters:
targetKey- one of the two hashes whose XOR distance is wantedrouterInQuestion- the other of the two hashes- Returns:
- the unsigned XOR of the two hashes, as a BigInteger over all 256 bits
compare
Compare two XOR distances without allocating BigInteger. Returns negative, zero, or positive as dist(a,b) < = > dist(c,d).- Parameters:
a- the first hash of the left-hand pairb- the second hash of the left-hand pairc- the first hash of the right-hand paird- the second hash of the right-hand pair- Returns:
- the first byte where a XOR b and c XOR d differ, or 0 if they are identical