fn add_node_to_parents<K, V>(
    path_to_leaf: &[u8],
    new_parent_node: Trie<K, V>,
    mut parents: Parents<K, V>,
) -> Result<Parents<K, V>, bytesrepr::Error>
where
    K: ToBytes,
    V: ToBytes,
{
    // TODO: add is_node() method to Trie
    match new_parent_node {
        Trie::Node { .. } => (),
        _ => panic!("new_parent must be a node"),
    }
    // The current depth will be the length of the path to the new parent node.
    let depth: usize = {
        // Get the path to this node
        let path_to_node: Vec<u8> = get_parents_path(&parents);
        // Check that the path to the node is a prefix of the current path
        let current_path = common_prefix(&path_to_leaf, &path_to_node);
        assert_eq!(current_path, path_to_node);
        // Get the length
        path_to_node.len()
    };
    // Index path by current depth;
    let index = {
        assert!(
            depth < path_to_leaf.len(),
            "depth must be < {}",
            path_to_leaf.len()
        );
        path_to_leaf[depth]
    };
    // Add node to parents, along with index to modify
    parents.push((index, new_parent_node));
    Ok(parents)
}
/// Takes a path to a leaf, that leaf's parent node, and the parents of that
/// node, and adds the node to the parents.
///
/// This function will panic if the the path to the leaf and the path to its
/// parent node do not share a common prefix.
Takes a path to a leaf, that leaf's parent node, and the parents of that
node, and adds the node to the parents.

This function will panic if the the path to the leaf and the path to its
parent node do not share a common prefix.
Takes a path to a leaf that leaf ' s parent node and the parents of that node and adds the node to the parents . This function will panic if the the path to the leaf and the path to its parent node do not share a common prefix .
fn add_node_to_parents<K, V>(
    path_to_leaf: &[u8],
    new_parent_node: Trie<K, V>,
    mut parents: Parents<K, V>,
) -> Result<Parents<K, V>, bytesrepr::Error>
where
    K: ToBytes,
    V: ToBytes,
{
    // TODO: add is_node() method to Trie
    match new_parent_node {
        Trie::Node { .. } => (),
        _ => panic!("new_parent must be a node"),
    }
    // The current depth will be the length of the path to the new parent node.
    let depth: usize = {
        // Get the path to this node
        let path_to_node: Vec<u8> = get_parents_path(&parents);
        // Check that the path to the node is a prefix of the current path
        let current_path = common_prefix(&path_to_leaf, &path_to_node);
        assert_eq!(current_path, path_to_node);
        // Get the length
        path_to_node.len()
    };
    // Index path by current depth;
    let index = {
        assert!(
            depth < path_to_leaf.len(),
            "depth must be < {}",
            path_to_leaf.len()
        );
        path_to_leaf[depth]
    };
    // Add node to parents, along with index to modify
    parents.push((index, new_parent_node));
    Ok(parents)
}
fn add_node_to_parents < K , V > ( path_to_leaf : & [ u8 ] , new_parent_node : Trie < K , V > , mut parents : Parents < K , V > , ) -> Result < Parents < K , V > , bytesrepr :: Error > where K : ToBytes , V : ToBytes , { // TODO: add is_node() method to Trie match new_parent_node { Trie :: Node { .. } => ( ) , _ => panic ! ( " " ) , } // The current depth will be the length of the path to the new parent node. let depth : usize = { // Get the path to this node let path_to_node : Vec < u8 > = get_parents_path ( & parents ) ; // Check that the path to the node is a prefix of the current path let current_path = common_prefix ( & path_to_leaf , & path_to_node ) ; assert_eq ! ( current_path path_to_node ) ; // Get the length path_to_node . len ( ) } ; // Index path by current depth; let index = { assert ! ( depth path_to_leaf len ( ) " " path_to_leaf len ( ) ) ; path_to_leaf [ depth ] } ; // Add node to parents, along with index to modify parents . push ( ( index , new_parent_node ) ) ; Ok ( parents ) }
Takes a path to a leaf, that leaf's parent node, and the parents of that
node, and adds the node to the parents.
Takes a path to a leaf that leaf ' s parent node and the parents of that node and adds the node to the parents .
path_to_leaf
&[u8]
new_parent_node
Trie<K, V>
parents
Parents<K, V>
path_to_leaf
&[u8]
new_parent_node
Trie<K, V>
parents
Parents<K, V>