pub enum Tree<B, U, A>{
Binary {
conn: B,
left: Box<Tree<B, U, A>>,
right: Box<Tree<B, U, A>>,
},
Unary {
conn: U,
next: Box<Tree<B, U, A>>,
},
Atom(A),
}
Expand description
Classic tree implementation, but the enum variants
for Binary, Unary and Atom ensure that ill-formed
formulas can never be constructed. Uses Box
as internal pointer because we modify formulae through
a zipper. Within the formula struct, represents the
untraversed/‘unzipped’ parts of the formula.
Variants§
Implementations§
Source§impl<B, U, A> Tree<B, U, A>
impl<B, U, A> Tree<B, U, A>
pub fn new(atom: A) -> Self
pub fn is_atomic(&self) -> bool
pub fn is_unary(&self) -> bool
pub fn is_binary(&self) -> bool
Sourcepub fn inorder_traverse<F: FnMut(&Self) -> Option<()>>(
&self,
func: &mut F,
) -> Option<()>
pub fn inorder_traverse<F: FnMut(&Self) -> Option<()>>( &self, func: &mut F, ) -> Option<()>
Inorder traversal starting at the current zipper.
Does not mutate the formula at all but the closure passed
in is still std::ops::FnMut
so that other state
can be mutated. As usual returns [Option<()>
] so that
traversal can be stopped early by returning None
.
Sourcepub fn preorder_traverse<F: FnMut(&Self) -> Option<()>>(
&self,
func: &mut F,
) -> Option<()>
pub fn preorder_traverse<F: FnMut(&Self) -> Option<()>>( &self, func: &mut F, ) -> Option<()>
Preorder traversal starting at the current context. Also takes in a closure that can read the formula.
Sourcepub fn combine(&mut self, bin: B, formula: Self)
pub fn combine(&mut self, bin: B, formula: Self)
Combine two trees with a binary operator, inserting the new tree on the right side.
Sourcepub fn left_combine(&mut self, bin: B, formula: Self)
pub fn left_combine(&mut self, bin: B, formula: Self)
Combine with new tree on the left!
Sourcepub fn read_inorder(&self, repr: &mut String)
pub fn read_inorder(&self, repr: &mut String)
Print the customary inorder traversal of a tree formula into an outparameter.