Same as [`nonrecursive_dft`], but allows changes to be made to the graph.
(
graph: &mut Graph,
root: NodeId,
at_enter: &mut AtEnter,
at_exit: &mut AtExit,
)
| 176 | |
| 177 | /// Same as [`nonrecursive_dft`], but allows changes to be made to the graph. |
| 178 | pub fn nonrecursive_dft_mut<Graph, NodeId, AtEnter, AtExit>( |
| 179 | graph: &mut Graph, |
| 180 | root: NodeId, |
| 181 | at_enter: &mut AtEnter, |
| 182 | at_exit: &mut AtExit, |
| 183 | ) where |
| 184 | NodeId: std::cmp::Ord + Clone, |
| 185 | AtEnter: FnMut(&mut Graph, &NodeId) -> Vec<NodeId>, |
| 186 | AtExit: FnMut(&mut Graph, &NodeId) -> (), |
| 187 | { |
| 188 | // Code in this method is identical to the code in `nonrecursive_dft`. |
| 189 | let mut entered = Vec::new(); |
| 190 | let mut exited = BTreeSet::new(); |
| 191 | |
| 192 | let children = at_enter(graph, &root); |
| 193 | entered_node(&mut entered, root, children); |
| 194 | while !entered.is_empty() { |
| 195 | if let Some(to_enter) = find_next_child_to_enter(&mut entered, &exited) { |
| 196 | let children = at_enter(graph, &to_enter); |
| 197 | entered_node(&mut entered, to_enter, children); |
| 198 | } else { |
| 199 | let (to_exit, _) = entered.pop().unwrap(); |
| 200 | at_exit(graph, &to_exit); |
| 201 | exited.insert(to_exit); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | /// Add to `entered` that we have entered `node` and `node` has `children`. |
| 207 | fn entered_node<NodeId>( |
nothing calls this directly
no test coverage detected