Trait graph::graph_ops::RelabelByDegreeOp [−][src]
pub trait RelabelByDegreeOp<Node: Idx> {
fn to_degree_ordered(&self) -> Self;
}
Required methods
fn to_degree_ordered(&self) -> Self
fn to_degree_ordered(&self) -> Self
Creates a new graph by relabeling the node ids of the given graph.
Ids are relabaled using descending degree-order, i.e., given n
nodes,
the node with the largest degree will become node id 0
, the node with
the smallest degree will become node id n - 1
.
Note, that this method creates a new graph with the same space requirements as the input graph.
Example
use graph::prelude::*;
let graph: UndirectedCsrGraph<u32> = GraphBuilder::new()
.edges(vec![(0, 1), (1, 2), (1, 3), (3, 0)])
.build();
assert_eq!(graph.degree(0), 2);
assert_eq!(graph.degree(1), 3);
assert_eq!(graph.degree(2), 1);
assert_eq!(graph.degree(3), 2);
assert_eq!(graph.neighbors(0), &[1, 3]);
let graph = graph.to_degree_ordered();
assert_eq!(graph.degree(0), 3);
assert_eq!(graph.degree(1), 2);
assert_eq!(graph.degree(2), 2);
assert_eq!(graph.degree(3), 1);
assert_eq!(graph.neighbors(0), &[1, 2, 3]);