Struct sn_routing::Prefix [−][src]
pub struct Prefix { /* 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.
Implementations
impl Prefix
[src]
impl Prefix
[src]pub fn new(bit_count: usize, name: XorName) -> Prefix
[src]
Creates a new Prefix
with the first bit_count
bits of name
. Insignificant bits are all
set to 0.
pub fn name(&self) -> XorName
[src]
Returns the name of this prefix.
pub fn pushed(self, bit: bool) -> Prefix
[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.
pub fn popped(self) -> Prefix
[src]
Returns a prefix copying the first bitcount() - 1
bits from self
,
or self
if it is already empty.
pub fn bit_count(&self) -> usize
[src]
Returns the number of bits in the prefix.
pub fn is_empty(&self) -> bool
[src]
Returns true
if this is the empty prefix, with no bits.
pub fn is_compatible(&self, other: &Prefix) -> bool
[src]
Returns true
if self
is a prefix of other
or vice versa.
pub fn is_extension_of(&self, other: &Prefix) -> bool
[src]
Returns true
if other
is compatible but strictly shorter than self
.
pub fn is_neighbour(&self, other: &Prefix) -> bool
[src]
Returns true
if the other
prefix differs in exactly one bit from this one.
pub fn common_prefix(&self, name: &XorName) -> usize
[src]
Returns the number of common leading bits with the input name, capped with prefix length.
pub fn matches(&self, name: &XorName) -> bool
[src]
Returns true
if this is a prefix of the given name
.
pub fn cmp_distance(&self, other: &Prefix, target: &XorName) -> 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).
pub fn cmp_breadth_first(&self, other: &Prefix) -> Ordering
[src]
Compares the prefixes using breadth-first order. That is, shorter prefixes are ordered
before longer. This is in contrast with the default Ord
impl of Prefix
which uses
depth-first order.
pub fn lower_bound(&self) -> XorName
[src]
Returns the smallest name matching the prefix
pub fn upper_bound(&self) -> XorName
[src]
Returns the largest name matching the prefix
pub fn range_inclusive(&self) -> RangeInclusive<XorName>
[src]
Inclusive range from lower_bound to upper_bound
pub fn is_covered_by<'a, I>(&self, prefixes: I) -> bool where
I: IntoIterator<Item = &'a Prefix> + Clone,
[src]
I: IntoIterator<Item = &'a Prefix> + Clone,
Returns whether the namespace defined by self
is covered by prefixes in the prefixes
set
pub fn with_flipped_bit(&self, i: u8) -> Prefix
[src]
Returns the neighbouring prefix differing in the i
-th bit
If i
is larger than our bit count, self
is returned
pub fn substituted_in(&self, name: XorName) -> XorName
[src]
Returns the given name
with first bits replaced by self
pub fn sibling(&self) -> Prefix
[src]
Returns the same prefix, with the last bit flipped, or unchanged, if empty.
pub fn ancestor(&self, bit_count: u8) -> Prefix
[src]
Returns the ancestors of this prefix that has the given bit count.
Panics
Panics if bit_count
is not less than the bit count of this prefix.
pub fn ancestors(&self) -> Ancestors
[src]
Returns an iterator that yields all ancestors of this prefix.
Trait Implementations
impl<'de> Deserialize<'de> for Prefix
[src]
impl<'de> Deserialize<'de> for Prefix
[src]pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Prefix, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
__deserializer: __D
) -> Result<Prefix, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl PartialOrd<Prefix> for Prefix
[src]
impl PartialOrd<Prefix> for Prefix
[src]impl Serialize for Prefix
[src]
impl Serialize for Prefix
[src]pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
impl StructuralEq for Prefix
[src]
impl StructuralEq for Prefix
[src]Auto Trait Implementations
impl RefUnwindSafe for Prefix
impl RefUnwindSafe for Prefix
impl UnwindSafe for Prefix
impl UnwindSafe for Prefix
Blanket Implementations
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,