fn witness_for_subtree<Builder: WitnessBuilder>(
    hash_tree: &HashTree,
    sub_witnesses: &mut FlatMap<Label, Builder::Tree>,
) -> Builder::Tree {
    if any_is_in_range(hash_tree, sub_witnesses.keys()) {
        match hash_tree {
            HashTree::Fork {
                // inside HashTree, recurse to subtrees
                left_tree,
                right_tree,
                ..
            } => {
                let left_witness = witness_for_subtree::<Builder>(left_tree, sub_witnesses);
                let right_witness = witness_for_subtree::<Builder>(right_tree, sub_witnesses);
                Builder::make_fork(left_witness, right_witness)
            }
            HashTree::Node {
                // bottom of the HashTree, stop recursion
                digest,
                label,
                ..
            } => {
                if let Some(sub_witness) = sub_witnesses.remove(label) {
                    Builder::make_node(label.to_owned(), sub_witness)
                } else {
                    Builder::make_pruned(digest.to_owned())
                }
            }
            HashTree::Leaf { .. } => panic!("Unexpectedly reached {:?}", hash_tree),
        }
    } else {
        Builder::make_pruned(hash_tree.digest().to_owned())
    }
}
// Generates a witness for a HashTree that represents a single
// LabeledTree::SubTree node, and uses the given sub_witnesses
// for the children of the node (if provided).
Generates a witness for a HashTree that represents a single
LabeledTree::SubTree node, and uses the given sub_witnesses
for the children of the node (if provided).
Generates a witness for a HashTree that represents a single LabeledTree :: SubTree node and uses the given sub_witnesses for the children of the node ( if provided ) .
fn witness_for_subtree<Builder: WitnessBuilder>(
    hash_tree: &HashTree,
    sub_witnesses: &mut FlatMap<Label, Builder::Tree>,
) -> Builder::Tree {
    if any_is_in_range(hash_tree, sub_witnesses.keys()) {
        match hash_tree {
            HashTree::Fork {
                // inside HashTree, recurse to subtrees
                left_tree,
                right_tree,
                ..
            } => {
                let left_witness = witness_for_subtree::<Builder>(left_tree, sub_witnesses);
                let right_witness = witness_for_subtree::<Builder>(right_tree, sub_witnesses);
                Builder::make_fork(left_witness, right_witness)
            }
            HashTree::Node {
                // bottom of the HashTree, stop recursion
                digest,
                label,
                ..
            } => {
                if let Some(sub_witness) = sub_witnesses.remove(label) {
                    Builder::make_node(label.to_owned(), sub_witness)
                } else {
                    Builder::make_pruned(digest.to_owned())
                }
            }
            HashTree::Leaf { .. } => panic!("Unexpectedly reached {:?}", hash_tree),
        }
    } else {
        Builder::make_pruned(hash_tree.digest().to_owned())
    }
}
fn witness_for_subtree < Builder : WitnessBuilder > ( hash_tree : & HashTree , sub_witnesses : & mut FlatMap < Label , Builder :: Tree > , ) -> Builder :: Tree { if any_is_in_range ( hash_tree , sub_witnesses . keys ( ) ) { match hash_tree { HashTree :: Fork { // inside HashTree, recurse to subtrees left_tree , right_tree , .. } => { let left_witness = witness_for_subtree :: < Builder > ( left_tree , sub_witnesses ) ; let right_witness = witness_for_subtree :: < Builder > ( right_tree , sub_witnesses ) ; Builder :: make_fork ( left_witness , right_witness ) } HashTree :: Node { // bottom of the HashTree, stop recursion digest , label , .. } => { if let Some ( sub_witness ) = sub_witnesses . remove ( label ) { Builder :: make_node ( label . to_owned ( ) , sub_witness ) } else { Builder :: make_pruned ( digest . to_owned ( ) ) } } HashTree :: Leaf { .. } => panic ! ( " " hash_tree ) , } } else { Builder :: make_pruned ( hash_tree . digest ( ) . to_owned ( ) ) } }
Generates a witness for a HashTree that represents a single
LabeledTree::SubTree node, and uses the given sub_witnesses
for the children of the node (if provided).
Generates a witness for a HashTree that represents a single LabeledTree :: SubTree node and uses the given sub_witnesses for the children of the node ( if provided ) .
hash_tree
&HashTree
sub_witnesses
&mut FlatMap<Label, Builder::Tree>
hash_tree
&HashTree
sub_witnesses
&mut FlatMap<Label, Builder::Tree>