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 = [0]
1 = [0,0]
2 = [0,0,0]
3 = [0,0,1]
4 = [0,1]
5 = [0,1,0]
6 = [0,1,1]
7 = [0,1,2]
Fields
path: Vec<usize>
an alternative path vector, where it specifies
the first element is the index of the root node which is always 0
the second element is the index of the child to traverse to and so on.
Given a DOM tree where node_idx
and path
was derived from, we can
verify that node_idx and path point to the same node.
The advantage of using this is that this doesn’t need to traverse nodes that are not
relevant. Traversal operation complexity is O(log n)
Implementations
sourceimpl TreePath
impl TreePath
sourcepub fn new(path: Vec<usize>) -> Self
pub fn new(path: Vec<usize>) -> Self
create a TreePath with node index node_idx
and traversal path path
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>> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Clone + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
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>> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Clone + Debug,
LEAF: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
find the node using the path of this tree path
Trait Implementations
impl StructuralPartialEq for TreePath
Auto Trait Implementations
impl RefUnwindSafe for TreePath
impl Send for TreePath
impl Sync for TreePath
impl Unpin for TreePath
impl UnwindSafe for TreePath
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more