Skip to main content

create

Function create 

Source
pub fn create(
    edges: &[(u32, u32)],
    n: u32,
    directed: bool,
) -> IgraphResult<Graph>
Expand description

Build a graph from a flat edge list.

edges is a slice of (source, target) pairs interpreted under directed. If n == 0 the vertex count is inferred from the largest endpoint (max + 1). If n > 0 but smaller than max + 1, the vertex count is silently raised to max + 1 (matches upstream igraph_create which calls igraph_add_vertices to extend).

§Errors

  • IgraphError::InvalidArgument — if the implied vertex count would overflow u32 (only possible when the maximum edge endpoint is u32::MAX).

§Examples

use rust_igraph::create;

// n = 0 infers vcount from the edges.
let g = create(&[(0, 1), (1, 2), (2, 3)], 0, false).unwrap();
assert_eq!((g.vcount(), g.ecount()), (4, 3));

// n > max+1 keeps the requested vertex count.
let h = create(&[(0, 1)], 5, false).unwrap();
assert_eq!((h.vcount(), h.ecount()), (5, 1));

// Directed graphs preserve arc orientation.
let d = create(&[(0, 1), (1, 0)], 2, true).unwrap();
assert_eq!((d.vcount(), d.ecount()), (2, 2));