Struct rose_tree::RoseTree [−][src]
Expand description
An indexable tree data structure with a variable and unbounded number of branches per node.
Also known as a multi-way tree.
See the wikipedia article on the “Rose tree” data structure.
Note: The following documentation is adapted from petgraph’s [Graph documentation] (http://bluss.github.io/petulant-avenger-graphlibrary/doc/petgraph/graph/struct.Graph.html).
RoseTree is parameterized over the node weight N and Ix which is the index type used.
A wrapper around petgraph’s Graph data structure with a refined API specifically targeted towards use as a RoseTree.
NodeIndex is a type that acts as a reference to nodes, but these are only stable across certain operations. Removing nodes may shift other indices. Adding kids to the RoseTree keeps all indices stable, but removing a node will force the last node to shift its index to take its place.
The fact that the node indices in the RoseTree are numbered in a compact interval from 0 to n-1 simplifies some graph algorithms.
The Ix parameter is u32 by default. The goal is that you can ignore this parameter completely unless you need a very large RoseTree – then you can use usize.
The RoseTree also offers methods for accessing the underlying Graph, which can be useful for taking advantage of petgraph’s various graph-related algorithms.
Implementations
Create a new RoseTree
along with some root node.
Returns both the RoseTree
and an index into the root node in a tuple.
Create a new RoseTree
with estimated capacity and some root node.
Returns both the RoseTree
and an index into the root node in a tuple.
The total number of nodes in the RoseTree.
Borrow the RoseTree
’s underlying PetGraph<N, Ix>
.
All existing NodeIndex
s may be used to index into this graph the same way they may be
used to index into the RoseTree
.
Take ownership of the RoseTree and return the internal PetGraph<N, Ix>.
All existing NodeIndex
s may be used to index into this graph the same way they may be
used to index into the RoseTree
.
Add a child node to the node at the given NodeIndex. Returns an index into the child’s position within the tree.
Computes in O(1) time.
Panics if the given parent node doesn’t exist.
Panics if the Graph is at the maximum number of edges for its index.
Borrow the weight from the node at the given index.
Mutably borrow the weight from the node at the given index.
Index the RoseTree
by two node indices.
Panics if the indices are equal or if they are out of bounds.
Remove all nodes in the RoseTree
except for the root.
Removes and returns the node at the given index.
The parent of node
will become the new parent for all of its children.
The root node cannot be removed. If its index is given, None
will be returned.
Note: this method may shift other node indices, invalidating previously returned indices!
Removes the node at the given index along with all their children, returning them as a new RoseTree.
If there was no node at the given index, None
will be returned.
An index to the parent of the node at the given index if there is one.
pub fn parent_recursion(
&self,
child: NodeIndex<Ix>
) -> ParentRecursion<'_, N, Ix>ⓘNotable traits for ParentRecursion<'a, N, Ix>impl<'a, N, Ix> Iterator for ParentRecursion<'a, N, Ix> where
Ix: IndexType, type Item = NodeIndex<Ix>;
pub fn parent_recursion(
&self,
child: NodeIndex<Ix>
) -> ParentRecursion<'_, N, Ix>ⓘNotable traits for ParentRecursion<'a, N, Ix>impl<'a, N, Ix> Iterator for ParentRecursion<'a, N, Ix> where
Ix: IndexType, type Item = NodeIndex<Ix>;
impl<'a, N, Ix> Iterator for ParentRecursion<'a, N, Ix> where
Ix: IndexType, type Item = NodeIndex<Ix>;
An iterator over the given child’s parent, that parent’s parent and so forth.
The returned iterator yields NodeIndex<Ix>
s.
An iterator over all nodes that are children to the node at the given index.
The returned iterator yields NodeIndex<Ix>
s.
A “walker” object that may be used to step through the children of the given parent node.
Unlike the Children
type, WalkChildren
does not borrow the RoseTree
.
An iterator over all nodes that are siblings to the node at the given index.
The returned iterator yields NodeIndex<Ix>
s.
A “walker” object that may be used to step through the siblings of the given child node.
Unlike the Siblings
type, WalkSiblings
does not borrow the RoseTree
.
Trait Implementations
Auto Trait Implementations
impl<N, Ix> RefUnwindSafe for RoseTree<N, Ix> where
Ix: RefUnwindSafe,
N: RefUnwindSafe,
impl<N, Ix> UnwindSafe for RoseTree<N, Ix> where
Ix: UnwindSafe,
N: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more