fn traverse_old_on_create(
        old_cell: &Cell,
        new_cells: &HashMap<UInt256, Cell>,
        pruned_branches: &mut HashMap<UInt256, Cell>
    ) -> Result<Option<BuilderData>> {

        let mut childs = vec!(None; old_cell.references_count());
        let mut has_pruned = false;

        for (i, child) in old_cell.clone_references().iter().enumerate() {
            let child_hash = child.repr_hash();
            if let Some(common_cell) = new_cells.get(&child_hash) {

                let pruned_branch_cell = Self::make_pruned_branch_cell(common_cell, 0)?;
                pruned_branches.insert(child_hash, pruned_branch_cell.clone().into_cell()?);

                childs[i] = Some(pruned_branch_cell);
                has_pruned = true;
            } else {
                childs[i] = Self::traverse_old_on_create(child, new_cells, pruned_branches)?;
                if childs[i].is_some() {
                    has_pruned = true;
                }
            }
        }

        if has_pruned {

            let mut old_update_cell = BuilderData::new();
            let mut child_mask = LevelMask::with_mask(0);
            for (i, child_opt) in childs.into_iter().enumerate() {
                let child = match child_opt {
                    None => {
                        let child = old_cell.reference(i).unwrap();
                        Self::make_pruned_branch_cell(&child, 0)?
                    }
                    Some(child) => child
                };
                child_mask |= child.level_mask();
                old_update_cell.append_reference_cell(child.into_cell()?);
            }
            old_update_cell.set_level_mask(child_mask);

            old_update_cell.append_bytestring(&SliceData::from(old_cell)).unwrap();
            Ok(Some(old_update_cell))

        } else {
            Ok(None)
        }
    }
// If old_cell's child contains in new_cells - it transformed to pruned branch cell,
//   else - recursion call for the child.
// If any child is pruned branch (or contains pruned branch among their subtree) 
//   - all other skipped childs are transformed to pruned branches
//   else - skip this cell (return None)
If old_cell's child contains in new_cells - it transformed to pruned branch cell,
else - recursion call for the child.
If any child is pruned branch (or contains pruned branch among their subtree)
all other skipped childs are transformed to pruned branches
else - skip this cell (return None)
If old_cell ' s child contains in new_cells - it transformed to pruned branch cell else - recursion call for the child . If any child is pruned branch ( or contains pruned branch among their subtree ) all other skipped childs are transformed to pruned branches else - skip this cell ( return None )
fn traverse_old_on_create(
        old_cell: &Cell,
        new_cells: &HashMap<UInt256, Cell>,
        pruned_branches: &mut HashMap<UInt256, Cell>
    ) -> Result<Option<BuilderData>> {
        let mut childs = vec!(None; old_cell.references_count());
        let mut has_pruned = false;
        for (i, child) in old_cell.clone_references().iter().enumerate() {
            let child_hash = child.repr_hash();
            if let Some(common_cell) = new_cells.get(&child_hash) {
                let pruned_branch_cell = Self::make_pruned_branch_cell(common_cell, 0)?;
                pruned_branches.insert(child_hash, pruned_branch_cell.clone().into_cell()?);
                childs[i] = Some(pruned_branch_cell);
                has_pruned = true;
            } else {
                childs[i] = Self::traverse_old_on_create(child, new_cells, pruned_branches)?;
                if childs[i].is_some() {
                    has_pruned = true;
                }
            }
        }
        if has_pruned {
            let mut old_update_cell = BuilderData::new();
            let mut child_mask = LevelMask::with_mask(0);
            for (i, child_opt) in childs.into_iter().enumerate() {
                let child = match child_opt {
                    None => {
                        let child = old_cell.reference(i).unwrap();
                        Self::make_pruned_branch_cell(&child, 0)?
                    }
                    Some(child) => child
                };
                child_mask |= child.level_mask();
                old_update_cell.append_reference_cell(child.into_cell()?);
            }
            old_update_cell.set_level_mask(child_mask);
            old_update_cell.append_bytestring(&SliceData::from(old_cell)).unwrap();
            Ok(Some(old_update_cell))
        } else {
            Ok(None)
        }
    }
fn traverse_old_on_create ( old_cell : & Cell , new_cells : & HashMap < UInt256 , Cell > , pruned_branches : & mut HashMap < UInt256 , Cell > ) -> Result < Option < BuilderData > > { let mut childs = vec ! ( None old_cell references_count ( ) ) ; let mut has_pruned = false ; for ( i , child ) in old_cell . clone_references ( ) . iter ( ) . enumerate ( ) { let child_hash = child . repr_hash ( ) ; if let Some ( common_cell ) = new_cells . get ( & child_hash ) { let pruned_branch_cell = Self :: make_pruned_branch_cell ( common_cell , 0 ) ? ; pruned_branches . insert ( child_hash , pruned_branch_cell . clone ( ) . into_cell ( ) ? ) ; childs [ i ] = Some ( pruned_branch_cell ) ; has_pruned = true ; } else { childs [ i ] = Self :: traverse_old_on_create ( child , new_cells , pruned_branches ) ? ; if childs [ i ] . is_some ( ) { has_pruned = true ; } } } if has_pruned { let mut old_update_cell = BuilderData :: new ( ) ; let mut child_mask = LevelMask :: with_mask ( 0 ) ; for ( i , child_opt ) in childs . into_iter ( ) . enumerate ( ) { let child = match child_opt { None => { let child = old_cell . reference ( i ) . unwrap ( ) ; Self :: make_pruned_branch_cell ( & child , 0 ) ? } Some ( child ) => child } ; child_mask |= child . level_mask ( ) ; old_update_cell . append_reference_cell ( child . into_cell ( ) ? ) ; } old_update_cell . set_level_mask ( child_mask ) ; old_update_cell . append_bytestring ( & SliceData :: from ( old_cell ) ) . unwrap ( ) ; Ok ( Some ( old_update_cell ) ) } else { Ok ( None ) } }
If old_cell's child contains in new_cells - it transformed to pruned branch cell,
else - recursion call for the child.
If old_cell ' s child contains in new_cells - it transformed to pruned branch cell else - recursion call for the child .
old_cell
&Cell
new_cells
&HashMap<UInt256, Cell>
pruned_branches
&mut HashMap<UInt256, Cell>
old_cell
&Cell
new_cells
&HashMap<UInt256, Cell>
pruned_branches
&mut HashMap<UInt256, Cell>