Browse Source

Use stderror more

master
Stephen 5 months ago
parent
commit
45896a54a0
4 changed files with 16 additions and 18 deletions
  1. +3
    -3
      src/bin/explorer.rs
  2. +6
    -8
      src/bin/longestpath.rs
  3. +5
    -5
      src/bin/wiki2graph.rs
  4. +2
    -2
      src/process.rs

+ 3
- 3
src/bin/explorer.rs View File

@ -7,13 +7,13 @@ use wikigraph::process::Graph;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Usage: ./{} bincode_file", args[0]);
eprintln!("Usage: ./{} bincode_file", args[0]);
return;
}
println!("Loading graph...");
eprintln!("Loading graph...");
let graph = Graph::load_bin(&args[1]);
println!("Done. {} nodes loaded.", graph.nodes.len());
eprintln!("Done. {} nodes loaded.", graph.nodes.len());
// Print all article titles
// graph.nodes.iter().for_each(|(_, v)| { println!("{}", v) });


+ 6
- 8
src/bin/longestpath.rs View File

@ -14,19 +14,19 @@ use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Usage: ./{} bincode_file", args[0]);
eprintln!("Usage: ./{} bincode_file", args[0]);
return;
}
println!("Loading graph...");
eprintln!("Loading graph...");
let mut graph = Graph::load_bin(&args[1]);
println!("Done.\r\nReversing direction of edges...");
eprintln!("Done.\r\nReversing direction of edges...");
graph.edges.par_iter_mut().for_each(|mut e| {
let tmp = e.from;
e.from = e.to;
e.to = tmp;
});
println!("Done.\r\nPreparing for Dijkstra's algorithm...");
eprintln!("Done.\r\nPreparing for Dijkstra's algorithm...");
//Since the graph is reversed, this is really the end point
let start = *graph
.nodes
@ -61,7 +61,7 @@ fn main() {
let mut unvisited_nodes: FnvHashSet<u32> = graph.nodes.par_iter().map(|(k, _)| *k).collect();
let mut slightly_visited_nodes: MiniVec = MiniVec::new(HashMap::new());
println!("Done.\r\nPerforming Dijkstra's algorithm...");
eprintln!("Done.\r\nPerforming Dijkstra's algorithm...");
let mut last_print = std::usize::MAX;
let mut cur_node = start;
@ -98,11 +98,9 @@ fn main() {
break;
}
cur_node = slightly_visited_nodes.get_min_distance();
//println!("Done");
}
println!("Done! Grabbing distances...");
eprintln!("Done! Grabbing distances...");
for (id, dist) in distances {
if dist > 5 && dist < std::u8::MAX {
let s = &graph.nodes[&id];


+ 5
- 5
src/bin/wiki2graph.rs View File

@ -29,7 +29,7 @@ fn main() {
//Process command line args
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!(
eprintln!(
"Usage: ./{} wikipedia_xml_file output_bincode_file",
args[0]
);
@ -39,7 +39,7 @@ fn main() {
let input_filename = &args[1];
let output_filename = &args[2];
println!("Converting {} to {}", input_filename, output_filename);
eprintln!("Converting {} to {}", input_filename, output_filename);
let file = File::open(input_filename).unwrap();
let file = BufReader::new(file);
@ -125,7 +125,7 @@ fn main() {
}
Ok(XmlEvent::Characters(data)) => match state {
FileState::Title => {
println!("Title: {}", data);
eprintln!("Title: {}", data);
}
FileState::PageTitle => {
cur_page.title += &data;
@ -136,7 +136,7 @@ fn main() {
_ => {}
},
Err(e) => {
println!("Error: {}", e);
eprintln!("Error: {}", e);
break;
}
_ => {}
@ -150,7 +150,7 @@ fn main() {
h.join().unwrap();
}
println!("Done! Saving...");
eprintln!("Done! Saving...");
if let Ok(graph) = Arc::try_unwrap(graph) {
save_graph(graph.into_inner().unwrap(), output_filename);
} else {


+ 2
- 2
src/process.rs View File

@ -90,8 +90,8 @@ pub fn process_graph(graph: &Arc<Mutex<GraphIntermediate>>, page: WikiPage) {
if graph.edges.len() % 10000 == 0
/*|| graph.edges.len() > 58730000*/
{
println!("{} nodes, {} edges.", graph.nodes.len(), graph.edges.len());
println!("{}", page.title);
eprintln!("{} nodes, {} edges.", graph.nodes.len(), graph.edges.len());
eprintln!("{}", page.title);
}
});
}


Loading…
Cancel
Save