Trait kademlia_routing_table::Xorable
[−]
[src]
pub trait Xorable { fn bucket_index(&self, other: &Self) -> usize; fn cmp_distance(&self, lhs: &Self, rhs: &Self) -> Ordering; fn differs_in_bit(&self, other: &Self, i: usize) -> bool; }
A sequence of bits, as a point in XOR space.
These are considered points in a space with the XOR metric, and need to implement the
functionality required by RoutingTable
to use them as node names.
Required Methods
fn bucket_index(&self, other: &Self) -> usize
Returns the bucket that other
belongs to, in the routing table of the node with name
self
. This must be the number of leading bits in which self
and other
agree. E. g.
the bucket index of other = 11110000
for self = 11111111
is 4, because the fifth bit is
the first one in which they differ.
fn cmp_distance(&self, lhs: &Self, rhs: &Self) -> Ordering
Compares the distance of the arguments to self
. Returns Less
if lhs
is closer,
Greater
if rhs
is closer, and Equal
if lhs == rhs
. (The XOR distance can only be
equal if the arguments are equal.)
fn differs_in_bit(&self, other: &Self, i: usize) -> bool
Returns true
if the i
-th bit of other has a different value than the i
-th bit of
self
.