-
-
Save RandyMcMillan/c7b011e3e05422e017b4dcda935bf9e7 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
use std::collections::HashMap; | |
use std::hash::{Hash, Hasher}; | |
fn main() { | |
let mut counts = HashMap::new(); | |
for i in 0..=144 { | |
let hash = hash_value(&i); | |
*counts.entry(hash).or_insert(0) += 1; | |
} | |
println!("{:?}", counts); | |
} | |
fn hash_value<T: Hash>(t: &T) -> u64 { | |
let mut s = std::hash::SipHasher::new(); | |
t.hash(&mut s); | |
s.finish() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment