|
|
|
@ -100,7 +100,7 @@ impl<N: Number> Election<N> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// A candidate in an [Election]
|
|
|
|
|
#[derive(Clone, Eq, PartialEq)] |
|
|
|
|
#[derive(Clone, Eq)] |
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), derive(Archive, Deserialize, Serialize))] |
|
|
|
|
pub struct Candidate { |
|
|
|
|
/// Index of the candidate
|
|
|
|
@ -111,13 +111,21 @@ pub struct Candidate { |
|
|
|
|
pub is_dummy: bool, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl PartialEq for Candidate { |
|
|
|
|
// Custom implementation of eq for HashMap purposes, to improve performance
|
|
|
|
|
//
|
|
|
|
|
// SAFETY: Results in undefined behaviour if multiple Candidates are allowed to have the same index
|
|
|
|
|
fn eq(&self, other: &Candidate) -> bool { |
|
|
|
|
return self.index == other.index; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Hash for Candidate { |
|
|
|
|
fn hash<H: Hasher>(&self, hasher: &mut H) { |
|
|
|
|
// Custom implementation of hash for use with NoHashHasher, to improve performance
|
|
|
|
|
hasher.write_usize(self.index); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl nohash_hasher::IsEnabled for Candidate {} |
|
|
|
|
|
|
|
|
|
/// The current state of counting an [Election]
|
|
|
|
|