Struct routing::Prefix
[−]
[src]
pub struct Prefix<T: Clone + Copy + Default + Binary + Xorable> { /* fields omitted */ }
A section prefix, i.e. a sequence of bits specifying the part of the network's name space consisting of all names that start with this sequence.
Methods
impl<T: Clone + Copy + Default + Binary + Xorable> Prefix<T>
[src]
fn new(bit_count: usize, name: T) -> Prefix<T>
[src]
Creates a new Prefix
with the first bit_count
bits of name
. Insignificant bits are all
set to 0. If bit_count
exceeds the size of T
in bits, then it is reduced to this lower
value.
fn with_version(self, version: u64) -> VersionedPrefix<T>
[src]
Returns a VersionedPrefix
with this prefix and the given version number.
fn pushed(self, bit: bool) -> Prefix<T>
[src]
Returns self
with an appended bit: 0
if bit
is false
, and 1
if bit
is true
. If
self.bit_count
is already at the maximum for this type, then an unmodified copy of self
is returned.
fn popped(self) -> Prefix<T>
[src]
Returns a prefix copying the first bitcount() - 1
bits from self
,
or self
if it is already empty.
fn bit_count(&self) -> usize
[src]
Returns the number of bits in the prefix.
fn is_compatible(&self, other: &Prefix<T>) -> bool
[src]
Returns true
if self
is a prefix of other
or vice versa.
fn is_extension_of(&self, other: &Prefix<T>) -> bool
[src]
Returns true
if other
is compatible but strictly shorter than self
.
fn is_neighbour(&self, other: &Prefix<T>) -> bool
[src]
Returns true
if the other
prefix differs in exactly one bit from this one.
fn common_prefix(&self, name: &T) -> usize
[src]
Returns the number of common leading bits with the input name, capped with prefix length.
fn matches(&self, name: &T) -> bool
[src]
Returns true
if this is a prefix of the given name
.
fn cmp_distance(&self, other: &Self, target: &T) -> Ordering
[src]
Compares the distance of self
and other
to target
. Returns Less
if self
is closer,
Greater
if other
is closer, and compares the prefix directly if of equal distance
(this is to make sorting deterministic).
fn lower_bound(&self) -> T
[src]
Returns the smallest name matching the prefix
fn upper_bound(&self) -> T
[src]
Returns the largest name matching the prefix
fn is_covered_by<'a, U>(&self, prefixes: U) -> bool where
T: 'a,
U: IntoIterator<Item = &'a Prefix<T>> + Clone,
[src]
T: 'a,
U: IntoIterator<Item = &'a Prefix<T>> + Clone,
Returns whether the namespace defined by self
is covered by prefixes in the prefixes
set
fn with_flipped_bit(&self, i: usize) -> Prefix<T>
[src]
Returns the neighbouring prefix differing in the i
-th bit
If i
is larger than our bit count, self
is returned
fn substituted_in(&self, name: T) -> T
[src]
Returns the given name
with first bits replaced by self
fn sibling(&self) -> Prefix<T>
[src]
Returns the same prefix, with the last bit flipped, or unchanged, if empty.
Trait Implementations
impl<T: Clone + Clone + Copy + Default + Binary + Xorable> Clone for Prefix<T>
[src]
fn clone(&self) -> Prefix<T>
[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<T: Copy + Clone + Copy + Default + Binary + Xorable> Copy for Prefix<T>
[src]
impl<T: Default + Clone + Copy + Default + Binary + Xorable> Default for Prefix<T>
[src]
impl<T: Eq + Clone + Copy + Default + Binary + Xorable> Eq for Prefix<T>
[src]
impl<T: Clone + Copy + Default + Binary + Xorable> PartialEq<Prefix<T>> for Prefix<T>
[src]
fn eq(&self, other: &Self) -> 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<T: Clone + Copy + Default + Binary + Xorable> PartialOrd<Prefix<T>> for Prefix<T>
[src]
fn partial_cmp(&self, other: &Self) -> 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<T: Clone + Copy + Default + Binary + Xorable> Ord for Prefix<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl<T: Clone + Copy + Default + Binary + Xorable> Hash for Prefix<T>
[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<T: Clone + Copy + Default + Binary + Xorable> Binary for Prefix<T>
[src]
fn fmt(&self, formatter: &mut Formatter) -> FmtResult
[src]
Formats the value using the given formatter.