Skip to main content

shortest_path

Function shortest_path 

Source
pub fn shortest_path<F: Fs>(
    db: &GraphDb<F>,
    a: &str,
    b: &str,
    edge_types: &[&str],
    max_hops: usize,
) -> Vec<(String, String)>
Expand description

The shortest chain of edge_types edges from a to b, as (edge type, node reached) hops — so a two-hop answer is [(IMPORTS, x), (CO_CHANGED, b)] and a is the caller’s own starting point.

Edges are followed in both directions: a importing x and x importing a both say the two are connected, and a reader asking how two files relate does not care which way the arrow points. Empty when a and b are the same node, when either is unknown, or when no chain of at most max_hops reaches one from the other.

Deterministic: neighbours are visited in (key, edge type) order, so of several shortest paths the same one always comes back.