+fn tally_votes(dir: &Path) -> std::io::Result<HashMap<String, HashSet<String>>> {
+ let mut tally: HashMap<String, HashSet<String>> = HashMap::new();
+ if let Ok(vfile) = std::fs::File::open(dir.to_owned().join("votes")) {
+ for liner in std::io::BufReader::new(vfile).lines() {
+ let line = liner?;
+ if let Some((voter, datum)) = line.split_once(' ') {
+ if voter.len() == COOKIE_LENGTH {
+ if let Some((vote, candidate)) = datum.split_once(' ') {
+ if vote == "0" {
+ if let Some(entry) = tally.get_mut(candidate) {
+ entry.remove(voter);
+ }
+ } else if vote == "1" {
+ tally
+ .entry(candidate.to_owned())
+ .or_default()
+ .insert(voter.to_owned());
+ }
+ }
+ }
+ }
+ }
+ }
+ Ok(tally)
+}
+
+fn valid_id_char(c: u8) -> bool {
+ (b'A'..=b'Z').contains(&c) || (b'a'..=b'z').contains(&c) || (b'0'..=b'9').contains(&c)
+}
+