pub struct TreeCoordinate(/* private fields */);Expand description
A node’s coordinates in the spanning tree.
Coordinates are the path from the node to the root:
[self, parent, grandparent, ..., root]
Each entry carries the node address plus declaration metadata (sequence and timestamp) for the wire protocol. Routing operations (distance, LCA) use only the node addresses.
The coordinate enables greedy routing via tree distance calculation. Two nodes can compute the hops between them by finding their lowest common ancestor (LCA) in the tree.
Implementations§
Source§impl TreeCoordinate
impl TreeCoordinate
Sourcepub fn new(path: Vec<CoordEntry>) -> Result<Self, TreeError>
pub fn new(path: Vec<CoordEntry>) -> Result<Self, TreeError>
Create a coordinate from a path of entries (self to root).
The path must be non-empty and ordered from the node to the root.
Sourcepub fn from_addrs(addrs: Vec<NodeAddr>) -> Result<Self, TreeError>
pub fn from_addrs(addrs: Vec<NodeAddr>) -> Result<Self, TreeError>
Create a coordinate from node addresses only (no metadata).
Convenience constructor for cases where only routing is needed. Each entry gets sequence=0, timestamp=0.
Sourcepub fn root_with_meta(
node_addr: NodeAddr,
sequence: u64,
timestamp: u64,
) -> Self
pub fn root_with_meta( node_addr: NodeAddr, sequence: u64, timestamp: u64, ) -> Self
Create a root coordinate with metadata.
Sourcepub fn entries(&self) -> &[CoordEntry]
pub fn entries(&self) -> &[CoordEntry]
The full path of entries with metadata.
Sourcepub fn node_addrs(&self) -> impl DoubleEndedIterator<Item = &NodeAddr>
pub fn node_addrs(&self) -> impl DoubleEndedIterator<Item = &NodeAddr>
Iterator over node addresses in the path (self to root).
Use this for routing operations (distance, LCA, ancestor checks) that only need the address path.
Sourcepub fn distance_to(&self, other: &TreeCoordinate) -> usize
pub fn distance_to(&self, other: &TreeCoordinate) -> usize
Calculate tree distance to another coordinate.
Distance is hops through the lowest common ancestor (LCA). If the coordinates have different roots, returns usize::MAX.
Sourcepub fn lca_depth(&self, other: &TreeCoordinate) -> usize
pub fn lca_depth(&self, other: &TreeCoordinate) -> usize
Find the depth of the lowest common ancestor.
Since coordinates are self-to-root, common ancestry is a suffix match. Returns the depth (from root) of the LCA.
Sourcepub fn lca(&self, other: &TreeCoordinate) -> Option<&NodeAddr>
pub fn lca(&self, other: &TreeCoordinate) -> Option<&NodeAddr>
Get the lowest common ancestor node ID.
Sourcepub fn has_ancestor(&self, other: &NodeAddr) -> bool
pub fn has_ancestor(&self, other: &NodeAddr) -> bool
Check if other is an ancestor (appears in our path after self).
Sourcepub fn contains(&self, other: &NodeAddr) -> bool
pub fn contains(&self, other: &NodeAddr) -> bool
Check if other is in our ancestry (including self).
Sourcepub fn ancestor_at(&self, depth: usize) -> Option<&NodeAddr>
pub fn ancestor_at(&self, depth: usize) -> Option<&NodeAddr>
Get the ancestor at a specific depth from self.
ancestor_at(0) returns self, ancestor_at(1) returns parent, etc.
Trait Implementations§
Source§impl Clone for TreeCoordinate
impl Clone for TreeCoordinate
Source§fn clone(&self) -> TreeCoordinate
fn clone(&self) -> TreeCoordinate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TreeCoordinate
impl Debug for TreeCoordinate
Source§impl PartialEq for TreeCoordinate
impl PartialEq for TreeCoordinate
Source§fn eq(&self, other: &TreeCoordinate) -> bool
fn eq(&self, other: &TreeCoordinate) -> bool
self and other values to be equal, and is used by ==.impl Eq for TreeCoordinate
impl StructuralPartialEq for TreeCoordinate
Auto Trait Implementations§
impl Freeze for TreeCoordinate
impl RefUnwindSafe for TreeCoordinate
impl Send for TreeCoordinate
impl Sync for TreeCoordinate
impl Unpin for TreeCoordinate
impl UnsafeUnpin for TreeCoordinate
impl UnwindSafe for TreeCoordinate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more