fn dfs_visit<F: Fn(&ModuleId) -> Vec<ModuleId>>(
            cursor_module: ModuleId,
            modules_discovered: &mut BTreeSet<ModuleId>,
            modules_finished: &mut BTreeSet<ModuleId>,
            immediate_module_dependencies: &F,
        ) -> bool {
            modules_discovered.insert(cursor_module.clone());
            for next_module in immediate_module_dependencies(&cursor_module) {
                if modules_finished.contains(&next_module) {
                    continue;
                }
                if modules_discovered.contains(&next_module)
                    || dfs_visit(
                        next_module,
                        modules_discovered,
                        modules_finished,
                        immediate_module_dependencies,
                    )
                {
                    return true;
                }
            }
            modules_discovered.remove(&cursor_module);
            modules_finished.insert(cursor_module);
            false
        }
// A variant of the three-color DFS, visit each node at max once.
// This function returns true if a back-edge is found during the DFS.
A variant of the three-color DFS, visit each node at max once.
This function returns true if a back-edge is found during the DFS.
A variant of the three - color DFS visit each node at max once . This function returns true if a back - edge is found during the DFS .
fn dfs_visit<F: Fn(&ModuleId) -> Vec<ModuleId>>(
            cursor_module: ModuleId,
            modules_discovered: &mut BTreeSet<ModuleId>,
            modules_finished: &mut BTreeSet<ModuleId>,
            immediate_module_dependencies: &F,
        ) -> bool {
            modules_discovered.insert(cursor_module.clone());
            for next_module in immediate_module_dependencies(&cursor_module) {
                if modules_finished.contains(&next_module) {
                    continue;
                }
                if modules_discovered.contains(&next_module)
                    || dfs_visit(
                        next_module,
                        modules_discovered,
                        modules_finished,
                        immediate_module_dependencies,
                    )
                {
                    return true;
                }
            }
            modules_discovered.remove(&cursor_module);
            modules_finished.insert(cursor_module);
            false
        }
fn dfs_visit < F : Fn ( & ModuleId ) -> Vec < ModuleId > > ( cursor_module : ModuleId , modules_discovered : & mut BTreeSet < ModuleId > , modules_finished : & mut BTreeSet < ModuleId > , immediate_module_dependencies : & F , ) -> bool { modules_discovered . insert ( cursor_module . clone ( ) ) ; for next_module in immediate_module_dependencies ( & cursor_module ) { if modules_finished . contains ( & next_module ) { continue ; } if modules_discovered . contains ( & next_module ) || dfs_visit ( next_module , modules_discovered , modules_finished , immediate_module_dependencies , ) { return true ; } } modules_discovered . remove ( & cursor_module ) ; modules_finished . insert ( cursor_module ) ; false }
A variant of the three-color DFS, visit each node at max once.
A variant of the three - color DFS visit each node at max once .
cursor_module
ModuleId
modules_discovered
&mut BTreeSet<ModuleId>
modules_finished
&mut BTreeSet<ModuleId>
immediate_module_dependencies
&F