[−][src]Function rs_graph::algorithms::complement
pub fn complement<'g, 'h, G, H>(g: &'g G) -> H where
G: IndexGraph<'g>,
H: Graph<'h> + Buildable,
Returns the complement of g
.
Example
use rs_graph::LinkedListGraph; use rs_graph::traits::{Undirected, IndexGraph, GraphSize}; use rs_graph::algorithms::complement; use rs_graph::classes::cycle; use std::cmp::{min, max}; let g: LinkedListGraph = cycle(5); let h: LinkedListGraph = complement(&g); assert_eq!(h.num_nodes(), 5); assert_eq!(h.num_edges(), 5); let mut edges: Vec<_> = h.edges().map(|e| { let (u, v) = h.enodes(e); let (u, v) = (h.node_id(u), h.node_id(v)); (min(u,v), max(u,v)) }).collect(); edges.sort(); assert_eq!(edges, vec![(0,2), (0,3), (1,3), (1,4), (2,4)]);
Note that this function assumes that g
is a simple graph (no
loops or double edges). It will work on multi-graphs, too, but
only adjacencies are respected, no multiplicities.