fn sorted_novel_positions(
    lhs_mps: &[MatchedPos],
    rhs_mps: &[MatchedPos],
    opposite_to_lhs: &HashMap<LineNumber, HashSet<LineNumber>>,
    opposite_to_rhs: &HashMap<LineNumber, HashSet<LineNumber>>,
) -> Vec<(Side, MatchedPos)> {
    let mut lhs_mps: Vec<MatchedPos> = lhs_mps.to_vec();
    lhs_mps.sort_unstable_by_key(|mp| mp.pos);

    let mut rhs_mps: Vec<MatchedPos> = rhs_mps.to_vec();
    rhs_mps.sort_unstable_by_key(|mp| mp.pos);

    let mut res: Vec<(Side, MatchedPos)> = vec![];

    let mut lhs_prev_matched_line = None;
    let mut rhs_prev_matched_line = None;
    let mut lhs_section = vec![];
    let mut rhs_section = vec![];

    let mut lhs_iter = lhs_mps.iter().peekable();
    let mut rhs_iter = rhs_mps.iter().peekable();
    loop {
        match (lhs_iter.peek(), rhs_iter.peek()) {
            (Some(lhs_mp), Some(rhs_mp)) if !lhs_mp.kind.is_novel() && !rhs_mp.kind.is_novel() => {
                res.append(&mut novel_section_in_order(
                    &lhs_section,
                    &rhs_section,
                    lhs_prev_matched_line,
                    rhs_prev_matched_line,
                    opposite_to_lhs,
                    opposite_to_rhs,
                ));
                lhs_section = vec![];
                rhs_section = vec![];

                lhs_prev_matched_line = Some(lhs_mp.pos.line);
                rhs_prev_matched_line = Some(rhs_mp.pos.line);
                lhs_iter.next();
                rhs_iter.next();
            }
            (Some(lhs_mp), _) if lhs_mp.kind.is_novel() => {
                lhs_section.push(lhs_mp);
                lhs_iter.next();
            }
            (_, Some(rhs_mp)) if rhs_mp.kind.is_novel() => {
                rhs_section.push(rhs_mp);
                rhs_iter.next();
            }
            (None, None) => {
                break;
            }
            _ => {
                unreachable!("Should be impossible: every LHS Unchanged MatchedPos should have a corresponding RHS Unchanged MatchedPos");
            }
        }
    }

    res.append(&mut novel_section_in_order(
        &lhs_section,
        &rhs_section,
        lhs_prev_matched_line,
        rhs_prev_matched_line,
        opposite_to_lhs,
        opposite_to_rhs,
    ));

    res
}
/// Return a vec of novel MatchedPos values in an order suited for
/// displaying.
///
/// Since novel positions don't have a corresponding opposite
/// position, use the last opposite matched position to decide
/// ordering.
Return a vec of novel MatchedPos values in an order suited for
displaying.

