Last active
September 16, 2021 00:49
-
-
Save howarddierking/b61a5b47ff3c60ab2d0429f1b208b707 to your computer and use it in GitHub Desktop.
sorting causes move
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
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