Enum Tree

Source
pub enum Tree<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,
{ 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§

§

Binary

Fields

§conn: B
§left: Box<Tree<B, U, A>>
§right: Box<Tree<B, U, A>>
§

Unary

Fields

§conn: U
§next: Box<Tree<B, U, A>>
§

Atom(A)

Implementations§

Source§

impl<B, U, A> Tree<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,

Only the most basic manipulations (adding unary operators and combining formulas) are provided; more complex manipulations are provided by the Formula which is much more ergonomic for expressing in-place mutation using its internal Zipper Zipper: Zipper Formula: Formula

Source

pub fn new(atom: A) -> Self

Source

pub fn is_atomic(&self) -> bool

Source

pub fn is_unary(&self) -> bool

Source

pub fn is_binary(&self) -> bool

Source

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.

Source

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.

Source

pub fn combine(&mut self, bin: B, formula: Self)

Combine two trees with a binary operator, inserting the new tree on the right side.

Source

pub fn left_combine(&mut self, bin: B, formula: Self)

Combine with new tree on the left!

Source

pub fn unify(&mut self, un: U)

Add a unary operator to the existing formula.

Source

pub fn read_inorder(&self, repr: &mut String)

Print the customary inorder traversal of a tree formula into an outparameter.

Trait Implementations§

Source§

impl<B, U, A> Clone for Tree<B, U, A>
where B: Symbolic + Clone, U: Symbolic + Clone, A: Symbolic + Clone,

Source§

fn clone(&self) -> Tree<B, U, A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B, U, A> Debug for Tree<B, U, A>
where B: Symbolic + Debug, U: Symbolic + Debug, A: Symbolic + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B, U, A> Default for Tree<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,

Source§

fn default() -> Self

Assuming A::default() returns a 0 value, effectively amounts to a null value without allowing invalid trees to be constructed.

Source§

impl<B, U, A> Display for Tree<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B, U, A> From<&Formula<B, U, A>> for Tree<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,

If you’re really lazy I guess!

Source§

fn from(value: &Formula<B, U, A>) -> Self

Converts to this type from the input type.
Source§

impl<B, U, A> From<Tree<B, U, A>> for Formula<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,

Source§

fn from(value: Tree<B, U, A>) -> Self

Converts to this type from the input type.
Source§

impl<B, U, A> Hash for Tree<B, U, A>
where B: Symbolic + Hash, U: Symbolic + Hash, A: Symbolic + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<B, U, A> Ord for Tree<B, U, A>
where B: Symbolic + Ord, U: Symbolic + Ord, A: Symbolic + Ord,

Source§

fn cmp(&self, other: &Tree<B, U, A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<B, U, A> PartialEq for Tree<B, U, A>

Source§

fn eq(&self, other: &Tree<B, U, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<B, U, A> PartialOrd for Tree<B, U, A>

Source§

fn partial_cmp(&self, other: &Tree<B, U, A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B, U, A> Eq for Tree<B, U, A>
where B: Symbolic + Eq, U: Symbolic + Eq, A: Symbolic + Eq,

Source§

impl<B, U, A> StructuralPartialEq for Tree<B, U, A>
where B: Symbolic, U: Symbolic, A: Symbolic,

Auto Trait Implementations§

§

impl<B, U, A> Freeze for Tree<B, U, A>
where B: Freeze, U: Freeze, A: Freeze,

§

impl<B, U, A> RefUnwindSafe for Tree<B, U, A>

§

impl<B, U, A> Send for Tree<B, U, A>
where B: Send, U: Send, A: Send,

§

impl<B, U, A> Sync for Tree<B, U, A>
where B: Sync, U: Sync, A: Sync,

§

impl<B, U, A> Unpin for Tree<B, U, A>
where B: Unpin, U: Unpin, A: Unpin,

§

impl<B, U, A> UnwindSafe for Tree<B, U, A>
where B: UnwindSafe, U: UnwindSafe, A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.