Since novel positions don't have a corresponding opposite
position, use the last opposite matched position to decide
ordering.
Return a vec of novel MatchedPos values in an order suited for displaying . Since novel positions don ' t have a corresponding opposite position use the last opposite matched position to decide ordering .
fn sorted_novel_positions(
    lhs_mps: &[MatchedPos],
    rhs_mps: &[MatchedPos],
    opposite_to_lhs: &HashMap<LineNumber, HashSet<LineNumber>>,
    opposite_to_rhs: &HashMap<LineNumber, HashSet<LineNumber>>,
) -> Vec<(Side, MatchedPos)> {
    let mut lhs_mps: Vec<MatchedPos> = lhs_mps.to_vec();
    lhs_mps.sort_unstable_by_key(|mp| mp.pos);
    let mut rhs_mps: Vec<MatchedPos> = rhs_mps.to_vec();
    rhs_mps.sort_unstable_by_key(|mp| mp.pos);
    let mut res: Vec<(Side, MatchedPos)> = vec![];
    let mut lhs_prev_matched_line = None;
    let mut rhs_prev_matched_line = None;
    let mut lhs_section = vec![];
    let mut rhs_section = vec![];
    let mut lhs_iter = lhs_mps.iter().peekable();
    let mut rhs_iter = rhs_mps.iter().peekable();
    loop {
        match (lhs_iter.peek(), rhs_iter.peek()) {
            (Some(lhs_mp), Some(rhs_mp)) if !lhs_mp.kind.is_novel() && !rhs_mp.kind.is_novel() => {
                res.append(&mut novel_section_in_order(
                    &lhs_section,
                    &rhs_section,
                    lhs_prev_matched_line,
                    rhs_prev_matched_line,
                    opposite_to_lhs,
                    opposite_to_rhs,
                ));
                lhs_section = vec![];
                rhs_section = vec![];
                lhs_prev_matched_line = Some(lhs_mp.pos.line);
                rhs_prev_matched_line = Some(rhs_mp.pos.line);
                lhs_iter.next();
                rhs_iter.next();
            }
            (Some(lhs_mp), _) if lhs_mp.kind.is_novel() => {
                lhs_section.push(lhs_mp);
                lhs_iter.next();
            }
            (_, Some(rhs_mp)) if rhs_mp.kind.is_novel() => {
                rhs_section.push(rhs_mp);
                rhs_iter.next();
            }
            (None, None) => {
                break;
            }
            _ => {
                unreachable!("Should be impossible: every LHS Unchanged MatchedPos should have a corresponding RHS Unchanged MatchedPos");
            }
        }
    }
    res.append(&mut novel_section_in_order(
        &lhs_section,
        &rhs_section,
        lhs_prev_matched_line,
        rhs_prev_matched_line,
        opposite_to_lhs,
        opposite_to_rhs,
    ));
    res
}
fn sorted_novel_positions ( lhs_mps : & [ MatchedPos ] , rhs_mps : & [ MatchedPos ] , opposite_to_lhs : & HashMap < LineNumber , HashSet < LineNumber > > , opposite_to_rhs : & HashMap < LineNumber , HashSet < LineNumber > > , ) -> Vec < ( Side , MatchedPos ) > { let mut lhs_mps : Vec < MatchedPos > = lhs_mps . to_vec ( ) ; lhs_mps . sort_unstable_by_key ( | mp | mp . pos ) ; let mut rhs_mps : Vec < MatchedPos > = rhs_mps . to_vec ( ) ; rhs_mps . sort_unstable_by_key ( | mp | mp . pos ) ; let mut res : Vec < ( Side , MatchedPos ) > = vec ! [ ] ; let mut lhs_prev_matched_line = None ; let mut rhs_prev_matched_line = None ; let mut lhs_section = vec ! [ ] ; let mut rhs_section = vec ! [ ] ; let mut lhs_iter = lhs_mps . iter ( ) . peekable ( ) ; let mut rhs_iter = rhs_mps . iter ( ) . peekable ( ) ; loop { match ( lhs_iter . peek ( ) , rhs_iter . peek ( ) ) { ( Some ( lhs_mp ) , Some ( rhs_mp ) ) if ! lhs_mp . kind . is_novel ( ) && ! rhs_mp . kind . is_novel ( ) => { res . append ( & mut novel_section_in_order ( & lhs_section , & rhs_section , lhs_prev_matched_line , rhs_prev_matched_line , opposite_to_lhs , opposite_to_rhs , ) ) ; lhs_section = vec ! [ ] ; rhs_section = vec ! [ ] ; lhs_prev_matched_line = Some ( lhs_mp . pos . line ) ; rhs_prev_matched_line = Some ( rhs_mp . pos . line ) ; lhs_iter . next ( ) ; rhs_iter . next ( ) ; } ( Some ( lhs_mp ) , _ ) if lhs_mp . kind . is_novel ( ) => { lhs_section . push ( lhs_mp ) ; lhs_iter . next ( ) ; } ( _ , Some ( rhs_mp ) ) if rhs_mp . kind . is_novel ( ) => { rhs_section . push ( rhs_mp ) ; rhs_iter . next ( ) ; } ( None , None ) => { break ; } _ => { unreachable ! ( " " ) ; } } } res . append ( & mut novel_section_in_order ( & lhs_section , & rhs_section , lhs_prev_matched_line , rhs_prev_matched_line , opposite_to_lhs , opposite_to_rhs , ) ) ; res }
Return a vec of novel MatchedPos values in an order suited for
displaying.
Return a vec of novel MatchedPos values in an order suited for displaying .
lhs_mps
&[MatchedPos]
rhs_mps
&[MatchedPos]
opposite_to_lhs
&HashMap<LineNumber, HashSet<LineNumber>>
opposite_to_rhs
&HashMap<LineNumber, HashSet<LineNumber>>