pub struct TreePath {
pub path: Vec<usize>,
}
Expand description
Describe the path traversal of a Node starting from the root node
The figure below shows node_idx
in a depth first traversal.
.─.
( 0 )
`-'
/ \
/ \
/ \
▼ ▼
.─. .─.
( 1 ) ( 4 )
`-' `-'
/ \ | \ '.
/ \ | \ '.
▼ ▼ | \ '.
.─. .─. ▼ ▼ ▼
( 2 ) ( 3 ) .─. .─. .─.
`─' `─' ( 5 ) ( 6 ) ( 7 )
`─' `─' `─'
The figure below shows the index of each child node relative to their parent node
.─.
( 0 )
`-'
/ \
/ \
/ \
▼ ▼
.─. .─.
( 0 ) ( 1 )
`-' `-'
/ \ | \ '.
/ \ | \ '.
▼ ▼ | \ '.
.─. .─. ▼ ▼ ▼
( 0 ) ( 1 ) .─. .─. .─.
`─' `─' ( 0 ) ( 1 ) ( 2 )
`─' `─' `─'
The equivalent idx and path are as follows:
0 = []
1 = [0]
2 = [0,0]
3 = [0,1]
4 = [1]
5 = [1,0]
6 = [1,1]
7 = [1,2]
Fields§
§path: Vec<usize>
An array of child index at each level of the dom tree. The children of the nodes at each child index is traverse at each traversal the first element of path is removed until the path becomes empty. If the path has become empty the node is said to be found.
Empty path means root node
Implementations§
source§impl TreePath
impl TreePath
sourcepub fn new(path: impl IntoIterator<Item = usize>) -> Self
pub fn new(path: impl IntoIterator<Item = usize>) -> Self
create a TreePath with node index node_idx
and traversal path path
sourcepub fn root() -> Self
pub fn root() -> Self
create a TreePath which starts at empty vec which is the root node of a DOM tree
sourcepub fn traverse(&self, node_idx: usize) -> Self
pub fn traverse(&self, node_idx: usize) -> Self
create a new TreePath with an added node_index This is used for traversing into child elements
sourcepub fn remove_first(&mut self) -> usize
pub fn remove_first(&mut self) -> usize
remove first node index of this treepath Everytime a node is traversed, the first element should be removed until no more index is in this path
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
returns tree if the path is empty This is used for checking if the path has been traversed
sourcepub fn find_node_by_path<'a, Ns, Tag, Leaf, Att, Val>(
&self,
node: &'a Node<Ns, Tag, Leaf, Att, Val>
) -> Option<&'a Node<Ns, Tag, Leaf, Att, Val>>
pub fn find_node_by_path<'a, Ns, Tag, Leaf, Att, Val>( &self, node: &'a Node<Ns, Tag, Leaf, Att, Val> ) -> Option<&'a Node<Ns, Tag, Leaf, Att, Val>>
find the node using the path of this tree path
Trait Implementations§
source§impl Ord for TreePath
impl Ord for TreePath
source§impl PartialEq for TreePath
impl PartialEq for TreePath
source§impl PartialOrd for TreePath
impl PartialOrd for TreePath
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more