Last active
May 26, 2016 23:53
-
-
Save jmoyers/b212710b776a050a1c8030bf3d23c387 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// From https://thesquareplanet.com/blog/the-path-to-rust/ | |
// Example 2: non-functional | |
let mut idx = HashMap::new(); | |
for fname in &args { | |
let f = match fs::File::open(fname) { | |
Ok(f) => io::BufReader::new(f), | |
Err(e) => panic!("input file {} could not be opened: {}", fname, e), | |
}; | |
let mut words = HashSet::new(); | |
for line in f.lines() { | |
for w in line.unwrap().split_whitespace() { | |
if words.insert(w.to_string()) { | |
// new word seen | |
idx.entry(w.to_string()).or_insert(Vec::new()).push(fname); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment