diff --git a/Cargo.toml b/Cargo.toml index 5e6bdf6..f9f6f74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,14 @@ [package] name = "page_rank" version = "0.1.0" -edition = "2021" +edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name = "page_ranker" +path = "src/bin/main.rs" + +[lib] +name = "page_rank" +path = "src/lib/lib.rs" [dependencies] diff --git a/src/bin/main.rs b/src/bin/main.rs new file mode 100644 index 0000000..9b5853e --- /dev/null +++ b/src/bin/main.rs @@ -0,0 +1,28 @@ +use page_rank::Graph; + +fn main() { + let mut pages: Graph = Graph::new(); + pages.add_page('A'); + pages.add_page('B'); + pages.add_page('C'); + pages.add_page('D'); + pages.add_page('E'); + + pages.add_link('A', 'E'); + + pages.add_link('B', 'A'); + pages.add_link('B', 'D'); + pages.add_link('B', 'E'); + + pages.add_link('C', 'B'); + + pages.add_link('D', 'C'); + + pages.add_link('E', 'D'); + + // println!("{pages:?}"); + pages.page_rank(40); + for (page, score) in pages.get_sorted_scores() { + println!("{page} => {score:.2}") + } +} \ No newline at end of file diff --git a/src/main.rs b/src/lib/lib.rs similarity index 74% rename from src/main.rs rename to src/lib/lib.rs index 2bdc131..e96c53c 100644 --- a/src/main.rs +++ b/src/lib/lib.rs @@ -1,32 +1,5 @@ use std::{collections::HashMap, hash::Hash}; -fn main() { - let mut pages: Graph = Graph::new(); - pages.add_page('A'); - pages.add_page('B'); - pages.add_page('C'); - pages.add_page('D'); - pages.add_page('E'); - - pages.add_link('A', 'E'); - - pages.add_link('B', 'A'); - pages.add_link('B', 'D'); - pages.add_link('B', 'E'); - - pages.add_link('C', 'B'); - - pages.add_link('D', 'C'); - - pages.add_link('E', 'D'); - - // println!("{pages:?}"); - pages.page_rank(40); - for (page, score) in pages.get_sorted_scores() { - println!("{page} => {score:.2}") - } -} - #[derive(Debug, Clone)] pub struct Graph { nodes: HashMap>,