shortest_path_length

Function shortest_path_length 

Source
pub fn shortest_path_length<T>(
    graph: &Graph<T>,
    source: usize,
    target: usize,
) -> Option<usize>
Expand description

Returns the length of the shortest path between two nodes in the graph.

ยงExamples

use zrx_graph::algorithm::shortest_path_length;
use zrx_graph::Graph;

// Create graph builder and add nodes
let mut builder = Graph::builder();
let a = builder.add_node("a");
let b = builder.add_node("b");
let c = builder.add_node("c");

// Create edges between nodes
builder.add_edge(a, b, 0)?;
builder.add_edge(b, c, 0)?;
builder.add_edge(a, c, 0)?;

// Create graph from builder
let graph = builder.build();

// Obtain shortest path length
let len = shortest_path_length(&graph, a, c);
assert_eq!(len, Some(1));