fn diff_slice_by_hash<'a, T: Eq + Hash>(
    lhs: &'a [T],
    rhs: &'a [T],
) -> Vec<myers_diff::DiffResult<&'a T>> {
    let mut value_ids: FxHashMap<&T, u32> = FxHashMap::default();
    let mut id_values: FxHashMap<u32, &T> = FxHashMap::default();

    let mut lhs_ids = Vec::with_capacity(lhs.len());
    for value in lhs {
        let id: u32 = match value_ids.get(value) {
            Some(id) => *id,
            None => {
                let new_id = value_ids.len() as u32;
                value_ids.insert(value, new_id);
                id_values.insert(new_id, value);
                new_id
            }
        };
        lhs_ids.push(id);
    }

    let mut rhs_ids = Vec::with_capacity(rhs.len());
    for value in rhs {
        let id = match value_ids.get(value) {
            Some(id) => *id,
            None => {
                let new_id = value_ids.len() as u32;
                value_ids.insert(value, new_id);
                id_values.insert(new_id, value);
                new_id
            }
        };
        rhs_ids.push(id);
    }

    myers_diff::slice(&lhs_ids[..], &rhs_ids[..])
        .into_iter()
        .map(|result| match result {
            myers_diff::DiffResult::Left(id) => {
                myers_diff::DiffResult::Left(*id_values.get(id).unwrap())
            }
            myers_diff::DiffResult::Both(lhs_id, rhs_id) => myers_diff::DiffResult::Both(
                *id_values.get(lhs_id).unwrap(),
                *id_values.get(rhs_id).unwrap(),
            ),
            myers_diff::DiffResult::Right(id) => {
                myers_diff::DiffResult::Right(*id_values.get(id).unwrap())
            }
        })
        .collect::<Vec<_>>()
}
/// Compute a unique numeric value for each item, use that for
/// diffing, then return diff results in terms of the original type.
///
/// This is the decorate-sort-undecorate pattern, or Schwartzian
/// transform, for diffing.
Compute a unique numeric value for each item, use that for
diffing, then return diff results in terms of the original type.

This is the decorate-sort-undecorate pattern, or Schwartzian
transform, for diffing.
Compute a unique numeric value for each item use that for diffing then return diff results in terms of the original type . This is the decorate - sort - undecorate pattern or Schwartzian transform for diffing .
fn diff_slice_by_hash<'a, T: Eq + Hash>(
    lhs: &'a [T],
    rhs: &'a [T],
) -> Vec<myers_diff::DiffResult<&'a T>> {
    let mut value_ids: FxHashMap<&T, u32> = FxHashMap::default();
    let mut id_values: FxHashMap<u32, &T> = FxHashMap::default();
    let mut lhs_ids = Vec::with_capacity(lhs.len());
    for value in lhs {
        let id: u32 = match value_ids.get(value) {
            Some(id) => *id,
            None => {
                let new_id = value_ids.len() as u32;
                value_ids.insert(value, new_id);
                id_values.insert(new_id, value);
                new_id
            }
        };
        lhs_ids.push(id);
    }
    let mut rhs_ids = Vec::with_capacity(rhs.len());
    for value in rhs {
        let id = match value_ids.get(value) {
            Some(id) => *id,
            None => {
                let new_id = value_ids.len() as u32;
                value_ids.insert(value, new_id);
                id_values.insert(new_id, value);
                new_id
            }
        };
        rhs_ids.push(id);
    }
    myers_diff::slice(&lhs_ids[..], &rhs_ids[..])
        .into_iter()
        .map(|result| match result {
            myers_diff::DiffResult::Left(id) => {
                myers_diff::DiffResult::Left(*id_values.get(id).unwrap())
            }
            myers_diff::DiffResult::Both(lhs_id, rhs_id) => myers_diff::DiffResult::Both(
                *id_values.get(lhs_id).unwrap(),
                *id_values.get(rhs_id).unwrap(),
            ),
            myers_diff::DiffResult::Right(id) => {
                myers_diff::DiffResult::Right(*id_values.get(id).unwrap())
            }
        })
        .collect::<Vec<_>>()
}
fn diff_slice_by_hash < ' a , T : Eq + Hash > ( lhs : & ' a [ T ] , rhs : & ' a [ T ] , ) -> Vec < myers_diff :: DiffResult < & ' a T > > { let mut value_ids : FxHashMap < & T , u32 > = FxHashMap :: default ( ) ; let mut id_values : FxHashMap < u32 , & T > = FxHashMap :: default ( ) ; let mut lhs_ids = Vec :: with_capacity ( lhs . len ( ) ) ; for value in lhs { let id : u32 = match value_ids . get ( value ) { Some ( id ) => * id , None => { let new_id = value_ids . len ( ) as u32 ; value_ids . insert ( value , new_id ) ; id_values . insert ( new_id , value ) ; new_id } } ; lhs_ids . push ( id ) ; } let mut rhs_ids = Vec :: with_capacity ( rhs . len ( ) ) ; for value in rhs { let id = match value_ids . get ( value ) { Some ( id ) => * id , None => { let new_id = value_ids . len ( ) as u32 ; value_ids . insert ( value , new_id ) ; id_values . insert ( new_id , value ) ; new_id } } ; rhs_ids . push ( id ) ; } myers_diff :: slice ( & lhs_ids [ .. ] , & rhs_ids [ .. ] ) . into_iter ( ) . map ( | result | match result { myers_diff :: DiffResult :: Left ( id ) => { myers_diff :: DiffResult :: Left ( * id_values . get ( id ) . unwrap ( ) ) } myers_diff :: DiffResult :: Both ( lhs_id , rhs_id ) => myers_diff :: DiffResult :: Both ( * id_values . get ( lhs_id ) . unwrap ( ) , * id_values . get ( rhs_id ) . unwrap ( ) , ) , myers_diff :: DiffResult :: Right ( id ) => { myers_diff :: DiffResult :: Right ( * id_values . get ( id ) . unwrap ( ) ) } } ) . collect :: < Vec < _ > > ( ) }
Compute a unique numeric value for each item, use that for
diffing, then return diff results in terms of the original type.
Compute a unique numeric value for each item use that for diffing then return diff results in terms of the original type .
lhs
&'a [T]
rhs
&'a [T]