pub trait Tree<T> {
type Position;
// Required methods
fn children(&self, node: Self::Position) -> Option<Vec<Self::Position>>;
fn get<'a>(&'a self, node: &'a Self::Position) -> Option<&'a T>;
fn parent(&self, node: Self::Position) -> Option<Self::Position>;
fn is_root(&self, node: Self::Position) -> bool;
fn is_leaf(&self, node: Self::Position) -> bool;
fn depth(&self, node: Self::Position) -> Option<usize>;
fn height(&self, node: Self::Position) -> Option<usize>;
fn num_children(&self, node: Self::Position) -> Option<usize>;
}Expand description
Defines the a basic Tree ADT where P is a position, and T is a type
Required Associated Types§
Required Methods§
Sourcefn children(&self, node: Self::Position) -> Option<Vec<Self::Position>>
fn children(&self, node: Self::Position) -> Option<Vec<Self::Position>>
Returns an iterable collection over the node’s children
NOTE: To make this iterable into an iterator simply call something like self.children(node).into_iter()
Sourcefn get<'a>(&'a self, node: &'a Self::Position) -> Option<&'a T>
fn get<'a>(&'a self, node: &'a Self::Position) -> Option<&'a T>
Returns an immutable reference to the node’s data type
Sourcefn parent(&self, node: Self::Position) -> Option<Self::Position>
fn parent(&self, node: Self::Position) -> Option<Self::Position>
Returns the position of a node’s parent, if it exists
Sourcefn is_root(&self, node: Self::Position) -> bool
fn is_root(&self, node: Self::Position) -> bool
Returns true if the specified position is the tree’s root
Sourcefn is_leaf(&self, node: Self::Position) -> bool
fn is_leaf(&self, node: Self::Position) -> bool
Returns true if the specified position is external
fn depth(&self, node: Self::Position) -> Option<usize>
fn height(&self, node: Self::Position) -> Option<usize>
Sourcefn num_children(&self, node: Self::Position) -> Option<usize>
fn num_children(&self, node: Self::Position) -> Option<usize>
Returns the immediate number of children for a given node