From d697871414c3a22a3bacc747ac6aed486328ab57 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 27 Jun 2021 23:20:35 +1000 Subject: [PATCH] Also bulk elect based on guarded candidates --- src/stv/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/stv/mod.rs b/src/stv/mod.rs index 1971f6b..a6cd1e2 100644 --- a/src/stv/mod.rs +++ b/src/stv/mod.rs @@ -929,18 +929,18 @@ where /// Declare all continuing candidates elected, if the number equals the number of remaining vacancies fn bulk_elect(state: &mut CountState, opts: &STVOptions) -> Result { - if state.election.candidates.len() - state.num_excluded <= state.election.seats { + let mut hopefuls: Vec<&Candidate> = state.election.candidates.iter() + .filter(|c| { + let cc = state.candidates.get(c).unwrap(); + return cc.state == CandidateState::Hopeful || cc.state == CandidateState::Guarded; + }) + .collect(); + + if state.num_elected + hopefuls.len() <= state.election.seats { state.kind = None; state.title = "Bulk election".to_string(); // Bulk elect all remaining candidates - let mut hopefuls: Vec<&Candidate> = state.election.candidates.iter() - .filter(|c| { - let cc = state.candidates.get(c).unwrap(); - return cc.state == CandidateState::Hopeful || cc.state == CandidateState::Guarded; - }) - .collect(); - while !hopefuls.is_empty() { let max_votes = hopefuls.iter() .max_by(|a, b| state.candidates.get(**a).unwrap().votes.cmp(&state.candidates.get(**b).unwrap().votes))