You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,12 +18,15 @@ The act of voting represents calling the `Vote` function with a `Ballot` map whe
18
18
19
19
Alternatively, `VoteRanked` accepts a pre-ordered slice of ranks (`[][]C`), avoiding map hashing overhead and enabling high-performance, low-allocation ingestion.
20
20
21
+
For elections where voters have different voting powers (such as shareholder voting, token- or stake-weighted governance, or pre-aggregated ballot batches), `VoteWeighted` and `VoteRankedWeighted` scale pairwise preferences by a positive numeric weight. Correspondingly, `UnvoteWeighted` removes a weighted vote using the ballot's `Record` and the original weight. Weights must be strictly greater than zero; non-positive weights return `ErrInvalidWeight`.
22
+
21
23
### Features
22
24
23
-
-**Reversible voting**: The `Unvote` function allows rolling back a previously added `Ballot` using its returned `Record`, enabling voters to change their vote without re-tallying all ballots.
25
+
-**Reversible voting**: The `Unvote` and `UnvoteWeighted` functions allow rolling back a previously added ballot using its returned `Record`, enabling voters to change their vote without re-tallying all ballots.
26
+
-**Weighted voting**: `VoteWeighted`, `VoteRankedWeighted`, and `UnvoteWeighted` scale preferences by a voter's voting power (e.g. shareholder voting, stake-weighted governance, or batch processing), validating that weight is greater than zero (`ErrInvalidWeight`).
24
27
-**Dynamic candidate adjustment**: `SetChoices` updates the pairwise preferences if choices need to be added, removed, or rearranged during active voting, while mathematically preserving consistency.
25
28
-**Choice Validation**: `ValidateChoices` ensures choices list is not empty and contains no duplicate candidates.
26
-
-**Direct ranked slice voting**: `VoteRanked`accepts ranked slices of candidates (`[][]C`).
-**Generic Ballot Ingestion**: `VoteFrom` enables voting directly from arbitrary external structures using a custom ranking function.
28
31
-**Type transformations (`Map`)**: `Record`, `Result`, `Duel`, and `Voting` support Go method type parameters via `.Map(...)` to translate between choice identifiers (e.g. `UUID` $\leftrightarrow$ `string` $\leftrightarrow$ `int`).
29
32
-**Standard Go iterators**: `Duels` provides a standard `iter.Seq[*Duel[C]]` iterator for range-over-func loops.
@@ -37,6 +40,8 @@ Alternatively, `VoteRanked` accepts a pre-ordered slice of ranks (`[][]C`), avoi
37
40
38
41
`Voting[C]` holds the number of votes for every pair of choices. It is a convenient construct to use when the preferences slice does not have to be exposed, and should be kept safe from accidental mutation. Methods on the `Voting` type are not safe for concurrent calls.
39
42
43
+
It provides methods for both standard and weighted voting (`Vote`, `VoteWeighted`, `VoteRanked`, `VoteRankedWeighted`, `Unvote`, `UnvoteWeighted`, `VoteFrom`), as well as candidate updates, mapping, and preference import/export.
44
+
40
45
## Results & Duels
41
46
42
47
Results are computed by `Compute`, returning the ranked list of choices and an iterator over all pairwise `Duels`. With Go range-over-func iterators, you can iterate over duels directly:
0 commit comments