Created
May 26, 2017 14:33
-
-
Save gregkatz/39ee2be6585c81874f83ca7712fc54f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate csv; | |
use std::error::Error; | |
use std::collections::HashMap; | |
use csv::ReaderBuilder; | |
fn main() { | |
match run() { | |
Ok(_) => {}, | |
Err(e) => println!("Error: {:?}", e), | |
}; | |
} | |
fn run() -> Result<(), Box<Error>> { | |
let mut map: HashMap<String, i64> = HashMap::new(); | |
let mut reader = ReaderBuilder::new() | |
.delimiter(b'\t') | |
.from_path("./googledata")?; | |
for record in reader.records() { | |
let record = record?; | |
*map.entry(record[1].into()).or_insert(0) += record[2].parse()?; | |
} | |
if let Some((max_key, max_val)) = map.iter().max_by_key(|&(_, v)| v) { | |
println!("max_key: {} sum: {}", max_key, max_val); | |
} else { | |
println!("No entries"); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment