Struct xor_name::XorName
[−]
[src]
pub struct XorName(pub [u8; 64]);
A XOR_NAME_BITS
-bit number, viewed as a point in XOR space.
This has as its only field an array of XOR_NAME_LEN
bytes,
i. e. a number between 0 and 2XOR_NAME_BITS - 1, the XorName
's "ID".
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]
pub fn new(id: [u8; 64]) -> XorName
[src]
Construct a XorName from a XOR_NAME_LEN
byte array.
pub fn get_id(&self) -> [u8; 64]
[src]
Return the internal array.
pub fn as_hex(&self) -> String
[src]
Hex-encode the XorName
as a String
.
pub fn bucket_distance(&self, name: &XorName) -> usize
[src]
Deprecated
Currently identical to bucket_index
. This method will be replaced with
XOR_NAME_BITS - bucket_index
or removed entirely.
pub fn cmp_closeness(&self, lhs: &XorName, rhs: &XorName) -> Ordering
[src]
Deprecated
Use the equivalent cmp_distance
instead.
pub fn bucket_index(&self, name: &XorName) -> usize
[src]
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
.
pub fn with_flipped_bit(
&self,
index: usize
) -> Result<XorName, BitIndexOutOfBoundsError>
[src]
&self,
index: usize
) -> Result<XorName, BitIndexOutOfBoundsError>
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 an error.
pub fn count_differing_bits(&self, other: &XorName) -> u32
[src]
Returns the number of bits in which self
differs from other
.
pub fn cmp_distance(&self, lhs: &XorName, rhs: &XorName) -> Ordering
[src]
Compares lhs
and rhs
with respect to their distance from self
.
pub fn from_hex(s: &str) -> Result<XorName, XorNameFromHexError>
[src]
Hex-decode a XorName
from a &str
.
Trait Implementations
impl Eq for XorName
[src]
impl Copy for XorName
[src]
impl Debug for XorName
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Display for XorName
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl PartialEq for XorName
[src]
fn eq(&self, other: &XorName) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Rand for XorName
[src]
fn rand<R: Rng>(rng: &mut R) -> XorName
[src]
Generates a random instance of this type using the specified source of randomness. Read more
impl Ord for XorName
[src]
The XorName
s can be ordered from zero as an integer. This is equivalent to ordering them by
their distance from the name 0
.
fn cmp(&self, other: &XorName) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl PartialOrd for XorName
[src]
fn partial_cmp(&self, other: &XorName) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Hash for XorName
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Clone for XorName
[src]
fn clone(&self) -> Self
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Index<Range<usize>> for XorName
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &[u8]
[src]
Performs the indexing (container[index]
) operation.
impl Index<RangeTo<usize>> for XorName
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &[u8]
[src]
Performs the indexing (container[index]
) operation.
impl Index<RangeFrom<usize>> for XorName
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &[u8]
[src]
Performs the indexing (container[index]
) operation.
impl Index<RangeFull> for XorName
[src]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: RangeFull) -> &[u8]
[src]
Performs the indexing (container[index]
) operation.
impl Encodable for XorName
[src]
fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), E::Error>
[src]
Serialize a value using an Encoder
.