fn resolve_ties_any_different<Tally:Clone+Eq+Hash+Ord+Display+FromStr>(tied_candidates: &mut [CandidateIndex],transcript:  &Transcript<Tally>,granularity:TieResolutionGranularityNeeded,just_consider_major_counts:bool) -> bool {
    //println!("Resolve ties any different between {}",tied_candidates.iter().map(|c|c.to_string()).collect::<Vec<_>>().join(","));
    for count in transcript.counts.iter().rev() {if count.reason_completed || !just_consider_major_counts {
        let mut observed : HashMap<Tally,Vec<CandidateIndex>> = HashMap::new();
        for candidate in tied_candidates.iter() {
            observed.entry(count.status.tallies.candidate[candidate.0].clone()).or_insert_with(||vec![]).push(*candidate);
        }
        if observed.len()>1 { // at least 1 different.
            //println!("Broken into {} groups",observed.len());
            let mut tallies : Vec<Tally> = observed.keys().cloned().collect();
            tallies.sort();
            let mut ok = true;
            let mut upto : usize = 0;
            for tally in tallies {
                let who = observed.get_mut(&tally).unwrap();
                if who.len()>1 {
                    match granularity {
                        TieResolutionGranularityNeeded::Total => {ok=ok&&resolve_ties_any_different(who,transcript,granularity,just_consider_major_counts)}  // could optimize to start at count currently up to.
                        TieResolutionGranularityNeeded::LowestSeparated(loc) if loc>upto && loc<upto+who.len() => {ok=ok&&resolve_ties_any_different(who,transcript,TieResolutionGranularityNeeded::LowestSeparated(loc-upto),just_consider_major_counts)}
                        TieResolutionGranularityNeeded::LowestSeparated(_) => {} // granularity means we don't care.
                    }
                }
                tied_candidates[upto..upto+who.len()].copy_from_slice(who);
                upto+=who.len();
            }
            //println!("Solution is : {}",tied_candidates.iter().map(|c|c.to_string()).collect::<Vec<_>>().join(","));
            return ok;
        }
    }}
    false
}
/// Sort candidates low to high based on the tie resolution rules.
/// Return true iff ties are resolved to the required granularity.
Sort candidates low to high based on the tie resolution rules.
Return true iff ties are resolved to the required granularity.
Sort candidates low to high based on the tie resolution rules . Return true iff ties are resolved to the required granularity .
fn resolve_ties_any_different<Tally:Clone+Eq+Hash+Ord+Display+FromStr>(tied_candidates: &mut [CandidateIndex],transcript:  &Transcript<Tally>,granularity:TieResolutionGranularityNeeded,just_consider_major_counts:bool) -> bool {
    //println!("Resolve ties any different between {}",tied_candidates.iter().map(|c|c.to_string()).collect::<Vec<_>>().join(","));
    for count in transcript.counts.iter().rev() {if count.reason_completed || !just_consider_major_counts {
        let mut observed : HashMap<Tally,Vec<CandidateIndex>> = HashMap::new();
        for candidate in tied_candidates.iter() {
            observed.entry(count.status.tallies.candidate[candidate.0].clone()).or_insert_with(||vec![]).push(*candidate);
        }
        if observed.len()>1 { // at least 1 different.
            //println!("Broken into {} groups",observed.len());
            let mut tallies : Vec<Tally> = observed.keys().cloned().collect();
            tallies.sort();
            let mut ok = true;
            let mut upto : usize = 0;
            for tally in tallies {
                let who = observed.get_mut(&tally).unwrap();
                if who.len()>1 {
                    match granularity {
                        TieResolutionGranularityNeeded::Total => {ok=ok&&resolve_ties_any_different(who,transcript,granularity,just_consider_major_counts)}  // could optimize to start at count currently up to.
                        TieResolutionGranularityNeeded::LowestSeparated(loc) if loc>upto && loc<upto+who.len() => {ok=ok&&resolve_ties_any_different(who,transcript,TieResolutionGranularityNeeded::LowestSeparated(loc-upto),just_consider_major_counts)}
                        TieResolutionGranularityNeeded::LowestSeparated(_) => {} // granularity means we don't care.
                    }
                }
                tied_candidates[upto..upto+who.len()].copy_from_slice(who);
                upto+=who.len();
            }
            //println!("Solution is : {}",tied_candidates.iter().map(|c|c.to_string()).collect::<Vec<_>>().join(","));
            return ok;
        }
    }}
    false
}
fn resolve_ties_any_different < Tally : Clone + Eq + Hash + Ord + Display + FromStr > ( tied_candidates : & mut [ CandidateIndex ] , transcript : & Transcript < Tally > , granularity : TieResolutionGranularityNeeded , just_consider_major_counts : bool ) -> bool { //println!("Resolve ties any different between {}",tied_candidates.iter().map(|c|c.to_string()).collect::<Vec<_>>().join(",")); for count in transcript . counts . iter ( ) . rev ( ) { if count . reason_completed || ! just_consider_major_counts { let mut observed : HashMap < Tally , Vec < CandidateIndex > > = HashMap :: new ( ) ; for candidate in tied_candidates . iter ( ) { observed . entry ( count . status . tallies . candidate [ candidate . 0 ] . clone ( ) ) . or_insert_with ( | | vec ! [ ] ) . push ( * candidate ) ; } if observed . len ( ) > 1 { // at least 1 different. //println!("Broken into {} groups",observed.len()); let mut tallies : Vec < Tally > = observed . keys ( ) . cloned ( ) . collect ( ) ; tallies . sort ( ) ; let mut ok = true ; let mut upto : usize = 0 ; for tally in tallies { let who = observed . get_mut ( & tally ) . unwrap ( ) ; if who . len ( ) > 1 { match granularity { TieResolutionGranularityNeeded :: Total => { ok = ok && resolve_ties_any_different ( who , transcript , granularity , just_consider_major_counts ) } // could optimize to start at count currently up to. TieResolutionGranularityNeeded :: LowestSeparated ( loc ) if loc > upto && loc < upto + who . len ( ) => { ok = ok && resolve_ties_any_different ( who , transcript , TieResolutionGranularityNeeded :: LowestSeparated ( loc - upto ) , just_consider_major_counts ) } TieResolutionGranularityNeeded :: LowestSeparated ( _ ) => { } // granularity means we don't care. } } tied_candidates [ upto .. upto + who . len ( ) ] . copy_from_slice ( who ) ; upto += who . len ( ) ; } //println!("Solution is : {}",tied_candidates.iter().map(|c|c.to_string()).collect::<Vec<_>>().join(",")); return ok ; } } } false }
Sort candidates low to high based on the tie resolution rules.
Sort candidates low to high based on the tie resolution rules .
tied_candidates
&mut [CandidateIndex]
transcript
&Transcript<Tally>
granularity
TieResolutionGranularityNeeded
just_consider_major_counts
bool
tied_candidates
&mut [CandidateIndex]
transcript
&Transcript<Tally>
granularity
TieResolutionGranularityNeeded
just_consider_major_counts
bool