MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / nonrecursive_dft_mut

Function nonrecursive_dft_mut

src/ore/src/graph.rs:178–204  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

176
177/// Same as [`nonrecursive_dft`], but allows changes to be made to the graph.
178pub 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`.
207fn entered_node<NodeId>(

Callers

nothing calls this directly

Calls 6

entered_nodeFunction · 0.85
find_next_child_to_enterFunction · 0.85
unwrapMethod · 0.80
is_emptyMethod · 0.45
popMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected