pub struct Node<U, T> { /* private fields */ }
Expand description
Describes a node inside the Tree
U: is the type for the node indentifier (must implement PartialEq)
T: is the type for the node value
Implementations§
Source§impl<U, T> Node<U, T>where
U: PartialEq,
impl<U, T> Node<U, T>where
U: PartialEq,
Sourcepub fn new(id: U, value: T) -> Node<U, T>
pub fn new(id: U, value: T) -> Node<U, T>
Instantiates a new Node
.
In order to use query methods the ID should be unique for each node in the tree
Sourcepub fn with_child(self, child: Node<U, T>) -> Node<U, T>
pub fn with_child(self, child: Node<U, T>) -> Node<U, T>
Create a new child in this Node
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, Node<U, T>>
pub fn iter_mut(&mut self) -> IterMut<'_, Node<U, T>>
Returns a mutable iterator over Node
’s children
Sourcepub fn add_child(&mut self, child: Node<U, T>)
pub fn add_child(&mut self, child: Node<U, T>)
Add a child to the Node
If the child already exists, it will be replaced
Sourcepub fn remove_child(&mut self, id: &U)
pub fn remove_child(&mut self, id: &U)
Remove child from Node
Sourcepub fn truncate(&mut self, depth: usize)
pub fn truncate(&mut self, depth: usize)
Truncate tree at depth.
If depth is 0
, Node
’s children will be cleared
Sourcepub fn is_leaf(&self) -> bool
pub fn is_leaf(&self) -> bool
Returns whether this Node
is a leaf (which means it has no children)
Sourcepub fn query(&self, id: &U) -> Option<&Node<U, T>>
pub fn query(&self, id: &U) -> Option<&Node<U, T>>
Search for id
inside Node
and return a reference to it, if exists
Sourcepub fn query_mut(&mut self, id: &U) -> Option<&mut Node<U, T>>
pub fn query_mut(&mut self, id: &U) -> Option<&mut Node<U, T>>
Search for id
inside Node
and return a mutable reference to it, if exists
Sourcepub fn find<P>(&self, predicate: &P) -> Vec<&Node<U, T>>
pub fn find<P>(&self, predicate: &P) -> Vec<&Node<U, T>>
Find a node, in this branch, by predicate.
Sourcepub fn node_by_route(&self, route: &[usize]) -> Option<&Node<U, T>>
pub fn node_by_route(&self, route: &[usize]) -> Option<&Node<U, T>>
Given a vector of indexes, returns the node associated to the route