pub struct VoteCount<I, R> {
pub sum: Vec<R>,
pub exhausted: R,
_phantom: PhantomData<I>,
}Expand description
Result of a vote count.
Fields§
§sum: Vec<R>Sum of votes for each candidate.
exhausted: RExhausted voting power.
_phantom: PhantomData<I>Implementations§
Source§impl<I, R> VoteCount<I, R>
impl<I, R> VoteCount<I, R>
Sourcepub fn count_votes(
election: &Election,
keep_factors: &[R],
parallel: Parallel,
thread_pool: Option<&VoteCountingThreadPool<'_, I, R>>,
pascal: Option<&[Vec<I>]>,
) -> Self
pub fn count_votes( election: &Election, keep_factors: &[R], parallel: Parallel, thread_pool: Option<&VoteCountingThreadPool<'_, I, R>>, pascal: Option<&[Vec<I>]>, ) -> Self
Counts the votes, based on the given keep factors.
Sourcefn accumulate_votes_rayon(
election: &Election,
keep_factors: &[R],
pascal: Option<&[Vec<I>]>,
) -> VoteAccumulator<I, R>
fn accumulate_votes_rayon( election: &Election, keep_factors: &[R], pascal: Option<&[Vec<I>]>, ) -> VoteAccumulator<I, R>
Parallel implementation of vote counting, leveraging all CPU cores to speed up the computation.
Source§impl<I, R> VoteCount<I, R>where
I: Integer,
for<'a> &'a I: IntegerRef<I>,
R: Rational<I>,
for<'a> &'a R: RationalRef<&'a I, R>,
impl<I, R> VoteCount<I, R>where
I: Integer,
for<'a> &'a I: IntegerRef<I>,
R: Rational<I>,
for<'a> &'a R: RationalRef<&'a I, R>,
Sourcepub fn write_stats(
&self,
out: &mut impl Write,
threshold: &R,
surplus: &R,
) -> Result<()>
pub fn write_stats( &self, out: &mut impl Write, threshold: &R, surplus: &R, ) -> Result<()>
Writes statistics about this vote count to the given output.
Sourcefn accumulate_votes_serial(
election: &Election,
keep_factors: &[R],
pascal: Option<&[Vec<I>]>,
) -> VoteAccumulator<I, R>
fn accumulate_votes_serial( election: &Election, keep_factors: &[R], pascal: Option<&[Vec<I>]>, ) -> VoteAccumulator<I, R>
Serial implementation of vote counting, using only one CPU core.
Sourcepub(crate) fn process_ballot(
vote_accumulator: &mut VoteAccumulator<I, R>,
keep_factors: &[R],
pascal: Option<&[Vec<I>]>,
i: usize,
ballot: &Ballot,
)
pub(crate) fn process_ballot( vote_accumulator: &mut VoteAccumulator<I, R>, keep_factors: &[R], pascal: Option<&[Vec<I>]>, i: usize, ballot: &Ballot, )
Processes a ballot and adds its votes to the accumulator.
Sourcepub fn threshold(&self, election: &Election) -> R
pub fn threshold(&self, election: &Election) -> R
Computes the new threshold, based on the election parameters and the exhausted votes after this count.
Sourcepub fn surplus_droop(&self, threshold: &R, elected: &[usize]) -> R
pub fn surplus_droop(&self, threshold: &R, elected: &[usize]) -> R
Computes the current surplus, based on the votes, the threshold and the currently elected candidates, in a manner compatible with Droop.py. This is the sum of the differences between the received vote count and the required threshold, across all elected candidates.
Note: Normally we’d only add positive surpluses here, but sometimes an
already elected candidate goes below the threshold. In this case,
Droop.py just sums the difference for the elected candidates, which
can lead to crashes. See the Self::surplus_positive() function which
fixes this behavior.
Sourcepub fn surplus_positive(&self, threshold: &R, elected: &[usize]) -> R
pub fn surplus_positive(&self, threshold: &R, elected: &[usize]) -> R
Computes the current surplus, based on the votes, the threshold and the currently elected candidates. This is the sum of the differences between the received vote count and the required threshold, across all elected candidates.
Note: Normally we’d only add positive surpluses here, but sometimes an
already elected candidate goes below the threshold. In this case, this
function counts a positive surplus for this candidate. See the
Self::surplus_droop() function for Droop.py’s behavior.
Sourcepub fn threshold_exhausted(election: &Election, exhausted: &R) -> R
pub fn threshold_exhausted(election: &Election, exhausted: &R) -> R
Computes the new threshold, based on the given election parameters and exhausted votes.
This is the ratio between the effectively used voting power (i.e. subtracted from any exhausted voting power) and the number of elected seats plus one.
Auto Trait Implementations§
impl<I, R> Freeze for VoteCount<I, R>where
R: Freeze,
impl<I, R> RefUnwindSafe for VoteCount<I, R>where
R: RefUnwindSafe,
I: RefUnwindSafe,
impl<I, R> Send for VoteCount<I, R>
impl<I, R> Sync for VoteCount<I, R>
impl<I, R> Unpin for VoteCount<I, R>
impl<I, R> UnwindSafe for VoteCount<I, R>where
R: UnwindSafe,
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more