Skip to content

Commit e0954aa

Browse files
committed
Update readme with Weighted functions amd methods
1 parent 2ce90c9 commit e0954aa

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ The act of voting represents calling the `Vote` function with a `Ballot` map whe
1818

1919
Alternatively, `VoteRanked` accepts a pre-ordered slice of ranks (`[][]C`), avoiding map hashing overhead and enabling high-performance, low-allocation ingestion.
2020

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+
2123
### Features
2224

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`).
2427
- **Dynamic candidate adjustment**: `SetChoices` updates the pairwise preferences if choices need to be added, removed, or rearranged during active voting, while mathematically preserving consistency.
2528
- **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`).
29+
- **Direct ranked slice voting**: `VoteRanked` and `VoteRankedWeighted` accept ranked slices of candidates (`[][]C`).
2730
- **Generic Ballot Ingestion**: `VoteFrom` enables voting directly from arbitrary external structures using a custom ranking function.
2831
- **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`).
2932
- **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
3740

3841
`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.
3942

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+
4045
## Results & Duels
4146

4247
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

Comments
 (0)