Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2018 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6343245400e26c39f28fb80ffe586cf3 to your computer and use it in GitHub Desktop.
Save anonymous/6343245400e26c39f28fb80ffe586cf3 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
use std::collections::HashMap;
fn make_freq_table<'a>(
data: &'a [u16],
counter: HashMap<&'a u16, usize>,
) -> HashMap<&'a u16, usize> {
let mut c = counter;
for x in data {
let entry = c.entry(x).or_insert(0);
*entry += 1;
}
c
}
fn main() {
let mut c = HashMap::new();
let data = &[1, 2, 3, 4, 5];
c = make_freq_table(data, c);
c = make_freq_table(data, c);
c = make_freq_table(data, c);
println!("{:?}", c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment