bfs_distances

Function bfs_distances 

Source
pub fn bfs_distances<T, S>(
    graph: &S,
    start: usize,
    directed: bool,
) -> SparseResult<Array1<isize>>
where T: Float + Debug + Copy + 'static, S: SparseArray<T>,
Expand description

Compute distances from a source vertex using BFS

§Arguments

  • graph - The graph as a sparse matrix (unweighted)
  • start - Starting vertex
  • directed - Whether the graph is directed

§Returns

Array of distances from the start vertex to all other vertices

§Examples

use scirs2_sparse::csgraph::bfs_distances;
use scirs2_sparse::csr_array::CsrArray;

let rows = vec![0, 1, 1, 2];
let cols = vec![1, 0, 2, 1];
let data = vec![1.0, 1.0, 1.0, 1.0];
let graph = CsrArray::from_triplets(&rows, &cols, &data, (3, 3), false).unwrap();

let distances = bfs_distances(&graph, 0, false).unwrap();