pub fn core_number<G>(graph: G) -> DictMap<G::NodeId, usize>
Expand description
Return the core number for each node in the graph.
A k-core is a maximal subgraph that contains nodes of degree k or more.
The function implicitly assumes that there are no parallel edges or self loops. It may produce incorrect/unexpected results if the input graph has self loops or parallel edges.
Arguments:
graph
- The graph in which to find the core numbers.
ยงExample
use petgraph::prelude::*;
use rustworkx_core::connectivity::core_number;
let edge_list = vec![(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)];
let graph = DiGraph::<i32, i32>::from_edges(&edge_list);
let res: Vec<(usize, usize)> = core_number(graph)
.iter()
.map(|(k, v)| (k.index(), *v))
.collect();
assert_eq!(res, vec![(0, 3), (1, 3), (2, 3), (3, 3)]);