Documentation ¶
Overview ¶
Package gocondorcet provides methods for running Condorcet elections.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrCyclicVote = errors.New("cyclic vote detected: cannot reference a candidate twice in a vote")
)
Defined errors.
Functions ¶
This section is empty.
Types ¶
type CandidateID ¶
type CandidateID string
CandidateID is a unique identifier for a candidate.
func BasicParseFn ¶
func BasicParseFn(in string) (CandidateID, error)
BasicParseFn provides a basic implementation of CandidateIDParseFn. The parser will trim whitespace and uppercase input.
type CandidateIDParseFn ¶
type CandidateIDParseFn func(string) (CandidateID, error)
CandidateIDParseFn should convert a user inputted candidate name into a CandidateID. you may wish to trim whitespace, convert to uppercase, etc. If the input corresponds to no valid candidate, you should return an error with the main reason.
type InvalidVote ¶
InvalidVote describes an issue with input which could not be parsed into a vote.
type Preference ¶
type Preference uint
Preference indicates to what degree something is preferred over other options. 0 is the highest preference, indicating most preferred.
type Results ¶
type Results []CandidateID
Results consists of the ranked set of candidates, resulting from an election.
type Vote ¶
type Vote map[CandidateID]Preference
Vote allocates preferences to candidates (0 being highest preference). A vote may give candidates equal preference, and may omit candidates (effectively giving them equal lowest preference).
type VoteReader ¶
type VoteReader struct {
// contains filtered or unexported fields
}
VoteReader wraps an io.Reader to read Votes.
func NewVoteReader ¶
func NewVoteReader(r io.Reader, parseFn CandidateIDParseFn) *VoteReader
NewVoteReader is a constructor.
func (*VoteReader) Read ¶
func (vr *VoteReader) Read() (*Vote, error)
func (*VoteReader) ReadAll ¶
func (vr *VoteReader) ReadAll() ([]Vote, []InvalidVote)
ReadAll reads all votes from the VoteReader (until the reader reaches EOF). Lines which can't be parsed are returned as InvalidVotes.