Skip to main content

flood

Function flood 

Source
pub fn flood<N: Clone + Eq + Hash, E>(
    starts: impl IntoIterator<Item = N>,
    take: Take,
    visit: impl FnMut(&N) -> Result<Vec<N>, E>,
) -> Result<Vec<N>, E>
Expand description

Visits starts and every node reachable from them, each once: visit is asked for each node in turn, and hands on its neighbours, in order; a node not handed on before joins the pending ones, and which of those comes next take says. Returns the nodes in the order visited.

The order is the starts’, visit’s and take’s alone: what has been handed on is only ever asked about, never iterated. A flood over finitely many nodes ends, whatever visit hands on. visit may keep state of its own (what it found, what it refused), since each node is visited once, in order.