Giter Club home page Giter Club logo

condorcet's Introduction

Condorcet

This is the Git repo for the Condorcet library, which attempts to provide safe and easy methods for calculating elections in Rust. This repo contains two crates: condorcet and condorcet_primitives. condorcet_primitives is for those who just want the functions to calculate different voting methods. condorcet takes those functions and wraps them in an easy-to-use API.

All code is released under the terms of the MIT License.

condorcet's People

Contributors

iohannesarnold avatar

Watchers

James Cloos avatar  avatar  avatar

condorcet's Issues

Data Structures for Ballots

Right now, a ballot is HashMap<T, u8>. I'm not sure if this is what I want though. To start with, I probably want to increase the u8 to at least a u16 since it's conceivable that more than 255 people/items might be in contention for some position in some edge cases. More importantly, I'm not sure if a HashMap is the right type of collection. It implies a constraint that T has to have Hash and I don't know how burdensome that is. I know it's a trivial #[derive(Hash)] for basic data like strings but I'd like to see Condorcet being used in more complex applications where one might be voting on complicated data structure representing, say, programs to be run. So I don't know if it would be better for me to implement ballots as a BTree or a Vec of Tuples or something else.

`clone()` and taking ballots by reference

So currently the code is idiomatic Rust where all functions and methods take their arguments by references, e.g.

      pub fn add_ballot(&mut self, ballot: &HashMap<T, u8>) {
          if self.ballots_lock {
              panic!("Attempting to add ballot when ballots are locked")
          }
          for (key, val) in ballot.iter() {
              if self.candidates_lock && !self.candidates.contains(key) {
                  panic!("Ballot contains unauthorized candidate")
              }
          }
          self.ballots.push(ballot.clone())
      }

But as a result of that I have to clone the ballot and later when I calculate the results I have to clone things again:

let mut results: HashMap<T, u8> = candidates.iter().cloned().map(|x| (x, 0)).collect();

It should allow me to get rid of all the cloning if I take ownership of the ballots rather then get them by reference, right? And since they're ballots, it would seem unlikely that anyone would have need of them after the election has been calculated, and if they did, they could always clone a copy themselves. Right? So what do I loose by taking ownership of the ballots and candidates, rather than taking them by reference?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.