fn compute_ranges<F: PartialEq>(
    rhss: &[Rhs<F>],
    ranges: Vec<Range<F>>,
    nr_rows: usize,
) -> Result<Vec<(usize, F)>, Inconsistency> {
    // If there are no ranges, this is not an issue anyway
    if ranges.is_empty() {
        return Ok(Vec::with_capacity(0))
    }

    // Flatten, we don't care about the different range names
    let mut range_rows = ranges.into_iter()
        .flat_map(|range| range.values.into_iter())
        .collect::<Vec<_>>();
    // We process them by row.
    range_rows.sort_unstable_by_key(|&(i, _)| i);
    let unduplicated_length = range_rows.len();
    range_rows.dedup_by_key(|&mut (i, _)| i);
    if range_rows.len() < unduplicated_length {
        return Err(Inconsistency::new("Only one range per row can be specified."));
    }

    let mut already_seen = vec![false; nr_rows];
    // It's very unlikely that this code path is necessary
    let mut duplicates = Vec::with_capacity(0);
    for rhs in rhss {
        for &(i, _) in &rhs.values {
            if already_seen[i] {
                duplicates.push(i);
            } else {
                already_seen[i] = true;
            }
        }
    }

    // See if any of the duplicate value have a range
    for duplicate in duplicates {
        if range_rows.iter().any(|&(i, _)| i == duplicate) {
            let values = rhss.iter().flat_map(|rhs| rhs.values.iter())
                .filter_map(|(i, v)| if *i == duplicate { Some(v) } else { None })
                .collect::<Vec<_>>();
            if let Some(first) = values.first() {
                if values.iter().any(|v| v != first) {
                    return Err(Inconsistency::new("Multiple rhs values for a constraint with a range"));
                }
            }
        }
    }

    Ok(range_rows)
}
/// Flatten the ranges and ensure consistency related to them.
///
/// Consistency: e.g. there should be at most one range per row, and if there is one, there should
/// be only one right hand side (or they should be equal).
Flatten the ranges and ensure consistency related to them.
Flatten the ranges and ensure consistency related to them .
fn compute_ranges<F: PartialEq>(
    rhss: &[Rhs<F>],
    ranges: Vec<Range<F>>,
    nr_rows: usize,
) -> Result<Vec<(usize, F)>, Inconsistency> {
    // If there are no ranges, this is not an issue anyway
    if ranges.is_empty() {
        return Ok(Vec::with_capacity(0))
    }
    // Flatten, we don't care about the different range names
    let mut range_rows = ranges.into_iter()
        .flat_map(|range| range.values.into_iter())
        .collect::<Vec<_>>();
    // We process them by row.
    range_rows.sort_unstable_by_key(|&(i, _)| i);
    let unduplicated_length = range_rows.len();
    range_rows.dedup_by_key(|&mut (i, _)| i);
    if range_rows.len() < unduplicated_length {
        return Err(Inconsistency::new("Only one range per row can be specified."));
    }
    let mut already_seen = vec![false; nr_rows];
    // It's very unlikely that this code path is necessary
    let mut duplicates = Vec::with_capacity(0);
    for rhs in rhss {
        for &(i, _) in &rhs.values {
            if already_seen[i] {
                duplicates.push(i);
            } else {
                already_seen[i] = true;
            }
        }
    }
    // See if any of the duplicate value have a range
    for duplicate in duplicates {
        if range_rows.iter().any(|&(i, _)| i == duplicate) {
            let values = rhss.iter().flat_map(|rhs| rhs.values.iter())
                .filter_map(|(i, v)| if *i == duplicate { Some(v) } else { None })
                .collect::<Vec<_>>();
            if let Some(first) = values.first() {
                if values.iter().any(|v| v != first) {
                    return Err(Inconsistency::new("Multiple rhs values for a constraint with a range"));
                }
            }
        }
    }
    Ok(range_rows)
}
fn compute_ranges < F : PartialEq > ( rhss : & [ Rhs < F > ] , ranges : Vec < Range < F > > , nr_rows : usize , ) -> Result < Vec < ( usize , F ) > , Inconsistency > { // If there are no ranges, this is not an issue anyway if ranges . is_empty ( ) { return Ok ( Vec :: with_capacity ( 0 ) ) } // Flatten, we don't care about the different range names let mut range_rows = ranges . into_iter ( ) . flat_map ( | range | range . values . into_iter ( ) ) . collect :: < Vec < _ > > ( ) ; // We process them by row. range_rows . sort_unstable_by_key ( | & ( i , _ ) | i ) ; let unduplicated_length = range_rows . len ( ) ; range_rows . dedup_by_key ( | & mut ( i , _ ) | i ) ; if range_rows . len ( ) < unduplicated_length { return Err ( Inconsistency :: new ( " " ) ) ; } let mut already_seen = vec ! [ false nr_rows ] ; // It's very unlikely that this code path is necessary let mut duplicates = Vec :: with_capacity ( 0 ) ; for rhs in rhss { for & ( i , _ ) in & rhs . values { if already_seen [ i ] { duplicates . push ( i ) ; } else { already_seen [ i ] = true ; } } } // See if any of the duplicate value have a range for duplicate in duplicates { if range_rows . iter ( ) . any ( | & ( i , _ ) | i == duplicate ) { let values = rhss . iter ( ) . flat_map ( | rhs | rhs . values . iter ( ) ) . filter_map ( | ( i , v ) | if * i == duplicate { Some ( v ) } else { None } ) . collect :: < Vec < _ > > ( ) ; if let Some ( first ) = values . first ( ) { if values . iter ( ) . any ( | v | v != first ) { return Err ( Inconsistency :: new ( " " ) ) ; } } } } Ok ( range_rows ) }
Flatten the ranges and ensure consistency related to them.
Flatten the ranges and ensure consistency related to them .
rhss
&[Rhs<F>]
ranges
Vec<Range<F>>
nr_rows
usize
rhss
&[Rhs<F>]
ranges
Vec<Range<F>>
nr_rows
usize