fn calculate_statistic_inner_presorted<T: std::cmp::PartialEq + Ord>(xs: &[T], ys: &[T]) -> f64 {
    // The current value testing for ECDF difference. Sweeps up through elements
    // present in xs and ys.
    let mut current: &T;

    // i, j index the first values in xs and ys that are greater than current.
    let mut i = 0;
    let mut j = 0;

    // ecdf_xs, ecdf_ys always hold the ECDF(current) of xs and ys.
    let mut ecdf_xs = 0.0;
    let mut ecdf_ys = 0.0;

    // The test statistic value computed over values <= current.
    let mut statistic = 0.0;

    let n = xs.len();
    let m = ys.len();
    while i < n && j < m {
        // Advance i through duplicate samples in xs.
        let x_i = &xs[i];
        while i + 1 < n && *x_i == xs[i + 1] {
            i += 1;
        }

        // Advance j through duplicate samples in ys.
        let y_j = &ys[j];
        while j + 1 < m && *y_j == ys[j + 1] {
            j += 1;
        }

        // Step to the next sample value in the ECDF sweep from low to high.
        current = min(x_i, y_j);

        // Update invariant conditions for i, j, ecdf_xs, and ecdf_ys.
        if current == x_i {
            ecdf_xs = (i + 1) as f64 / n as f64;
            i += 1;
        }
        if current == y_j {
            ecdf_ys = (j + 1) as f64 / m as f64;
            j += 1;
        }

        // Update invariant conditions for the test statistic.
        let diff = (ecdf_xs - ecdf_ys).abs();
        if diff > statistic {
            statistic = diff;
        }
    }

    // Don't need to walk the rest of the samples because one of the ecdfs is
    // already one and the other will be increasing up to one. This means the
    // difference will be monotonically decreasing, so we have our test
    // statistic value already.

    statistic
}
/// Internal use only, because it strongly assumes that the input samples
/// are pre-sorted and of an acceptable length (e.g. > 7)
///
/// Calculate the test statistic for the two sample Kolmogorov-Smirnov test.
///
/// The test statistic is the maximum vertical distance between the ECDFs of
/// the two samples.
Internal use only, because it strongly assumes that the input samples
are pre-sorted and of an acceptable length

Calculate the test statistic for the two sample Kolmogorov-Smirnov test.

The test statistic is the maximum vertical distance between the ECDFs of
the two samples.
Internal use only because it strongly assumes that the input samples are pre - sorted and of an acceptable length Calculate the test statistic for the two sample Kolmogorov - Smirnov test . The test statistic is the maximum vertical distance between the ECDFs of the two samples .
fn calculate_statistic_inner_presorted<T: std::cmp::PartialEq + Ord>(xs: &[T], ys: &[T]) -> f64 {
    // The current value testing for ECDF difference. Sweeps up through elements
    // present in xs and ys.
    let mut current: &T;
    // i, j index the first values in xs and ys that are greater than current.
    let mut i = 0;
    let mut j = 0;
    // ecdf_xs, ecdf_ys always hold the ECDF(current) of xs and ys.
    let mut ecdf_xs = 0.0;
    let mut ecdf_ys = 0.0;
    // The test statistic value computed over values <= current.
    let mut statistic = 0.0;
    let n = xs.len();
    let m = ys.len();
    while i < n && j < m {
        // Advance i through duplicate samples in xs.
        let x_i = &xs[i];
        while i + 1 < n && *x_i == xs[i + 1] {
            i += 1;
        }
        // Advance j through duplicate samples in ys.
        let y_j = &ys[j];
        while j + 1 < m && *y_j == ys[j + 1] {
            j += 1;
        }
        // Step to the next sample value in the ECDF sweep from low to high.
        current = min(x_i, y_j);
        // Update invariant conditions for i, j, ecdf_xs, and ecdf_ys.
        if current == x_i {
            ecdf_xs = (i + 1) as f64 / n as f64;
            i += 1;
        }
        if current == y_j {
            ecdf_ys = (j + 1) as f64 / m as f64;
            j += 1;
        }
        // Update invariant conditions for the test statistic.
        let diff = (ecdf_xs - ecdf_ys).abs();
        if diff > statistic {
            statistic = diff;
        }
    }
    // Don't need to walk the rest of the samples because one of the ecdfs is
    // already one and the other will be increasing up to one. This means the
    // difference will be monotonically decreasing, so we have our test
    // statistic value already.
    statistic
}
fn calculate_statistic_inner_presorted < T : std :: cmp :: PartialEq + Ord > ( xs : & [ T ] , ys : & [ T ] ) -> f64 { // The current value testing for ECDF difference. Sweeps up through elements // present in xs and ys. let mut current : & T ; // i, j index the first values in xs and ys that are greater than current. let mut i = 0 ; let mut j = 0 ; // ecdf_xs, ecdf_ys always hold the ECDF(current) of xs and ys. let mut ecdf_xs = 0.0 ; let mut ecdf_ys = 0.0 ; // The test statistic value computed over values <= current. let mut statistic = 0.0 ; let n = xs . len ( ) ; let m = ys . len ( ) ; while i < n && j < m { // Advance i through duplicate samples in xs. let x_i = & xs [ i ] ; while i + 1 < n && * x_i == xs [ i + 1 ] { i += 1 ; } // Advance j through duplicate samples in ys. let y_j = & ys [ j ] ; while j + 1 < m && * y_j == ys [ j + 1 ] { j += 1 ; } // Step to the next sample value in the ECDF sweep from low to high. current = min ( x_i , y_j ) ; // Update invariant conditions for i, j, ecdf_xs, and ecdf_ys. if current == x_i { ecdf_xs = ( i + 1 ) as f64 / n as f64 ; i += 1 ; } if current == y_j { ecdf_ys = ( j + 1 ) as f64 / m as f64 ; j += 1 ; } // Update invariant conditions for the test statistic. let diff = ( ecdf_xs - ecdf_ys ) . abs ( ) ; if diff > statistic { statistic = diff ; } } // Don't need to walk the rest of the samples because one of the ecdfs is // already one and the other will be increasing up to one. This means the // difference will be monotonically decreasing, so we have our test // statistic value already. statistic }
Internal use only, because it strongly assumes that the input samples
are pre-sorted and of an acceptable length (e.g.
Internal use only because it strongly assumes that the input samples are pre - sorted and of an acceptable length ( e . g .
xs
&[T]
ys
&[T]
xs
&[T]
ys
&[T]