Skip to content

Commit

Permalink
make topo.graph pub
Browse files Browse the repository at this point in the history
  • Loading branch information
digizeph committed Jan 17, 2024
1 parent 135e6cd commit 8c110e0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/all_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/all_paths_between_two_ases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
let ut_path = topo.paths_graph(university_of_twente_asn);

let paths = all_simple_paths::<Vec<_>, _>(
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,
Expand Down
4 changes: 2 additions & 2 deletions examples/draw_path_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/
}
2 changes: 1 addition & 1 deletion examples/read_caida_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
2 changes: 1 addition & 1 deletion examples/shortest_path_between_two_ases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 4 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Default for RelType {
}

pub struct Topology {
graph: DiGraph<u32, RelType>,
pub graph: DiGraph<u32, RelType>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -300,14 +300,6 @@ impl Topology {
// assert!(!is_cyclic_directed(&graph));
Topology { graph }
}

pub fn raw_graph(&self) -> &DiGraph<u32, RelType> {
&self.graph
}

pub fn raw_graph_mut(&mut self) -> &mut DiGraph<u32, RelType> {
&mut self.graph
}
}

#[cfg(test)]
Expand Down Expand Up @@ -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()
};
Expand All @@ -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));
}
}

0 comments on commit 8c110e0

Please sign in to comment.