From 8c110e0999b699815b64ba357ef6ed371d0f9f0a Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Tue, 16 Jan 2024 19:55:20 -0800 Subject: [PATCH] make topo.graph pub --- examples/all_paths.rs | 2 +- examples/all_paths_between_two_ases.rs | 2 +- examples/draw_path_graph.rs | 4 ++-- examples/read_caida_as.rs | 2 +- examples/shortest_path_between_two_ases.rs | 2 +- src/lib.rs | 16 ++++------------ 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/examples/all_paths.rs b/examples/all_paths.rs index 6b21c45..0c2070d 100644 --- a/examples/all_paths.rs +++ b/examples/all_paths.rs @@ -31,7 +31,7 @@ fn main() { all_paths.push(path.clone()); let childrens = topo - .raw_graph() + .graph .neighbors_directed(node_idx, petgraph::Direction::Outgoing) .map(|child_idx| { let mut path = path.clone(); diff --git a/examples/all_paths_between_two_ases.rs b/examples/all_paths_between_two_ases.rs index 805554c..4b91117 100644 --- a/examples/all_paths_between_two_ases.rs +++ b/examples/all_paths_between_two_ases.rs @@ -12,7 +12,7 @@ fn main() { let ut_path = topo.paths_graph(university_of_twente_asn); let paths = all_simple_paths::, _>( - ut_path.raw_graph(), + ut_path.graph, ut_path.index_of(university_of_twente_asn).unwrap(), ut_path.index_of(universidade_de_sao_paulo_asn).unwrap(), 0, diff --git a/examples/draw_path_graph.rs b/examples/draw_path_graph.rs index 3c55b6e..1b79249 100644 --- a/examples/draw_path_graph.rs +++ b/examples/draw_path_graph.rs @@ -13,11 +13,11 @@ fn main() { ]); println!("Basic topology"); - println!("{:?}", Dot::new(&topo.raw_graph())); + println!("{:?}", Dot::new(&topo.graph)); let topo_path = topo.paths_graph(4); println!("Path topology"); - println!("{:?}", Dot::new(&topo_path.raw_graph())); + println!("{:?}", Dot::new(&topo_path.graph)); // You can visualize the graphs online at https://dreampuf.github.io/GraphvizOnline/ } diff --git a/examples/read_caida_as.rs b/examples/read_caida_as.rs index c19b3e5..4d8b688 100644 --- a/examples/read_caida_as.rs +++ b/examples/read_caida_as.rs @@ -6,5 +6,5 @@ fn main() { let file = File::open("20231201.as-rel.txt").unwrap(); let topo = Topology::from_caida(file).unwrap(); - println!("Number of ases: {}", topo.raw_graph().node_count()); + println!("Number of ases: {}", topo.graph.node_count()); } diff --git a/examples/shortest_path_between_two_ases.rs b/examples/shortest_path_between_two_ases.rs index a5bbda8..6279fae 100644 --- a/examples/shortest_path_between_two_ases.rs +++ b/examples/shortest_path_between_two_ases.rs @@ -13,7 +13,7 @@ fn main() { // Use A* to find the shortest path between two nodes let (_len, path) = astar( - ut_path.raw_graph(), + ut_path.graph, ut_path.index_of(university_of_twente_asn).unwrap(), |finish| finish == ut_path.index_of(universidade_de_sao_paulo_asn).unwrap(), |edge| match edge.weight() { diff --git a/src/lib.rs b/src/lib.rs index 3a18c03..a93f493 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ impl Default for RelType { } pub struct Topology { - graph: DiGraph, + pub graph: DiGraph, } #[derive(Debug)] @@ -300,14 +300,6 @@ impl Topology { // assert!(!is_cyclic_directed(&graph)); Topology { graph } } - - pub fn raw_graph(&self) -> &DiGraph { - &self.graph - } - - pub fn raw_graph_mut(&mut self) -> &mut DiGraph { - &mut self.graph - } } #[cfg(test)] @@ -430,7 +422,7 @@ mod test { let topo = topo.paths_graph(4); let has_edge = |asn1: u32, asn2: u32| { - topo.raw_graph() + topo.graph .find_edge(topo.index_of(asn1).unwrap(), topo.index_of(asn2).unwrap()) .is_some() }; @@ -446,7 +438,7 @@ mod test { assert!(has_edge(3, 5)); assert!(has_edge(3, 6)); - assert_eq!(topo.raw_graph().edge_count(), 7); - assert!(!is_cyclic_directed(topo.raw_graph())); + assert_eq!(topo.graph.edge_count(), 7); + assert!(!is_cyclic_directed(topo.graph)); } }