Struct mt_dom::patch::TreePath [−][src]
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
node_idx: usize
The node_idx
is the index when traversing the DOM tree depth first.
0 is the root node, 1 is the first child of the root node, 2 is the first child of first
child
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
create a tree path which starts at node_idx
0 and traversal path path
at vec![0]
.
create a TreePath with node index node_idx
and traversal path path
find the node using the path of this tree path
find the node using the node_idx of this tree path
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for TreePath
impl UnwindSafe for TreePath
Blanket Implementations
Mutably borrows from an owned value. Read more