Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active February 28, 2025 12:08
Show Gist options
  • Save RandyMcMillan/1d23455b0a7c1c77458e7b85b88f955b to your computer and use it in GitHub Desktop.
Save RandyMcMillan/1d23455b0a7c1c77458e7b85b88f955b to your computer and use it in GitHub Desktop.
sorted_hashmap.re
use std::collections::HashMap;
fn main() {
let mut hashmap: HashMap<i32, (i32, i32)> = HashMap::new();
for count in 0..1000 {
hashmap.insert(count, (count, count % 13));
}
let mut sorted_vec: Vec<(&i32, &(i32, i32))> = hashmap.iter().collect();
sorted_vec.sort_by_key(|(key, _value)| *key);
for vec in sorted_vec {
println!("{:?}", vec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment