pub struct MultiGraph<N: Node, E: EdgeWeight, Ix: IndexType = u32> { /* private fields */ }
Expand description
A multi-graph structure that supports parallel edges
Unlike Graph, MultiGraph allows multiple edges between the same pair of nodes. This is useful for modeling scenarios where multiple connections of different types or weights can exist between nodes.
Implementations§
Source§impl<N: Node, E: EdgeWeight, Ix: IndexType> MultiGraph<N, E, Ix>
impl<N: Node, E: EdgeWeight, Ix: IndexType> MultiGraph<N, E, Ix>
Sourcepub fn add_edge(&mut self, source: N, target: N, weight: E) -> usize
pub fn add_edge(&mut self, source: N, target: N, weight: E) -> usize
Add an edge between two nodes with a given weight Returns the edge ID for reference
Sourcepub fn get_edges_between(&self, source: &N, target: &N) -> Vec<(usize, &E)>where
E: Clone,
pub fn get_edges_between(&self, source: &N, target: &N) -> Vec<(usize, &E)>where
E: Clone,
Get all parallel edges between two nodes
Sourcepub fn remove_edge(&mut self, edge_id: usize) -> Result<Edge<N, E>>
pub fn remove_edge(&mut self, edge_id: usize) -> Result<Edge<N, E>>
Remove an edge by its ID
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the graph
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges in the graph
Trait Implementations§
Auto Trait Implementations§
impl<N, E, Ix> Freeze for MultiGraph<N, E, Ix>
impl<N, E, Ix> RefUnwindSafe for MultiGraph<N, E, Ix>
impl<N, E, Ix> Send for MultiGraph<N, E, Ix>where
Ix: Send,
impl<N, E, Ix> Sync for MultiGraph<N, E, Ix>where
Ix: Sync,
impl<N, E, Ix> Unpin for MultiGraph<N, E, Ix>
impl<N, E, Ix> UnwindSafe for MultiGraph<N, E, Ix>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more