Skip to main content

reverse_edges

Function reverse_edges 

Source
pub fn reverse_edges(graph: &Graph, eids: &[u32]) -> IgraphResult<Graph>
Expand description

Returns a new graph with only the specified edges reversed.

For directed graphs, each edge in eids has its direction flipped ((u, v) becomes (v, u)). Edges not listed remain unchanged. For undirected graphs, this is a no-op (returns a structural copy).

Duplicate edge IDs in eids are silently ignored (double-reversing a single edge still results in one reversal).

§Errors

Returns InvalidArgument if any edge ID in eids is out of range.

§Examples

use rust_igraph::{Graph, reverse_edges};

let mut g = Graph::new(3, true).unwrap();
g.add_edge(0, 1).unwrap(); // eid 0
g.add_edge(1, 2).unwrap(); // eid 1

// Reverse only edge 0
let rev = reverse_edges(&g, &[0]).unwrap();
assert_eq!(rev.edge(0).unwrap(), (1, 0)); // reversed
assert_eq!(rev.edge(1).unwrap(), (1, 2)); // unchanged