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 (egf64
for fractional vote weights). If usingVariant::Dowdall
then a float, arational
, or anyting that implementsReal
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
impl<T, C> BordaTally<T, C> where
T: Eq + Clone + Hash,
C: Copy + PartialOrd + AddAssign + Num + NumCast,
impl<T, C> BordaTally<T, C> where
T: Eq + Clone + Hash,
C: Copy + PartialOrd + AddAssign + Num + NumCast,
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.)
pub fn with_capacity(
num_winners: usize,
variant: Variant<C>,
expected_candidates: usize
) -> Self
pub fn with_capacity(
num_winners: usize,
variant: Variant<C>,
expected_candidates: usize
) -> Self
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 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
impl<T, C = u64> !RefUnwindSafe for BordaTally<T, C>
impl<T, C = u64> !Send for BordaTally<T, C>
impl<T, C = u64> !Sync for BordaTally<T, C>
impl<T, C> Unpin for BordaTally<T, C> where
C: Unpin,
T: Unpin,
impl<T, C = u64> !UnwindSafe for BordaTally<T, C>