Function isolates

Source
pub fn isolates<G>(graph: G) -> Vec<G::NodeId>
Expand description

Return the isolates in a graph object

An isolate is a node without any neighbors meaning it has a degree of 0. For directed graphs this means the in-degree and out-degree are both 0.

Arguments:

  • graph - The graph in which to find the isolates.

ยงExample

use petgraph::prelude::*;
use rustworkx_core::connectivity::isolates;

let edge_list = vec![
    (0, 1),
    (3, 0),
    (0, 5),
    (8, 0),
    (1, 2),
    (1, 6),
    (2, 3),
    (3, 4),
    (4, 5),
    (6, 7),
    (7, 8),
    (8, 9),
];
let mut graph = DiGraph::<i32, i32>::from_edges(&edge_list);
graph.add_node(10);
graph.add_node(11);
let res: Vec<usize> = isolates(&graph).into_iter().map(|x| x.index()).collect();
assert_eq!(res, [10, 11])