Struct tallystick::borda::BordaTally[][src]

pub struct BordaTally<T, C = u64> where
    T: Eq + Clone + Hash,
    C: Copy + PartialOrd + AddAssign + Num + NumCast
{ /* fields omitted */ }
Expand description

A generic borda tally.

Generics:

  • T: The candidate type.
  • C: The count type. u64 is recommended, but can be modified to use a different type for counting votes (eg f64 for fractional vote weights). If using Variant::Dowdall then a float, a rational, or anyting that implements Real must be used.

Example:

   use tallystick::borda::BordaTally;
   use tallystick::borda::Variant;

   // A tally with string candidates, one winner, `f64` counting, using the Dowall point system.
   let mut tally = BordaTally::<&str, f64>::new(1, Variant::Dowdall);
   tally.add(vec!["Alice", "Bob", "Carlos"]);
   tally.add(vec!["Bob", "Carlos", "Alice"]);
   tally.add(vec!["Alice", "Carlos", "Bob"]);
   tally.add(vec!["Alice", "Bob", "Carlos"]);

   let winners = tally.winners();

Implementations

Create a new BordaTally with the given number of winners.

If there is a tie, the number of winners might be more than num_winners. (See winners() for more information on ties.)

Create a new BordaTally with the given number of winners, and number of expected candidates.

Add a new vote

Votes are represented as a vector of ranked candidates, ordered by preference. An error will only be returned if vote contains duplicate candidates.

Add a new vote by reference

Add a weighted vote. By default takes a weight as a usize integer, but can be customized by using BordaTally with a custom vote type.

Add a weighted vote by reference

Get a ranked list of winners. Winners with the same rank are tied. The number of winners might be greater than the requested num_winners if there is a tie. In a borda count, the winners are determine by what candidate obtains the most points.

Get a ranked list of all candidates. Candidates with the same rank are tied.

Get point totals for this tally.

This will return a vector with the number of borda points for each candidate.

Example

   use tallystick::borda::DefaultBordaTally;
   use tallystick::borda::Variant;

   let mut tally = DefaultBordaTally::new(1, Variant::ClassicBorda);
   for _ in 0..30 { tally.add(vec!["Alice", "Bob"]).unwrap() }
   for _ in 0..10 { tally.add(vec!["Bob", "Alice"]).unwrap() }

   for (candidate, num_points) in tally.totals().iter() {
      println!("{} has {} points", candidate, num_points);
   }
   // Prints:
   //   Alice has 70 points
   //   Bob has 30 points

Get a list of all candidates seen by this tally. Candidates are returned in no particular order.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.