Struct Node

Source
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> Clone for Node<'_, V, M, P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V, M, P> Debug for Node<'_, V, M, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V, M, P> Display for Node<'_, V, M, P>

Source§

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);
Source§

impl<'a, V, M, P> PartialEq<Node<'a, V, M, P>> for NodeMut<'_, V, M, P>

Source§

fn eq(&self, other: &Node<'a, V, M, P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, V, M, P> PartialEq<NodeMut<'a, V, M, P>> for Node<'_, V, M, P>

Source§

fn eq(&self, other: &NodeMut<'a, V, M, P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V, M, P> PartialEq for Node<'_, V, M, P>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V, M, P> Send for Node<'_, V, M, P>

Source§

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>

§

impl<'a, V, M, P> Unpin for Node<'a, V, M, P>

§

impl<'a, V, M, P> UnwindSafe for Node<'a, V, M, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, V, M, P, X> NodeRef<'a, V, M, P> for X
where V: TreeVariant + 'a, M: MemoryPolicy, P: PinnedStorage, X: NodeRefCore<'a, V, M, P>,

Source§

fn idx(&self) -> NodeIdx<V>

Returns the node index of this node. Read more
Source§

fn is_root(&self) -> bool

Returns true if this is the root node; equivalently, if its parent is none. Read more
Source§

fn is_leaf(&self) -> bool

Returns true if this is a leaf node; equivalently, if num_children is zero. Read more
Source§

fn data(&self) -> &'a V::Item

Returns a reference to the data of the node. Read more
Source§

fn num_children(&self) -> usize

Returns the number of child nodes of this node. Read more
Source§

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 more
Source§

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>>
where V::Item: Send + Sync, Self: Sync,

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>>

Returns the child-index-th child of the node; returns None if out of bounds. Read more
Source§

fn child(&self, child_index: usize) -> Node<'a, V, M, P>

Returns the child-index-th child of the node. Read more
Source§

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

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

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>>

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>>
where V::Item: Send + Sync,

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

Returns true if this node is an ancestor of the node with the given idx; false otherwise. Read more
Source§

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>
where F: Fn(Node<'a, V, M, P>) -> Option<Node<'a, V, M, P>>,

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>
where F: Fn(Node<'a, V, M, P>) -> Option<Node<'a, V, M, P>>, V::Item: Send + Sync,

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>
where T: Traverser<OverData>, Self: Sized,

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>
where T: Traverser<OverData>, Self: Sized, V::Item: Send + Sync,

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>>>
where O: Over, T: Traverser<O>, Self: Sized, 't: 'a,

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>>>
where O: Over, T: Traverser<O>, Self: Sized, <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>: Send + Sync, 't: 'a,

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>
where T: Traverser<OverData>,

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>
where T: Traverser<OverData>, V::Item: Send + Sync,

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>
where O: Over<Enumeration = Val>, T: Traverser<O>,

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>
where O: Over<Enumeration = Val>, T: Traverser<O>, V::Item: Send + Sync, Self: Sync,

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>
where V2: TreeVariant<Item = V::Item> + 'a, P::PinnedVec<V2>: Default, V::Item: Clone,

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>
where T: Traverser<OverData>,

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>
where T: Traverser<OverData>, V::Item: Send + Sync,

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>>>
where O: Over, T: Traverser<O>,

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>>>
where O: Over, T: Traverser<O>, <<O as Over>::Enumeration as Enumeration>::Item<<O as Over>::NodeItem<'a, V, M, P>>: Send + Sync,

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>>
where T: Traverser<OverData>, V: 'static,

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>>>
where O: Over, T: Traverser<O>, V: 'static, Self: Sized,

Returns an iterator of node indices. Read more
Source§

fn as_cloned_subtree(self) -> ClonedSubTree<'a, V, M, P, Self>
where V::Item: Clone, Self: Sized,

Creates a subtree view including this node as the root and all of its descendants with their orientation relative to this node. Read more
Source§

fn as_copied_subtree(self) -> CopiedSubTree<'a, V, M, P, Self>
where V::Item: Copy, Self: Sized,

Creates a subtree view including this node as the root and all of its descendants with their orientation relative to this node. Read more
Source§

impl<T> SoM<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
Source§

fn get_mut(&mut self) -> &mut T

Returns a mutable reference to self.
Source§

impl<T> SoR<T> for T

Source§

fn get_ref(&self) -> &T

Returns a reference to self.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.