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>
impl<Ty, Op> OpenTree<Ty, Op>
Sourcepub fn graft(subtrees: impl IntoIterator<Item = Self>, op: Op) -> Self
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.
Sourcepub fn linear(iter: impl IntoIterator<Item = Op>) -> Option<Self>
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.
Sourcepub fn arity(&self) -> usize
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.
Sourcepub fn size(&self) -> usize
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.
Sourcepub fn only(self) -> Option<Op>
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.
Sourcepub fn is_isomorphic_to(&self, other: &Self) -> bool
pub fn is_isomorphic_to(&self, other: &Self) -> bool
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.
Trait Implementations§
impl<Ty: Eq, Op: Eq> Eq for OpenTree<Ty, Op>
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>where
Ty: RefUnwindSafe,
Op: RefUnwindSafe,
impl<Ty, Op> Send for OpenTree<Ty, Op>
impl<Ty, Op> Sync for OpenTree<Ty, Op>
impl<Ty, Op> Unpin for OpenTree<Ty, Op>
impl<Ty, Op> UnwindSafe for OpenTree<Ty, Op>where
Ty: UnwindSafe,
Op: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.