VoteCount

Struct VoteCount 

Source
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: R

Exhausted voting power.

§_phantom: PhantomData<I>

Implementations§

Source§

impl<I, R> VoteCount<I, R>
where I: Integer + Send + Sync, for<'a> &'a I: IntegerRef<I>, R: Rational<I> + Send + Sync, for<'a> &'a R: RationalRef<&'a I, R>,

Source

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.

Source

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>,

Source

pub fn write_stats( &self, out: &mut impl Write, threshold: &R, surplus: &R, ) -> Result<()>

Writes statistics about this vote count to the given output.

Source

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.

Source

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.

Source

pub fn threshold(&self, election: &Election) -> R

Computes the new threshold, based on the election parameters and the exhausted votes after this count.

Source

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.

Source

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.

Source

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>

§

impl<I, R> Send for VoteCount<I, R>
where R: Send, I: Send,

§

impl<I, R> Sync for VoteCount<I, R>
where R: Sync, I: Sync,

§

impl<I, R> Unpin for VoteCount<I, R>
where R: Unpin, I: Unpin,

§

impl<I, R> UnwindSafe for VoteCount<I, R>
where R: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.