Function graphalgs::spec::prufer_code
source · pub fn prufer_code<G>(graph: G) -> Vec<G::NodeId>where
G: IntoEdges + IntoNodeIdentifiers + NodeCount + NodeIndexable + IntoNeighbors,
Expand description
Generate the prufer code for a given tree.
Before calling this function, make sure that the graph being called is indeed a tree, otherwise stack overflow is possible.
Example
use graphalgs::spec::prufer_code;
use petgraph::graph::UnGraph;
use petgraph::visit::NodeIndexable;
let tree = UnGraph::<u8, ()>::from_edges(&[(0, 3), (0, 5), (3, 4), (3, 1), (3, 2)]);
// tree:
//
// 4
// |
// 5-0-3-1
// |
// 2
let ix = |i| tree.from_index(i);
assert_eq!(prufer_code(&tree), vec![ix(3), ix(3), ix(3), ix(0)]);