pub struct BinaryTree<T>where
T: Hash,{
pub root: Option<NodeId>,
/* private fields */
}Expand description
The most basic tree in woodland. All nodes stored in the tree are BinaryTreeNode<T>s.
NOTE: The TreeOperations::insert() definition for this tree will call std::unimplemented
as there is no invariant to fall back on to determine where to insert the node.
Example usage:
use woodland::prelude::*;
use woodland::binary_tree::BinaryTree;
/* Tree looks like the following:
*
* 4
* / \
* 2 6
* / \ / \
* 1 3 5 7
*/
let mut new_tree = BinaryTree::<u8>::new();
let left_left_id = new_tree.create_node(1);
let left_right_id = new_tree.create_node(3);
let left_id = new_tree.create_node(2);
let right_id = new_tree.create_node(6);
let right_left_id = new_tree.create_node(5);
let right_right_id = new_tree.create_node(7);
new_tree.root = Some(new_tree.create_node(4));
let root_ref = new_tree.get_node_mut(new_tree.root.unwrap()).unwrap();
root_ref.set_left(Some(left_id));
root_ref.set_right(Some(right_id));
let left_ref = new_tree.get_node_mut(left_id).unwrap();
left_ref.set_left(Some(left_left_id));
left_ref.set_right(Some(left_right_id));
let right_ref = new_tree.get_node_mut(right_id).unwrap();
right_ref.set_left(Some(right_left_id));
right_ref.set_right(Some(right_right_id));Fields§
§root: Option<NodeId>The root node’s NodeId.
Trait Implementations§
Source§impl<'a, T> IterativeTreeOperations<BinaryTreeNode<T>> for BinaryTree<T>
impl<'a, T> IterativeTreeOperations<BinaryTreeNode<T>> for BinaryTree<T>
Source§fn preorder_iter(&self) -> Box<dyn Iterator<Item = &BinaryTreeNode<T>> + '_>
fn preorder_iter(&self) -> Box<dyn Iterator<Item = &BinaryTreeNode<T>> + '_>
Get a preorder traveral iterator.
Source§fn inorder_iter(&self) -> Box<dyn Iterator<Item = &BinaryTreeNode<T>> + '_>
fn inorder_iter(&self) -> Box<dyn Iterator<Item = &BinaryTreeNode<T>> + '_>
Get an inorder traversal iterator.
Source§fn postorder_iter(&self) -> Box<dyn Iterator<Item = &BinaryTreeNode<T>> + '_>
fn postorder_iter(&self) -> Box<dyn Iterator<Item = &BinaryTreeNode<T>> + '_>
Get a postorder traversal iterator.
Source§impl<T> TreeOperations<BinaryTreeNode<T>> for BinaryTree<T>
impl<T> TreeOperations<BinaryTreeNode<T>> for BinaryTree<T>
Source§fn create_node(&mut self, data: T) -> NodeId
fn create_node(&mut self, data: T) -> NodeId
Genereate a new mutable reference to a NodeType. You must call this function to get new references
since we are allocating all references in the Arena.
Source§fn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns
true if there are no nodes in the tree, and returns false otherwise.Source§fn get_node(&self, node_id: NodeId) -> Option<&BinaryTreeNode<T>>
fn get_node(&self, node_id: NodeId) -> Option<&BinaryTreeNode<T>>
Get a refrence to a
NodeType<T> from a given NodeId, if a node with the specified
NodeId exists in the tree.Source§fn get_node_mut(&mut self, node_id: NodeId) -> Option<&mut BinaryTreeNode<T>>
fn get_node_mut(&mut self, node_id: NodeId) -> Option<&mut BinaryTreeNode<T>>
Get a mutable reference to a
NodeType<T> from a given NodeId, if a node with the
specified NodeId exists in the tree.Auto Trait Implementations§
impl<T> Freeze for BinaryTree<T>
impl<T> RefUnwindSafe for BinaryTree<T>where
T: RefUnwindSafe,
impl<T> Send for BinaryTree<T>where
T: Send,
impl<T> Sync for BinaryTree<T>where
T: Sync,
impl<T> Unpin for BinaryTree<T>where
T: Unpin,
impl<T> UnwindSafe for BinaryTree<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more