pub struct Tree<T: Clone> { /* private fields */ }
Expand description
Stores all data and relationships between nodes
Implementations§
Source§impl<T: Clone> Tree<T>
impl<T: Clone> Tree<T>
Sourcepub fn is_valid(&self, node: NodeID) -> bool
pub fn is_valid(&self, node: NodeID) -> bool
Check if a node id
points to a valid, non-deleted node in the tree.
Returns true if the node id is valid.
§Arguments
node
- the NodeID to check
Sourcepub fn delete(&mut self, node: NodeID) -> usize
pub fn delete(&mut self, node: NodeID) -> usize
Mark a node in the tree, and all of its children as invalid. This allows the reuse of these indexes by other nodes created later. Returns the number of total nodes that were deleted.
Sourcepub fn get_mut(&mut self, node: NodeID) -> Option<&mut T>
pub fn get_mut(&mut self, node: NodeID) -> Option<&mut T>
Returns the mutable value for a node (if it exists)
Sourcepub fn get_unchecked(&self, node: NodeID) -> &T
pub fn get_unchecked(&self, node: NodeID) -> &T
Returns the value for a node, and panic if it doesn’t exist
Sourcepub fn get_unchecked_mut(&mut self, node: NodeID) -> &mut T
pub fn get_unchecked_mut(&mut self, node: NodeID) -> &mut T
Returns the mutable value for a node, and panic if it doesn’t exist
Sourcepub fn add_child(&mut self, node: NodeID, val: T) -> Option<NodeID>
pub fn add_child(&mut self, node: NodeID, val: T) -> Option<NodeID>
Add a child to the node and return its id (if successful)
Sourcepub fn add_child_unchecked(&mut self, node: NodeID, val: T) -> NodeID
pub fn add_child_unchecked(&mut self, node: NodeID, val: T) -> NodeID
Add a child to the node and return its id. Panics if node does not exist
Sourcepub fn children_ids_unchecked(&self, node: NodeID) -> &Vec<NodeID>
pub fn children_ids_unchecked(&self, node: NodeID) -> &Vec<NodeID>
Returns the children_ids for a node Panics if the node doesn’t exist
Sourcepub fn iter_depth(&self) -> DepthIter<'_, T> ⓘ
pub fn iter_depth(&self) -> DepthIter<'_, T> ⓘ
Returns a depth-first iterator This iterates a single node until a leaf is reached and then moves onto the next one
Sourcepub fn iter_breadth(&self) -> BreadthIter<'_, T> ⓘ
pub fn iter_breadth(&self) -> BreadthIter<'_, T> ⓘ
Returns a breadth-first iterator This iterates an entire depth-level before moving onto the next deepest nodes
Sourcepub fn path(&self, node: NodeID) -> Vec<NodeID>
pub fn path(&self, node: NodeID) -> Vec<NodeID>
Returns the node sequence from a root node to the given node
Sourcepub fn path_values_ref(&self, node: NodeID) -> Vec<&T>
pub fn path_values_ref(&self, node: NodeID) -> Vec<&T>
Returns references to values in the node sequence from a root node to the given node
Sourcepub fn path_values(&self, node: NodeID) -> Vec<T>
pub fn path_values(&self, node: NodeID) -> Vec<T>
Returns cloned values in the node sequence from a root node to the given node