pub struct Node<'a, V, M = Auto, P = SplitRecursive>{ /* private fields */ }
Expand description
A node of the tree.
Trait Implementations§
Source§impl<V, M, P> Display for Node<'_, V, M, P>
impl<V, M, P> Display for Node<'_, V, M, P>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Creates a convenient-to-read string representation of the tree or a subtree rooted at a node.
§Examples
use orx_tree::*;
// 1
// ╱ ╲
// ╱ ╲
// 2 3
// ╱ ╲ ╱ ╲
// 4 5 6 7
// | | ╱ ╲
// 8 9 10 11
let mut tree = DynTree::new(1);
let mut root = tree.root_mut();
let [id2, id3] = root.push_children([2, 3]);
let [id4, _] = tree.node_mut(&id2).push_children([4, 5]);
tree.node_mut(&id4).push_child(8);
let [id6, id7] = tree.node_mut(&id3).push_children([6, 7]);
tree.node_mut(&id6).push_child(9);
tree.node_mut(&id7).push_children([10, 11]);
let expected_str = r#"1
├──2
│ ├──4
│ │ └──8
│ └──5
└──3
├──6
│ └──9
└──7
├──10
└──11
"#;
assert_eq!(tree.to_string(), expected_str);
let expected_str = r#"3
├──6
│ └──9
└──7
├──10
└──11
"#;
println!("{}", tree.node(&id3).to_string());
assert_eq!(tree.node(&id3).to_string(), expected_str);
impl<V, M, P> Send for Node<'_, V, M, P>
impl<V, M, P> Sync for Node<'_, V, M, P>
Auto Trait Implementations§
impl<'a, V, M, P> Freeze for Node<'a, V, M, P>
impl<'a, V, M, P> RefUnwindSafe for Node<'a, V, M, P>where
<M as MemoryPolicy>::MemoryReclaimPolicy<V>: RefUnwindSafe,
<P as PinnedStorage>::PinnedVec<V>: RefUnwindSafe,
<V as TreeVariant>::Children: RefUnwindSafe,
<V as Variant>::Item: RefUnwindSafe,
impl<'a, V, M, P> Unpin for Node<'a, V, M, P>
impl<'a, V, M, P> UnwindSafe for Node<'a, V, M, P>where
<M as MemoryPolicy>::MemoryReclaimPolicy<V>: RefUnwindSafe,
<P as PinnedStorage>::PinnedVec<V>: RefUnwindSafe,
<V as TreeVariant>::Children: RefUnwindSafe,
<V as Variant>::Item: RefUnwindSafe,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'a, V, M, P, X> NodeRef<'a, V, M, P> for X
impl<'a, V, M, P, X> NodeRef<'a, V, M, P> for X
Source§fn is_leaf(&self) -> bool
fn is_leaf(&self) -> bool
Returns true if this is a leaf node; equivalently, if
num_children
is zero. Read moreSource§fn num_children(&self) -> usize
fn num_children(&self) -> usize
Returns the number of child nodes of this node. Read more
Source§fn num_siblings(&self) -> usize
fn num_siblings(&self) -> usize
Returns the number of siblings including this node.
In other words, it returns the
num_children
of its parent;
or returns 1 if this is the root. Read moreSource§fn children(&'a self) -> impl ExactSizeIterator<Item = Node<'a, V, M, P>>
fn children(&'a self) -> impl ExactSizeIterator<Item = Node<'a, V, M, P>>
Returns an exact-sized iterator of children nodes of this node. Read more
Source§fn children_par(&'a self) -> impl ParIter<Item = Node<'a, V, M, P>>
fn children_par(&'a self) -> impl ParIter<Item = Node<'a, V, M, P>>
Creates a parallel iterator of children nodes of this node. Read more
Source§fn get_child(&self, child_index: usize) -> Option<Node<'a, V, M, P>>
fn get_child(&self, child_index: usize) -> Option<Node<'a, V, M, P>>
Returns the
child-index
-th child of the node; returns None if out of bounds. Read moreSource§fn child(&self, child_index: usize) -> Node<'a, V, M, P>
fn child(&self, child_index: usize) -> Node<'a, V, M, P>
Returns the
child-index
-th child of the node. Read moreSource§fn parent(&self) -> Option<Node<'a, V, M, P>>
fn parent(&self) -> Option<Node<'a, V, M, P>>
Returns the parent of this node; returns None if this is the root node. Read more
Source§fn sibling_idx(&self) -> usize
fn sibling_idx(&self) -> usize
Returns the position of this node in the children collection of its parent;
returns 0 if this is the root node (root has no other siblings). Read more
Source§fn depth(&self) -> usize
fn depth(&self) -> usize
Returns the depth of this node with respect to the root of the tree which has a
depth of 0. Read more
Source§fn ancestors(&'a self) -> impl Iterator<Item = Node<'a, V, M, P>>
fn ancestors(&'a self) -> impl Iterator<Item = Node<'a, V, M, P>>
Returns an iterator starting from this node’s parent moving upwards until the root: Read more
Source§fn ancestors_par(&'a self) -> impl ParIter<Item = Node<'a, V, M, P>>
fn ancestors_par(&'a self) -> impl ParIter<Item = Node<'a, V, M, P>>
Creates a parallel iterator starting from this node moving upwards until the root: Read more
Source§fn is_ancestor_of(&self, idx: &NodeIdx<V>) -> bool
fn is_ancestor_of(&self, idx: &NodeIdx<V>) -> bool
Returns true if this node is an ancestor of the node with the given
idx
;
false otherwise. Read moreSource§fn height(&self) -> usize
fn height(&self) -> usize
Returns the height of this node relative to the deepest leaf of the subtree rooted at this node. Read more
Source§fn custom_walk<F>(&self, next_node: F) -> impl Iterator<Item = &'a V::Item>
fn custom_walk<F>(&self, next_node: F) -> impl Iterator<Item = &'a V::Item>
Creates a custom walk starting from this node such that: Read more
Source§fn custom_walk_par<F>(&self, next_node: F) -> impl ParIter<Item = &'a V::Item>
fn custom_walk_par<F>(&self, next_node: F) -> impl ParIter<Item = &'a V::Item>
Creates a parallel iterator that yields references to data of all nodes belonging to the subtree rooted at this node. Read more
Source§fn walk<T>(&'a self) -> impl Iterator<Item = &'a V::Item>
fn walk<T>(&'a self) -> impl Iterator<Item = &'a V::Item>
Creates an iterator that yields references to data of all nodes belonging to the subtree rooted at this node. Read more
Source§fn walk_par<T>(&'a self) -> impl ParIter<Item = &'a V::Item>
fn walk_par<T>(&'a self) -> impl ParIter<Item = &'a V::Item>
Creates a parallel iterator that yields references to data of all nodes belonging to the subtree rooted at this node. Read more
Source§fn walk_with<'t, T, O>(
&'a self,
traverser: &'t mut T,
) -> impl Iterator<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
fn walk_with<'t, T, O>( &'a self, traverser: &'t mut T, ) -> impl Iterator<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
Creates an iterator that traverses all nodes belonging to the subtree rooted at this node. Read more
Source§fn walk_with_par<'t, T, O>(
&'a self,
traverser: &'t mut T,
) -> impl ParIter<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
fn walk_with_par<'t, T, O>( &'a self, traverser: &'t mut T, ) -> impl ParIter<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
Creates a parallel iterator that traverses all nodes belonging to the subtree rooted at this node. Read more
Source§fn paths<T>(
&'a self,
) -> impl Iterator<Item = impl Iterator<Item = &'a V::Item> + Clone>
fn paths<T>( &'a self, ) -> impl Iterator<Item = impl Iterator<Item = &'a V::Item> + Clone>
Returns an iterator of paths from all leaves of the subtree rooted at
this node upwards to this node. Read more
Source§fn paths_par<T>(
&'a self,
) -> impl ParIter<Item = impl Iterator<Item = &'a V::Item> + Clone>
fn paths_par<T>( &'a self, ) -> impl ParIter<Item = impl Iterator<Item = &'a V::Item> + Clone>
Creates a parallel iterator of paths from all leaves of the subtree rooted at this node upwards to this node. Read more
Source§fn paths_with<T, O>(
&'a self,
traverser: &'a mut T,
) -> impl Iterator<Item = impl Iterator<Item = <O as Over>::NodeItem<'a, V, M, P>> + Clone>
fn paths_with<T, O>( &'a self, traverser: &'a mut T, ) -> impl Iterator<Item = impl Iterator<Item = <O as Over>::NodeItem<'a, V, M, P>> + Clone>
Returns an iterator of paths from all leaves of the subtree rooted at
this node upwards to this node. Read more
Source§fn paths_with_par<T, O>(
&'a self,
traverser: &'a mut T,
) -> impl ParIter<Item = impl Iterator<Item = <O as Over>::NodeItem<'a, V, M, P>> + Clone>
fn paths_with_par<T, O>( &'a self, traverser: &'a mut T, ) -> impl ParIter<Item = impl Iterator<Item = <O as Over>::NodeItem<'a, V, M, P>> + Clone>
Creates a parallel iterator of paths from all leaves of the subtree rooted at this node upwards to this node. Read more
Source§fn clone_as_tree<V2>(&'a self) -> Tree<V2, M, P>
fn clone_as_tree<V2>(&'a self) -> Tree<V2, M, P>
Clone the subtree rooted at this node as a separate tree. Read more
Source§fn leaves<T>(&'a self) -> impl Iterator<Item = &'a V::Item>
fn leaves<T>(&'a self) -> impl Iterator<Item = &'a V::Item>
Returns an iterator of references to data of leaves of the subtree rooted at this node. Read more
Source§fn leaves_par<T>(&'a self) -> impl ParIter<Item = &'a V::Item>
fn leaves_par<T>(&'a self) -> impl ParIter<Item = &'a V::Item>
Creates a parallel iterator of references to data of leaves of the subtree rooted at this node. Read more
Source§fn leaves_with<T, O>(
&'a self,
traverser: &'a mut T,
) -> impl Iterator<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
fn leaves_with<T, O>( &'a self, traverser: &'a mut T, ) -> impl Iterator<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
Returns an iterator of leaves of the subtree rooted at this node. Read more
Source§fn leaves_with_par<T, O>(
&'a self,
traverser: &'a mut T,
) -> impl ParIter<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
fn leaves_with_par<T, O>( &'a self, traverser: &'a mut T, ) -> impl ParIter<Item = <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>>
Creates a parallel iterator of references to data of leaves of the subtree rooted at this node. Read more
Source§fn indices<T>(&self) -> impl Iterator<Item = NodeIdx<V>>
fn indices<T>(&self) -> impl Iterator<Item = NodeIdx<V>>
Returns an iterator of node indices. Read more
Source§fn indices_with<T, O>(
&self,
traverser: &mut T,
) -> impl Iterator<Item = <O::Enumeration as Enumeration>::Item<NodeIdx<V>>>
fn indices_with<T, O>( &self, traverser: &mut T, ) -> impl Iterator<Item = <O::Enumeration as Enumeration>::Item<NodeIdx<V>>>
Returns an iterator of node indices. Read more
Source§fn as_cloned_subtree(self) -> ClonedSubTree<'a, V, M, P, Self>
fn as_cloned_subtree(self) -> ClonedSubTree<'a, V, M, P, Self>
Creates a subtree view including this node as the root and all of its descendants with their orientation relative
to this node. Read more