Struct routing::XorName [] [src]

pub struct XorName(pub [u8; 32]);

A XOR_NAME_BITS-bit number, viewed as a point in XOR space.

This wraps an array of XOR_NAME_LEN bytes, i. e. a number between 0 and 2XOR_NAME_BITS - 1.

XOR space is the space of these numbers, with the XOR metric as a notion of distance, i. e. the points with IDs x and y are considered to have distance x xor y.

Methods

impl XorName
[src]

fn to_hex(&self) -> String

Hex-encode the XorName as a String.

fn with_flipped_bit(&self, index: usize) -> XorName

Returns a copy of self, with the index-th bit flipped.

If the parameter does not address one of the name's bits, i. e. if it does not satisfy index < XOR_NAME_BITS, the result will be equal to the argument.

fn count_differing_bits(&self, other: &XorName) -> u32

Returns the number of bits in which self differs from other.

fn from_hex(s: &str) -> Result<XorNameXorNameFromHexError>

Hex-decode a XorName from a &str.

fn bucket_index(&self, other: &XorName) -> usize

Returns the number of leading bits in which self and name agree.

Here, "leading bits" means the most significant bits. E. g. for 10101... and 10011..., that value will be 2, as their common prefix 10 has length 2 and the third bit is the first one in which they disagree.

Equivalently, this is XOR_NAME_BITS - bucket_distance, where bucket_distance is the length of the remainders after the common prefix is removed from the IDs of self and name.

The bucket distance is the magnitude of the XOR distance. More precisely, if d > 0 is the XOR distance between self and name, the bucket distance equals floor(log2(d)), i. e. a bucket distance of n means that 2n - 1 <= d < 2n.

fn cmp_distance(&self, lhs: &XorName, rhs: &XorName) -> Ordering

Compares lhs and rhs with respect to their distance from self.

fn differs_in_bit(&self, name: &XorName, i: usize) -> bool

Returns true if the i-th bit of name is different from the i-th bit of self.

fn closer(&self, lhs: &XorName, rhs: &XorName) -> bool

Returns true if lhs is closer to self than rhs.

Equivalently, this returns true if in the most significant bit where lhs and rhs disagree, lhs agrees with self.

fn closer_or_equal(&self, lhs: &XorName, rhs: &XorName) -> bool

Returns true if lhs is closer to self than rhs, or lhs == rhs.

Trait Implementations

impl PartialOrd for XorName
[src]

fn partial_cmp(&self, __arg_0: &XorName) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, __arg_0: &XorName) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, __arg_0: &XorName) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn gt(&self, __arg_0: &XorName) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, __arg_0: &XorName) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq for XorName
[src]

fn eq(&self, __arg_0: &XorName) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &XorName) -> bool

This method tests for !=.

impl Ord for XorName
[src]

fn cmp(&self, __arg_0: &XorName) -> Ordering

This method returns an Ordering between self and other. Read more

impl Hash for XorName
[src]

fn hash<__H: Hasher>(&self, __arg_0: &mut __H)

Feeds this value into the state given, updating the hasher as necessary.

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0

Feeds a slice of this type into the state provided.

impl Clone for XorName
[src]

fn clone(&self) -> XorName

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

impl Copy for XorName
[src]

impl Eq for XorName
[src]

impl Xorable for XorName
[src]

fn bucket_index(&self, other: &XorName) -> 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. Read more

fn cmp_distance(&self, lhs: &XorName, rhs: &XorName) -> 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.) Read more

fn differs_in_bit(&self, name: &XorName, i: usize) -> bool

Returns true if the i-th bit of other has a different value than the i-th bit of self. Read more

impl Debug for XorName
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Display for XorName
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Rand for XorName
[src]

fn rand<R: Rng>(rng: &mut R) -> XorName

Generates a random instance of this type using the specified source of randomness. Read more

impl Index<Range<usize>> for XorName
[src]

type Output = [u8]

The returned type after indexing

fn index(&self, index: Range<usize>) -> &[u8]

The method for the indexing (Foo[Bar]) operation

impl Index<RangeTo<usize>> for XorName
[src]

type Output = [u8]

The returned type after indexing

fn index(&self, index: RangeTo<usize>) -> &[u8]

The method for the indexing (Foo[Bar]) operation

impl Index<RangeFrom<usize>> for XorName
[src]

type Output = [u8]

The returned type after indexing

fn index(&self, index: RangeFrom<usize>) -> &[u8]

The method for the indexing (Foo[Bar]) operation

impl Index<RangeFull> for XorName
[src]

type Output = [u8]

The returned type after indexing

fn index(&self, index: RangeFull) -> &[u8]

The method for the indexing (Foo[Bar]) operation

impl Encodable for XorName
[src]

fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), E::Error>

impl Decodable for XorName
[src]

fn decode<D: Decoder>(decoder: &mut D) -> Result<XorName, D::Error>