Struct mt_dom::patch::TreePath[][src]

pub struct TreePath {
    pub node_idx: usize,
    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 = [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

add a path node idx

find the node using the path of this tree path

find the node using the node_idx of this tree path

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.