/// Iterative move towards the median.
/// Returns ( positive imbalance, number of items equal to x,
/// increment of x position towards the median )
Iterative move towards the median.
Returns ( positive imbalance, number of items equal to x,
increment of x position towards the median )
Iterative move towards the median . Returns ( positive imbalance number of items equal to x increment of x position towards the median )
fn next(s:&[f64],x:f64) -> (i64,i64,f64) {
    let mut recipsum = 0_f64;
    let (mut left,mut right) = (0_i64,0_i64); 
    for &si in s {
        if si < x { left += 1; recipsum += 1./(x-si); continue; };
        if si > x { right += 1; recipsum += 1./(si-x); 
        }
    }
    let balance = right-left;
    ( balance.abs(),s.len() as i64-left-right,(balance as f64)/recipsum )
}
fn next ( s : & [ f64 ] , x : f64 ) -> ( i64 , i64 , f64 ) { let mut recipsum = 0_f64 ; let ( mut left , mut right ) = ( 0_i64 , 0_i64 ) ; for & si in s { if si < x { left += 1 ; recipsum += 1. / ( x - si ) ; continue ; } ; if si > x { right += 1 ; recipsum += 1. / ( si - x ) ; } } let balance = right - left ; ( balance . abs ( ) , s . len ( ) as i64 - left - right , ( balance as f64 ) / recipsum ) }
Iterative move towards the median.
Iterative move towards the median .
s
&[f64]
x
f64