pub fn descendants<G>(
graph: G,
node: G::NodeId,
) -> impl Iterator<Item = G::NodeId>Expand description
Return the descendants of a node in a graph.
node is included in the output.
§Arguments:
node- The node to find the ancestors of
§Returns
An iterator where each item is a node id for an ancestor of node.
This includes node in the returned ids.
§Example
use rustworkx_core::traversal::descendants;
use rustworkx_core::petgraph::stable_graph::{StableDiGraph, NodeIndex};
let graph: StableDiGraph<(), ()> = StableDiGraph::from_edges(&[
(0, 1), (1, 2), (1, 3), (2, 4), (3, 4), (4, 5)
]);
let descendants: Vec<usize> = descendants(&graph, NodeIndex::new(3)).map(|x| x.index()).collect();
assert_eq!(vec![3_usize, 4, 5], descendants);