[][src]Function rs_graph::search::bfs::start_with_data

Important traits for BFS<'a, A, S, Q>
pub fn start_with_data<'a, A, S, Q>(
    adj: A,
    src: A::Node,
    data: (S, Q)
) -> BFS<'a, A, S, Q> where
    A: Adjacencies<'a>,
    S: ItemMap<A::Node, A::Edge>,
    Q: ItemQueue<A::Node>, 

Start and return a BFS iterator with user defined data structures.

The returned iterator traverses the edges in breadth-first order. The iterator returns the next node and its incoming edge.

Note that the start node is not returned by the iterator.

The algorithm requires a pair (M, Q) with M implementing ItemMap<Node, Edge>, and Q implementing ItemQueue<Node> as internal data structures. The map is used to store the last edge of the path from the source to each reachable node. The queue is used to handle the nodes in breadth-first order. The data structures can be reused for multiple searches.

Parameter

  • adj: adjacency information for the graph
  • src: the source node at which the search should start.
  • data: the data structures used in the algorithm

Example

use rs_graph::LinkedListGraph;
use rs_graph::traits::*;
use rs_graph::classes;
use rs_graph::search::bfs;
use std::collections::{HashMap, VecDeque};

let g: LinkedListGraph = classes::peterson();
let mut cnt = 0;
for (u, e) in bfs::start_with_data(g.neighbors(), g.id2node(0),
                                   (HashMap::new(), VecDeque::new()))
{
    assert_ne!(g.node_id(u), 0);
    cnt += 1;
}
assert_eq!(cnt, g.num_nodes() - 1);