fn slice_edge(
        slice: &mut SliceData, // slice without label
        bit_len: usize,
        prefix: SliceData,
        mut label: SliceData,
        mut key: SliceData,
        leaf: &BuilderData,
        extra: &Y
    ) -> Result<Y> {
        key.shrink_data(1..);
        let label_bit = label.get_next_bit()?;
        let length = bit_len - 1 - prefix.remaining_bits();
        let is_leaf = length == label.remaining_bits();
        // Common prefix
        let mut builder = Self::make_cell_with_label(prefix, bit_len)?;
        // Remainder of tree
        let existing_cell = Self::make_cell_with_label_and_data(label, length, is_leaf, slice)?;
        // AugResult<Y> for fork
        if !is_leaf {
            if slice.remaining_references() < 2 {
                debug_assert!(false, "fork should have at least two refs");
            }
            slice.shrink_references(2..); // drain left, right
        }
        let mut fork_extra = Y::construct_from(slice)?;
        fork_extra.calc(extra)?;
        // Leaf for fork
        let another_cell = Self::make_cell_with_label_and_builder(key, length, true, &Self::combine(extra, leaf)?)?;
        if !label_bit {
            builder.append_reference_cell(existing_cell.into_cell()?);
            builder.append_reference_cell(another_cell.into_cell()?);
        } else {
            builder.append_reference_cell(another_cell.into_cell()?);
            builder.append_reference_cell(existing_cell.into_cell()?);
        };
        fork_extra.write_to(&mut builder)?;
        *slice = builder.into_cell()?.into();
        Ok(fork_extra)
    }
// Slices the edge and put new leaf
Slices the edge and put new leaf
Slices the edge and put new leaf
fn slice_edge(
        slice: &mut SliceData, // slice without label
        bit_len: usize,
        prefix: SliceData,
        mut label: SliceData,
        mut key: SliceData,
        leaf: &BuilderData,
        extra: &Y
    ) -> Result<Y> {
        key.shrink_data(1..);
        let label_bit = label.get_next_bit()?;
        let length = bit_len - 1 - prefix.remaining_bits();
        let is_leaf = length == label.remaining_bits();
        // Common prefix
        let mut builder = Self::make_cell_with_label(prefix, bit_len)?;
        // Remainder of tree
        let existing_cell = Self::make_cell_with_label_and_data(label, length, is_leaf, slice)?;
        // AugResult<Y> for fork
        if !is_leaf {
            if slice.remaining_references() < 2 {
                debug_assert!(false, "fork should have at least two refs");
            }
            slice.shrink_references(2..); // drain left, right
        }
        let mut fork_extra = Y::construct_from(slice)?;
        fork_extra.calc(extra)?;
        // Leaf for fork
        let another_cell = Self::make_cell_with_label_and_builder(key, length, true, &Self::combine(extra, leaf)?)?;
        if !label_bit {
            builder.append_reference_cell(existing_cell.into_cell()?);
            builder.append_reference_cell(another_cell.into_cell()?);
        } else {
            builder.append_reference_cell(another_cell.into_cell()?);
            builder.append_reference_cell(existing_cell.into_cell()?);
        };
        fork_extra.write_to(&mut builder)?;
        *slice = builder.into_cell()?.into();
        Ok(fork_extra)
    }
fn slice_edge ( slice : & mut SliceData , // slice without label bit_len : usize , prefix : SliceData , mut label : SliceData , mut key : SliceData , leaf : & BuilderData , extra : & Y ) -> Result < Y > { key . shrink_data ( 1 .. ) ; let label_bit = label . get_next_bit ( ) ? ; let length = bit_len - 1 - prefix . remaining_bits ( ) ; let is_leaf = length == label . remaining_bits ( ) ; // Common prefix let mut builder = Self :: make_cell_with_label ( prefix , bit_len ) ? ; // Remainder of tree let existing_cell = Self :: make_cell_with_label_and_data ( label , length , is_leaf , slice ) ? ; // AugResult<Y> for fork if ! is_leaf { if slice . remaining_references ( ) < 2 { debug_assert ! ( false " " ) ; } slice . shrink_references ( 2 .. ) ; // drain left, right } let mut fork_extra = Y :: construct_from ( slice ) ? ; fork_extra . calc ( extra ) ? ; // Leaf for fork let another_cell = Self :: make_cell_with_label_and_builder ( key , length , true , & Self :: combine ( extra , leaf ) ? ) ? ; if ! label_bit { builder . append_reference_cell ( existing_cell . into_cell ( ) ? ) ; builder . append_reference_cell ( another_cell . into_cell ( ) ? ) ; } else { builder . append_reference_cell ( another_cell . into_cell ( ) ? ) ; builder . append_reference_cell ( existing_cell . into_cell ( ) ? ) ; } ; fork_extra . write_to ( & mut builder ) ? ; * slice = builder . into_cell ( ) ? . into ( ) ; Ok ( fork_extra ) }
Slices the edge and put new leaf
Slices the edge and put new leaf
slice
&mut SliceData
bit_len
usize
prefix
SliceData
label
SliceData
key
SliceData
leaf
&BuilderData
extra
&Y
slice
&mut SliceData
bit_len
usize
prefix
SliceData
label
SliceData
key
SliceData
leaf
&BuilderData
extra
&Y