Implement new graph data structure and dijkstra
This commit is contained in:
parent
778cb6748d
commit
18e54c4ce1
6 changed files with 516 additions and 3 deletions
|
|
@ -1,11 +1,16 @@
|
|||
mod algo;
|
||||
pub mod commands;
|
||||
mod data;
|
||||
mod graph;
|
||||
mod util;
|
||||
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
use std::io::{self, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
|
||||
use clap::Parser;
|
||||
use data::store;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Parser)]
|
||||
pub enum PhilosophyGameCmd {
|
||||
|
|
@ -35,8 +40,18 @@ enum Command {
|
|||
#[arg(short, long)]
|
||||
flip: bool,
|
||||
},
|
||||
/// Find a path from one article to another.
|
||||
Path2 {
|
||||
from: String,
|
||||
to: String,
|
||||
/// Flip start and end article.
|
||||
#[arg(short, long)]
|
||||
flip: bool,
|
||||
},
|
||||
/// Find the longest shortest path starting at an article.
|
||||
LongestShortestPath { from: String },
|
||||
LongestShortestPath {
|
||||
from: String,
|
||||
},
|
||||
/// Analyze articles using "Philosophy Game" rules.
|
||||
PhilosophyGame {
|
||||
#[command(subcommand)]
|
||||
|
|
@ -49,6 +64,7 @@ enum Command {
|
|||
/// The page to inspect.
|
||||
page: String,
|
||||
},
|
||||
Test,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
|
|
@ -74,6 +90,13 @@ fn main() -> io::Result<()> {
|
|||
commands::path::path(&args.datafile, &from, &to)
|
||||
}
|
||||
}
|
||||
Command::Path2 { from, to, flip } => {
|
||||
if flip {
|
||||
commands::path2::path(&args.datafile, &to, &from)
|
||||
} else {
|
||||
commands::path2::path(&args.datafile, &from, &to)
|
||||
}
|
||||
}
|
||||
Command::LongestShortestPath { from } => {
|
||||
commands::longest_shortest_path::run(&args.datafile, &from)
|
||||
}
|
||||
|
|
@ -82,5 +105,21 @@ fn main() -> io::Result<()> {
|
|||
}
|
||||
Command::ListPages => commands::list_pages::run(&args.datafile),
|
||||
Command::ListLinks { page } => commands::list_links::run(&args.datafile, &page),
|
||||
Command::Test => test(&args.datafile),
|
||||
}
|
||||
}
|
||||
|
||||
fn test(datafile: &Path) -> io::Result<()> {
|
||||
let a = Instant::now();
|
||||
// println!(">> Import adjacency list");
|
||||
// let mut databuf = BufReader::new(File::open(datafile)?);
|
||||
// let adjlist = store::read_adjacency_list(&mut databuf)?;
|
||||
println!(">> Import graph");
|
||||
let mut databuf = BufReader::new(File::open(datafile)?);
|
||||
let (pages, links, graph) = store::read_graph(&mut databuf)?;
|
||||
let b = Instant::now();
|
||||
|
||||
println!("{:?}", b.duration_since(a));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue