[−][src]Struct read_tree::Node
A slice of a Tree
<T>
or PolyTree
<T>
.
A node is essentially the same as a tree, except it does not own its data.
Navigating the subtree of a node is done using iterators.
It is planned to add a query type that allows querying nodes from subtrees using chains of conditions. Currently only some basic iterators are available.
Methods
impl<'a, T> Node<'a, T>
[src]
pub fn from(verts: &[Vertex<T>]) -> Result<Node<T>, ValidationError>
[src]
Turns a slice of vertices into a Node
<T>
, after performing some
validations.
Returns an error in case of a failed validation. For the possible errors
see ValidationError
. For a more detailed description of the
validation process see the safety section for from_unchecked
.
To avoid running the validations; which have a significant cost for
large trees; use the unsafe alternative from_unchecked
.
pub unsafe fn from_unchecked(verts: &[Vertex<T>]) -> Node<T>
[src]
Returns a slice of vertices as a Node
<T>
.
This is the unsafe alternative to from
that skips all validations.
Safety
The caller must guarantee that all expected qualities of the vertex slice are fulfilled.
-
The vertex slice must not be empty.
-
The first vertex must span the entire slice.
This means that the
len
of the first vertex is equal toverts.len() - 1
. -
The scope of all vertices must be contained within the scope of its parent vertex
Here
scope
refers to the range starting from a nodes index to the nodes index plus itslen
inclusive.
pub fn data(self) -> &'a T
[src]
Returns a reference to the payload of the node.
pub fn rank(self) -> usize
[src]
Returns the rank of the node in the tree. The rank can be used to look
up the node from the tree using get
.
The rank also exposes information about the structure of the tree. Any
node child
with a rank greater than that of a node parent
but not
exceeding parent.rank() + parent.len()
is a descendant of parent
.
pub fn len(self) -> usize
[src]
Returns the number of descending nodes within the subtree of this node.
A leaf node returns length 0
.
pub fn is_empty(self) -> bool
[src]
Returns true
if the node has no child nodes.
pub fn get(self, rank: usize) -> Option<Node<'a, T>>
[src]
Returns the node with the specified rank
.
The rank must be relative to the trees root, or the most recently pruned
node. See isolated
for more information.
pub fn parent(self) -> Option<Node<'a, T>>
[src]
Returns the parent of the node or None
if it does not have one.
ⓘImportant traits for Children<'a, T>pub fn children(self) -> Children<'a, T>
[src]
Returns an iterator over the child nodes of the node. See Children
for more information about the iterator.
ⓘImportant traits for Descendants<'a, T>pub fn descendants(self) -> Descendants<'a, T>
[src]
Returns a depth first iterator of nodes. It iterates all nodes in the
subtree of the node, including the node itself. See Descendants
for
more information about the iterator.
ⓘImportant traits for Ancestors<'a, T>pub fn ancestors(self) -> Ancestors<'a, T>
[src]
Returns an iterator over the parent nodes. The parent of the node is
first. The root of the tree is last. See Ancestors
for more
information about the iterator.
pub fn as_slice(self) -> &'a [Vertex<T>]
[src]
Returns the nodes internal vertex slice.
pub fn isolated(self) -> Node<'a, T>
[src]
Returns the node isolated from the rest of the tree.
An isolated node will always have rank 0
, and it will be impossible to
access its ancestors. It is still possible to explore the subtree below
the node.
When getting nodes by rank you must get them from this or any descending node. If you use the rank in a node that is not affected by this isolation, it will return some other node. Think of the isolated node as an entirely new tree with its own ranking.
pub fn into_tree(self) -> Tree<T> where
T: Clone,
[src]
T: Clone,
Clones the contents of the node into a new Tree
<T>
.
Similar to push_node
this operation is cheaper if T
implements
Copy
. It is internally based on Vec::extend_from_slice
.
Trait Implementations
impl<'a, T> Clone for Node<'a, T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a, T> Copy for Node<'a, T>
[src]
impl<'a, T: Debug> Debug for Node<'a, T>
[src]
Auto Trait Implementations
impl<'a, T> Send for Node<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Sync for Node<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Unpin for Node<'a, T>
impl<'a, T> UnwindSafe for Node<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T> RefUnwindSafe for Node<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,