fn look_for_continuous_streams<T:Copy,F : Fn(usize)->T>(markings:&[RawBallotMarking],result_generator:F,consider_cross_as_one:bool) -> Vec<T> {
        let mut times_seen = vec![0 as usize;markings.len()];
        let mut prefs = vec![result_generator(0);markings.len()];
        for i in 0..markings.len() {
            match markings[i] {
                RawBallotMarking::Number(n) if n>0 && n as usize<= markings.len() => {
                    prefs[n as usize-1]=result_generator(i);
                    times_seen[n as usize-1]+=1;
                }
                RawBallotMarking::OneEquivalent if consider_cross_as_one => {
                    prefs[1-1]=result_generator(i);
                    times_seen[1-1]+=1;
                }
                _ => {}
            }
        }
        let mut num_good = 0;
        while num_good<times_seen.len() && times_seen[num_good]==1 { num_good+=1; }
        prefs.truncate(num_good);
        prefs
    }
/// Interpret a list of markings as preferences.
/// * Ignore all repeated numbers. E.g. 1 2 2 ignore the 2s.
/// * Ignore all numbers after a gap. E.g. 1 3 4 ignore the 3 and 4
/// * Treat a cross as a 1 iff consider_cross_as_one true
/// Otherwise take the longest list of preferences starting at 1.
/// The return type is given by a (provided) function
Interpret a list of markings as preferences.
Ignore all repeated numbers.
Interpret a list of markings as preferences . Ignore all repeated numbers .
fn look_for_continuous_streams<T:Copy,F : Fn(usize)->T>(markings:&[RawBallotMarking],result_generator:F,consider_cross_as_one:bool) -> Vec<T> {
        let mut times_seen = vec![0 as usize;markings.len()];
        let mut prefs = vec![result_generator(0);markings.len()];
        for i in 0..markings.len() {
            match markings[i] {
                RawBallotMarking::Number(n) if n>0 && n as usize<= markings.len() => {
                    prefs[n as usize-1]=result_generator(i);
                    times_seen[n as usize-1]+=1;
                }
                RawBallotMarking::OneEquivalent if consider_cross_as_one => {
                    prefs[1-1]=result_generator(i);
                    times_seen[1-1]+=1;
                }
                _ => {}
            }
        }
        let mut num_good = 0;
        while num_good<times_seen.len() && times_seen[num_good]==1 { num_good+=1; }
        prefs.truncate(num_good);
        prefs
    }
fn look_for_continuous_streams < T : Copy , F : Fn ( usize ) -> T > ( markings : & [ RawBallotMarking ] , result_generator : F , consider_cross_as_one : bool ) -> Vec < T > { let mut times_seen = vec ! [ 0 as usize markings len ( ) ] ; let mut prefs = vec ! [ result_generator ( 0 ) markings len ( ) ] ; for i in 0 .. markings . len ( ) { match markings [ i ] { RawBallotMarking :: Number ( n ) if n > 0 && n as usize <= markings . len ( ) => { prefs [ n as usize - 1 ] = result_generator ( i ) ; times_seen [ n as usize - 1 ] += 1 ; } RawBallotMarking :: OneEquivalent if consider_cross_as_one => { prefs [ 1 - 1 ] = result_generator ( i ) ; times_seen [ 1 - 1 ] += 1 ; } _ => { } } } let mut num_good = 0 ; while num_good < times_seen . len ( ) && times_seen [ num_good ] == 1 { num_good += 1 ; } prefs . truncate ( num_good ) ; prefs }
Interpret a list of markings as preferences.
Interpret a list of markings as preferences .
markings
&[RawBallotMarking]
result_generator
F
consider_cross_as_one
bool
markings
&[RawBallotMarking]
result_generator
F
consider_cross_as_one
bool