Skip to main content

dfs

Function dfs 

Source
pub fn dfs<T: Clone + Eq + Hash, U, F, G, E>(
    start: &T,
    visiteds: &mut HashSet<T>,
    data: &mut U,
    f: F,
    g: G,
) -> Result<DfsResult<T>, E>
where F: FnMut(&T, &mut U) -> Result<Vec<T>, E>, G: FnMut(&T, &mut U) -> Result<(), E>,
Expand description

This function is an implementation of DFS algorithm with a cycle detection.

A graph is depth-first searched by this function. This function returns a path with the cycle if this function detects a cycle in the graph, otherwise returns a success.