Skip to content

Commit

Permalink
docs(readme): update readme with function documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnamchoi committed Mar 21, 2024
1 parent 793b559 commit 2ee10ea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,51 @@ Additional sources:
* https://www.aec.gov.au/learn/files/poster-count-senate-pref-voting.pdf
* https://www.aec.gov.au/learn/files/poster-counting-hor-pref-voting.pdf
* https://facultycouncil.utexas.edu/hare-clark-preferential-voting-system

## Usage

This is a single-header library. To use this, simply download the `src/hare-clark.hpp` file into your project and `#include "hare-clark.hpp"`.

However, it is recommended that you add this repository as a submodule using `git submodule add https://github.com/tinnamchoi/hare-clark-cpp` to make updating the library easier. Read more on Git submodules [here](https://git-scm.com/book/en/v2/Git-Tools-Submodules).

### Functions

#### `HareClark(int number_of_vacancies = 1)`

Construct a new Hare Clark object

| Parameters | Description |
| --------------------- | ----------------------------------- |
| `number_of_vacancies` | Number of vacancies, defaulted to 1 |

#### `void add_candidates(std::vector<std::string> candidates)`

Add to the list of candidates

| Parameters | Description |
| ------------ | ------------------------------ |
| `candidates` | List of candidates to be added |

#### `void add_ballots(std::vector<std::vector<int>> ballots)`

Add to the list of ballots

| Parameters | Description |
| ---------- | --------------------------- |
| `ballots` | List of ballots to be added |

Each ballot is a list of integers, where each integer represents the index of the candidate in the list of candidates.

e.g. with a candidate list of `{"A", "B", "C"}`, a ballot of `{2, 0, 1}` would represent a ballot with "C" as the first preference, "A" as the second preference, and "B" as the third preference.

#### `std::vector<std::string> run()`

Run the Hare-Clark process

| Returns | Description |
| -------------------- | -------------------------- |
| `elected_candidates` | List of elected candidates |

## Examples

For a practical example of the library being applied, see [example/README.md](example/README.md)
2 changes: 1 addition & 1 deletion src/hare-clark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HareClark {
*
* @param ballots List of ballots to be added
* @details Each ballot is a list of integers, where each integer represents the index of the candidate in the list of candidates.
* @details e.g. with a candidate list of {"A", "B", "C"}, a ballot of {2, 0, 1} would represent a ballot with "C" as the first preference, "A" as the second preference, and "B" as the third preference.
* @details e.g. with a candidate list of `{"A", "B", "C"}`, a ballot of `{2, 0, 1}` would represent a ballot with "C" as the first preference, "A" as the second preference, and "B" as the third preference.
*/
void add_ballots(std::vector<std::vector<int>> ballots) {
for (std::vector<int>& ballot : ballots) std::reverse(ballot.begin(), ballot.end());
Expand Down

0 comments on commit 2ee10ea

Please sign in to comment.