Enum OpenTree

Source
pub enum OpenTree<Ty, Op> {
    Id(Ty),
    Comp(Tree<Option<Op>>),
}
Expand description

An open tree, or tree with boundary.

In a non-empty open tree, backed by a [Tree], each node carries either an operation or a null value. The null nodes constitute the boundary of the tree. It is an error for null nodes to have children or for the root to be null. Failure to maintain this invariant may result in panics.

Compare with the Path data type, of which this type may be considered a generalization.

Variants§

§

Id(Ty)

The identity, or empty, tree on a type.

§

Comp(Tree<Option<Op>>)

A rooted tree, representing a nonempty composite of operations.

Implementations§

Source§

impl<Ty, Op> OpenTree<Ty, Op>

Source

pub fn empty(ty: Ty) -> Self

Constructs the empty or identity tree.

Source

pub fn single(op: Op, arity: usize) -> Self

Constructs a singleton tree with the given arity.

Source

pub fn graft(subtrees: impl IntoIterator<Item = Self>, op: Op) -> Self

Constructs an open tree by grafting subtrees onto a root operation.

The root operation is assumed to have arity equal to the number of subtrees.

Source

pub fn linear(iter: impl IntoIterator<Item = Op>) -> Option<Self>

Constructs a linear open tree from a sequence of unary operations.

Each operation is assumed to be unary. This constructor returns nothing if the sequence is empty.

Source

pub fn arity(&self) -> usize

Gets the arity of the open tree.

The arity of an open tree is the number of boundary nodes in it.

Source

pub fn size(&self) -> usize

Gets the size of the open tree.

The size of an open tree is the number of non-boundary nodes in it, ignoring orphans.

Source

pub fn is_empty(&self) -> bool

Is the open tree empty?

Source

pub fn only(self) -> Option<Op>

Extracts the unique node in a tree of size 1.

This method is a one-sided inverse to OpenTree::single.

Source

pub fn is_isomorphic_to(&self, other: &Self) -> bool
where Ty: Eq, Op: Eq,

Is the open tree isomorphic to another?

Open trees should generally be compared for isomorphism rather than equality because, among other reasons, the flatten method produces orphan nodes.

Source

pub fn map<CodOp>(self, f: impl FnMut(Op) -> CodOp) -> OpenTree<Ty, CodOp>

Maps over the operations in the tree.

Source§

impl<Ty, Op> OpenTree<Ty, OpenTree<Ty, Op>>

Source

pub fn flatten(self) -> OpenTree<Ty, Op>

Flattens an open tree of open trees into a single open tree.

Trait Implementations§

Source§

impl<Ty: Clone, Op: Clone> Clone for OpenTree<Ty, Op>

Source§

fn clone(&self) -> OpenTree<Ty, Op>

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<Ty: Debug, Op: Debug> Debug for OpenTree<Ty, Op>

Source§

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

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

impl<E, ProE, Sq> From<OpenTree<ProE, DblNode<E, Sq>>> for DblTree<E, ProE, Sq>

Source§

fn from(value: OpenTree<ProE, DblNode<E, Sq>>) -> Self

Converts to this type from the input type.
Source§

impl<Ty, Op> From<Tree<Option<Op>>> for OpenTree<Ty, Op>

Source§

fn from(value: Tree<Option<Op>>) -> Self

Converts to this type from the input type.
Source§

impl<Ty: PartialEq, Op: PartialEq> PartialEq for OpenTree<Ty, Op>

Source§

fn eq(&self, other: &OpenTree<Ty, Op>) -> 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<Ty: Eq, Op: Eq> Eq for OpenTree<Ty, Op>

Source§

impl<Ty, Op> StructuralPartialEq for OpenTree<Ty, Op>

Auto Trait Implementations§

§

impl<Ty, Op> Freeze for OpenTree<Ty, Op>
where Ty: Freeze,

§

impl<Ty, Op> RefUnwindSafe for OpenTree<Ty, Op>

§

impl<Ty, Op> Send for OpenTree<Ty, Op>
where Ty: Send, Op: Send,

§

impl<Ty, Op> Sync for OpenTree<Ty, Op>
where Ty: Sync, Op: Sync,

§

impl<Ty, Op> Unpin for OpenTree<Ty, Op>
where Ty: Unpin, Op: Unpin,

§

impl<Ty, Op> UnwindSafe for OpenTree<Ty, Op>
where Ty: UnwindSafe, Op: 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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,