Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active January 10, 2025 16:33
Show Gist options
  • Save RandyMcMillan/c945400e4d5f6bbb6d2aa37f1696541d to your computer and use it in GitHub Desktop.
Save RandyMcMillan/c945400e4d5f6bbb6d2aa37f1696541d to your computer and use it in GitHub Desktop.
hash_map_count.rs
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);
println!("{}",hash);
*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