pub trait MutBorrowedTreeNode<'a>
where Self: Sized + 'a,
{ type MutBorrowedValue: Sized; type MutBorrowedChildren: Iterator<Item = &'a mut Self>; // Required method fn get_value_and_children_iter_mut( &'a mut self ) -> (Self::MutBorrowedValue, Option<Self::MutBorrowedChildren>); // Provided methods fn bfs_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue> { ... } fn dfs_preorder_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue> { ... } fn dfs_postorder_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue> { ... } }
Expand description

A tree node where getting its children mutably borrows its value.

Required Associated Types§

source

type MutBorrowedValue: Sized

A mutable reference to the value of each node in the tree.

source

type MutBorrowedChildren: Iterator<Item = &'a mut Self>

The type of iterator that can be used to iterate over each node’s children collection.

Required Methods§

source

fn get_value_and_children_iter_mut( &'a mut self ) -> (Self::MutBorrowedValue, Option<Self::MutBorrowedChildren>)

This method gets the value and children from this node. The other methods of this trait assume that the ‘Children’ list does not contain any circular references. If there are, an infinite loop will result.

Provided Methods§

source

fn bfs_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue>

This method retrieves an iterator that can be used to perform Breadth First (VecDeque-based) searches of a tree.

A Breadth First Search (BFS) is defined as:

A tree traversal that involves breadth-first searching a tree from the top down. Given a tree of the following shape, this traversal type would traverse the elements in the order 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

In this traversal, we scan each level of the tree from left to right before going down to the next level.

       0
      / \
     1   2
    / \ / \
   3  4 5  6
          /
         7
          \
           8
          /
         9
          \
          10
source

fn dfs_preorder_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue>

This method retrieves an iterator that can be used to perform Depth First Preorder searches of a tree.

A Depth First Preorder search is defined as:

A tree traversal that involves depth-first searching a tree from the top down. Given a tree of the following shape, this traversal type would traverse the elements in the order 0, 1, 3, 4, 2, 5, 6, 7, 8, 9, 10.

In this traversal, each node will only be traversed before any of its children have been traversed.

       0
      / \
     1   2
    / \ / \
   3  4 5  6
          /
         7
          \
           8
          /
         9
          \
          10
source

fn dfs_postorder_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue>

This method retrieves an iterator that can be used to perform Depth First Postorder searches of a tree.

A Depth First Postorder search (referred to as DFS Postorder) is defined as:

A tree traversal that involves depth-first searching a tree from the bottom up. Given a tree of the following shape, this traversal type would traverse the elements in the order 3, 4, 1, 5, 10, 9, 8, 7, 6, 2, 0.

In this traversal, each node will only be traversed after all of its children have been traversed.

       0
      / \
     1   2
    / \ / \
   3  4 5  6
          /
         7
          \
           8
          /
         9
          \
          10

This traversal type guarantees that getChildren() will only be called once per node of the tree.

Object Safety§

This trait is not object safe.

Implementors§