Skip to content

Instantly share code, notes, and snippets.

@howarddierking
Last active September 16, 2021 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howarddierking/b61a5b47ff3c60ab2d0429f1b208b707 to your computer and use it in GitHub Desktop.
Save howarddierking/b61a5b47ff3c60ab2d0429f1b208b707 to your computer and use it in GitHub Desktop.
sorting causes move
fn report_adjacency_list(g: HashMap<u32, Vec<u32>>){
// need to sort
let sorted_keys = g.keys().sorted();
println!("{}\t# number of vertices", g.len());
let mut last_line = 1 + sorted_keys.len();
for (i, k) in sorted_keys.enumerate() {
let val = g.get(k).unwrap();
println!("{}\t# starting value for vertex {}", last_line, i + 1);
last_line = last_line + val.len();
}
// Good lord this is ugly. TODO: figure out how I can get sorted keys without
// using an iterator that consumes the collection, thus moving the pointer
let sorted_keys_2 = g.keys().sorted();
for k in sorted_keys_2 {
let val = g.get(k).unwrap();
for z in val{
println!("{0} 1\t# Vertex {1} is adjacent to vertex {0}", z, k);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment