Trait Tree

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

Source

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

Source

fn get<'a>(&'a self, node: &'a Self::Position) -> Option<&'a T>

Returns an immutable reference to the node’s data type

Source

fn parent(&self, node: Self::Position) -> Option<Self::Position>

Returns the position of a node’s parent, if it exists

Source

fn is_root(&self, node: Self::Position) -> bool

Returns true if the specified position is the tree’s root

Source

fn is_leaf(&self, node: Self::Position) -> bool

Returns true if the specified position is external

Source

fn depth(&self, node: Self::Position) -> Option<usize>

Source

fn height(&self, node: Self::Position) -> Option<usize>

Source

fn num_children(&self, node: Self::Position) -> Option<usize>

Returns the immediate number of children for a given node

Implementors§

Source§

impl<T> Tree<T> for BinTree<T>
where T: Clone + PartialEq,