Function cnetworks::bfs_many [−][src]
pub fn bfs_many(
net: &Network,
root: usize,
targets: &[usize]
) -> Result<Vec<(usize, Option<usize>)>, Err>
Expand description
Like bfs
, but with multiple targets.
Returns a vector of (target, distance) pairs in the order in which targets were encountered,
Err
if the root or any of the target nodes do not exist.
A distance of None
means the target was not enountered, such targets are pushed to the end of
the returned vector.
Panics
This function pancis when the queue operations fail.
Examples
let net = Network::new(100, Model::ER { p: 0.05, whole: false }, Weight::None);
for (target, distance) in bfs_many( &net, 1, &[2, 3])? {
match distance {
Some(distance) => println!("Distance from 1 to {} is {}", target, distance),
None => println!("Cannot reach {} from 1", target),
}
}