Feature: Now a library as well as a binary
This commit is contained in:
parent
f54794bdfe
commit
1acbeaf647
10
Cargo.toml
10
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]
|
||||
|
28
src/bin/main.rs
Normal file
28
src/bin/main.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use page_rank::Graph;
|
||||
|
||||
fn main() {
|
||||
let mut pages: Graph<char> = 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}")
|
||||
}
|
||||
}
|
@ -1,32 +1,5 @@
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
fn main() {
|
||||
let mut pages: Graph<char> = 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<T> {
|
||||
nodes: HashMap<T, Node<T>>,
|
Loading…
Reference in New Issue
Block a user