Function cnetworks::bfs [−][src]
pub fn bfs(
net: &Network,
root: usize,
target: usize
) -> Result<Option<HashSet<usize>>, Error>
Expand description
Perform a breadth-first search over the network, starting with root and looking for target.
Return a HashSet of all nodes discovered in the process or None
if the path is not found.
Returns Err
if the root or target nodes do not exist. Panics if the network is corrupted or
when the queue operations fail.
Examples
use cnetworks::*; let net = Network::new(100, Model::ER { p: 0.05, whole: false }, Weight::Constant { c: 1.0}); match bfs(&net, 1, 3).expect("Node 1 or 3 does not exist") { Some(n) => println!("Found 3 after discovering {:?}", n), None => println!("No path to 3 found!"), }