-
-
Save whatalnk/74ec185473a752dae06a1163e90ad7ff to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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
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
Update counter.
Take data and HashMap, update HashMap, return HashMap.