MCPcopy Create free account
hub / github.com/CodeSentryAI/lockbud / cycle_paths

Method cycle_paths

src/detector/lock/mod.rs:904–932  ·  view source on GitHub ↗

Find all the cycles in the graph.

(&self)

Source from the content-addressed store, hash-verified

902 let mut back_edges = Vec::new();
903 let nodes = self.graph.node_indices();
904 for start in nodes {
905 depth_first_search(&self.graph, Some(start), |event| {
906 match event {
907 DfsEvent::BackEdge(u, v) => {
908 if !back_edges.contains(&(u, v)) && !back_edges.contains(&(v, u)) {
909 back_edges.push((u, v));
910 }
911 }
912 DfsEvent::Finish(_, _) => {
913 return Control::Break(());
914 }
915 _ => {}
916 };
917 Control::Continue
918 });
919 }
920 back_edges
921 }
922
923 /// Find all the cycles in the graph.
924 fn cycle_paths(&self) -> Vec<Vec<RelationId>> {
925 let mut dedup = Vec::new();
926 let mut edge_sets = Vec::new();
927 for (src, target) in self.back_edges() {
928 // FIXME(boqin): all_simple_paths may return infinitely many paths. I think this is a bug in petgraph.
929 // The issue is tracked in https://github.com/petgraph/petgraph/issues/680.
930 // Before a patch is available, I limit the path number with MAX_PATH_NUM = 100. I think 100 is enough for most cases.
931 const MAX_PATH_NUM: usize = 100;
932 let cycle_paths =
933 algo::all_simple_paths::<Vec<_>, _>(&self.graph, target, src, 0, None)
934 .take(MAX_PATH_NUM)
935 .collect::<Vec<_>>();

Callers 1

detect_deadlockMethod · 0.80

Calls 1

back_edgesMethod · 0.80

Tested by

no test coverage detected