Remove unnecessary usage of HashMap.contains_key
This commit is contained in:
parent
9a4af322ca
commit
61b22b388d
|
@ -69,14 +69,15 @@ impl<'t, N: Number> BallotTree<'t, N> {
|
|||
|
||||
let candidate = &candidates[*preference.first().unwrap()];
|
||||
|
||||
if next_preferences.contains_key(candidate) {
|
||||
let np_bt = next_preferences.get_mut(candidate).unwrap();
|
||||
match next_preferences.get_mut(candidate) {
|
||||
Some(np_bt) => {
|
||||
np_bt.num_ballots += &bit.ballot.orig_value;
|
||||
np_bt.ballots.push(BallotInTree {
|
||||
ballot: bit.ballot,
|
||||
up_to_pref: bit.up_to_pref + 1,
|
||||
});
|
||||
} else {
|
||||
}
|
||||
None => {
|
||||
let mut np_bt = BallotTree::new();
|
||||
np_bt.num_ballots += &bit.ballot.orig_value;
|
||||
np_bt.ballots.push(BallotInTree {
|
||||
|
@ -85,6 +86,7 @@ impl<'t, N: Number> BallotTree<'t, N> {
|
|||
});
|
||||
next_preferences.insert(candidate, np_bt);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Exhausted
|
||||
next_exhausted.num_ballots += &bit.ballot.orig_value;
|
||||
|
|
|
@ -823,17 +823,19 @@ pub fn next_preferences<'a, N: Number>(state: &CountState<'a, N>, votes: Vec<Vot
|
|||
|
||||
// Have to structure like this to satisfy Rust's borrow checker
|
||||
if let Some(candidate) = next_candidate {
|
||||
if result.candidates.contains_key(candidate) {
|
||||
let entry = result.candidates.get_mut(candidate).unwrap();
|
||||
match result.candidates.get_mut(candidate) {
|
||||
Some(entry) => {
|
||||
entry.num_ballots += &vote.ballot.orig_value;
|
||||
entry.votes.push(vote);
|
||||
} else {
|
||||
}
|
||||
None => {
|
||||
let entry = NextPreferencesEntry {
|
||||
num_ballots: vote.ballot.orig_value.clone(),
|
||||
votes: vec![vote],
|
||||
};
|
||||
result.candidates.insert(candidate, entry);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.exhausted.num_ballots += &vote.ballot.orig_value;
|
||||
result.exhausted.votes.push(vote);
|
||||
|
|
Loading…
Reference in New Issue