Method
dfs
(&mut self, g: &dyn IGraph, v: usize, u: usize)
Source from the content-addressed store, hash-verified
| 45 | |
| 46 | impl Cycle { |
| 47 | fn dfs(&mut self, g: &dyn IGraph, v: usize, u: usize) { |
| 48 | self.marked[v] = true; |
| 49 | for &w in g.adj(v) { |
| 50 | // short circuit if cycle already found |
| 51 | if self.cycle.is_some() { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if !self.marked[w] { |
| 56 | self.edge_to[w] = v; |
| 57 | self.dfs(g, w, v); |
| 58 | } else if w != u { |
| 59 | let mut cycle = Stack::default(); |
| 60 | let mut x = v; |
| 61 | while x != w { |
| 62 | cycle.push(x); |
| 63 | x = self.edge_to[x]; |
| 64 | } |
| 65 | cycle.push(w); |
| 66 | cycle.push(v); |
| 67 | self.cycle = Some(cycle); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // does this graph have two parallel edges? |
| 73 | fn has_parallel_edges(&mut self, graph: &dyn IGraph) -> bool { |
Tested by
no test coverage detected