Skip to content

Commit f7716ac

Browse files
committed
after running cargo fmt
1 parent f7f614f commit f7716ac

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

rustworkx-core/src/connectivity/minimum_cycle_basis.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::connectivity::conn_components::connected_components;
22
use crate::dictmap::*;
3+
use crate::shortest_path::dijkstra;
34
use crate::Result;
45
use hashbrown::{HashMap, HashSet};
56
use petgraph::algo::{astar, min_spanning_tree};
67
use petgraph::csr::IndexType;
7-
use crate::shortest_path::dijkstra;
88
use petgraph::data::{DataMap, Element};
99
use petgraph::graph::Graph;
1010
use petgraph::graph::NodeIndex;
@@ -35,20 +35,18 @@ impl EdgeWeightToNumber for i32 {
3535

3636
fn create_subgraphs_from_components<G>(
3737
graph: G,
38-
components: Vec<HashSet<G::NodeId>>
38+
components: Vec<HashSet<G::NodeId>>,
3939
) -> Vec<(Graph<G::NodeId, i32, Undirected>, HashMap<usize, NodeIndex>)>
4040
where
41-
G: IntoEdgeReferences
42-
+ NodeIndexable
43-
+ IntoNodeIdentifiers,
41+
G: IntoEdgeReferences + NodeIndexable + IntoNodeIdentifiers,
4442
G::NodeId: Eq + Hash,
4543
G::EdgeWeight: EdgeWeightToNumber,
4644
{
4745
components
4846
.into_iter()
4947
.map(|component| {
50-
let mut subgraph = Graph::<_ ,i32, Undirected>::default();
51-
let mut node_subnode_map:HashMap<usize, NodeIndex> = HashMap::new();
48+
let mut subgraph = Graph::<_, i32, Undirected>::default();
49+
let mut node_subnode_map: HashMap<usize, NodeIndex> = HashMap::new();
5250
for nodeid in graph.node_identifiers() {
5351
if component.contains(&nodeid) {
5452
let node = graph.to_index(nodeid);
@@ -66,7 +64,8 @@ where
6664
}
6765
}
6866
(subgraph, node_subnode_map)
69-
}).collect()
67+
})
68+
.collect()
7069
}
7170
pub fn minimum_cycle_basis<G, E>(graph: G) -> Result<Vec<Vec<NodeIndex>>, E>
7271
where
@@ -114,20 +113,23 @@ where
114113
.map(|(index, node_index)| (node_index, index))
115114
.collect();
116115
for edge in subgraph.edge_references() {
117-
sub_edges.push((
118-
node_map[&edge.source()],
119-
node_map[&edge.target()],
120-
));
116+
sub_edges.push((node_map[&edge.source()], node_map[&edge.target()]));
121117
}
122118
let mst = min_spanning_tree(&subgraph);
123-
let sub_mst_edges: Vec<_> = mst.filter_map(|element| {
124-
if let Element::Edge { source, target, weight: _ } = element {
125-
Some((source, target))
119+
let sub_mst_edges: Vec<_> = mst
120+
.filter_map(|element| {
121+
if let Element::Edge {
122+
source,
123+
target,
124+
weight: _,
125+
} = element
126+
{
127+
Some((source, target))
126128
} else {
127-
None
129+
None
128130
}
129-
})
130-
.collect();
131+
})
132+
.collect();
131133

132134
let mut chords: Vec<(usize, usize)> = Vec::new();
133135
for edge in sub_edges.iter() {
@@ -201,7 +203,7 @@ where
201203
fn _min_cycle<G, F, E>(
202204
subgraph: G,
203205
orth: HashSet<(usize, usize)>,
204-
mut weight_fn: F
206+
mut weight_fn: F,
205207
) -> Result<Vec<(usize, usize)>, E>
206208
where
207209
G: IntoNodeReferences + IntoEdgeReferences + DataMap + NodeIndexable,
@@ -243,11 +245,13 @@ where
243245
let mut shortest_path_map: HashMap<G::NodeId, i32> = HashMap::new();
244246
for nodeid in subgraph.node_identifiers() {
245247
let (node, lifted_node) = subgraph_gi_map[&nodeid];
246-
let result: Result<DictMap<NodeIndex, i32>> = dijkstra(&gi,
247-
node,
248-
Some(lifted_node),
248+
let result: Result<DictMap<NodeIndex, i32>> = dijkstra(
249+
&gi,
250+
node,
251+
Some(lifted_node),
249252
|e| Ok(*e.weight() as i32),
250-
None);
253+
None,
254+
);
251255
// Find the shortest distance in the result and store it in the shortest_path_map
252256
let spl = result.unwrap()[&lifted_node];
253257
shortest_path_map.insert(nodeid, spl);
@@ -301,16 +305,13 @@ where
301305
Ok(min_edgelist)
302306
}
303307

304-
305-
306308
#[cfg(test)]
307309
mod test_minimum_cycle_basis {
308310

309311
use crate::connectivity::minimum_cycle_basis::minimum_cycle_basis;
310312
use petgraph::graph::{Graph, NodeIndex};
311313
use petgraph::Undirected;
312314

313-
314315
#[test]
315316
fn test_empty_graph() {
316317
let graph: Graph<String, i32> = Graph::new();

src/connectivity/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use super::{
2222

2323
use hashbrown::{HashMap, HashSet};
2424

25-
use petgraph::algo;
2625
use petgraph::stable_graph::NodeIndex;
2726
use petgraph::unionfind::UnionFind;
2827
use petgraph::visit::{EdgeRef, IntoEdgeReferences, NodeCount, NodeIndexable, Visitable};
28+
use petgraph::{algo, Graph};
2929
use pyo3::exceptions::PyValueError;
3030
use pyo3::prelude::*;
3131
use pyo3::types::PyDict;

0 commit comments

Comments
 (0)