Struct libp2p_kad::kbucket::KeyBytes
source · pub struct KeyBytes(_);
Expand description
The raw bytes of a key in the DHT keyspace.
Implementations§
source§impl KeyBytes
impl KeyBytes
sourcepub fn new<T>(value: T) -> Selfwhere
T: Borrow<[u8]>,
pub fn new<T>(value: T) -> Selfwhere
T: Borrow<[u8]>,
Creates a new key in the DHT keyspace by running the given value through a random oracle.
sourcepub fn distance<U>(&self, other: &U) -> Distancewhere
U: AsRef<KeyBytes>,
pub fn distance<U>(&self, other: &U) -> Distancewhere
U: AsRef<KeyBytes>,
Computes the distance of the keys according to the XOR metric.
sourcepub fn for_distance(&self, d: Distance) -> KeyBytes
pub fn for_distance(&self, d: Distance) -> KeyBytes
Returns the uniquely determined key with the given distance to self
.
This implements the following equivalence:
self xor other = distance <==> other = self xor distance