Struct dfir_lang::graph::DiMulGraph
source · pub struct DiMulGraph<V, E>{ /* private fields */ }
Expand description
A directed multigraph where an vertex’s inbound and outbound edges are indexed.
DiMulGraph
does not allocate vertices V
. The user shall use an external
SlotMap<V, _>
for allocating vertices, which also allows the user to associate data with
each vertex.
DiMulGraph
does allocate edges E
as they are added. Additional data can be associated
with edges via an external SecondaryMap<E, _>
.
Implementations§
source§impl<V, E> DiMulGraph<V, E>
impl<V, E> DiMulGraph<V, E>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a DiMulGraph
with pre-allocated memory for capacity
vertices and capacity
edges.
sourcepub fn assert_valid(&self)
pub fn assert_valid(&self)
Assert that self
is in a consistent state, for debugging. This is computationally
expensive for large graphs.
sourcepub fn insert_edge(&mut self, src: V, dst: V) -> E
pub fn insert_edge(&mut self, src: V, dst: V) -> E
Creates an edge going from src
to dst
and returns the edge ID.
sourcepub fn insert_intermediate_vertex(
&mut self,
new_vertex: V,
edge: E,
) -> Option<(E, E)>
pub fn insert_intermediate_vertex( &mut self, new_vertex: V, edge: E, ) -> Option<(E, E)>
For an edge
from A --> B
, insert a new vertex V
along that edge to create
A --e0--> V --e1--> B
. Returns the pair of new edge IDs in and out of V
, i.e.
(e0, e1)
.
Returns None
if the edge doesn’t exist.
edge
is removed from the graph, both returned edge IDs are new.
sourcepub fn remove_intermediate_vertex(&mut self, vertex: V) -> Option<(E, (E, E))>
pub fn remove_intermediate_vertex(&mut self, vertex: V) -> Option<(E, (E, E))>
For a vertex with one incoming edge and one outgoing edge, removes the vertex. Inserts a new edge.
Returns (new edge, (old edge in, old edge out))
.
Returns None
if vertex
is not in the graph or does not have the right degree in/out.
sourcepub fn remove_edge(&mut self, e: E) -> Option<(V, V)>
pub fn remove_edge(&mut self, e: E) -> Option<(V, V)>
Remove an edge from the graph. If the edgeId is found then the edge is removed from the graph and returned. If the edgeId was not found in the graph then nothing is returned and nothing is done.
sourcepub fn remove_vertex(&mut self, v: V)
pub fn remove_vertex(&mut self, v: V)
Remove a vertex from the graph, it must have no edges to or from it when doing this.
sourcepub fn edge(&self, e: E) -> Option<(V, V)>
pub fn edge(&self, e: E) -> Option<(V, V)>
Get the source and destination vertex IDs for the given edge ID.
sourcepub fn edges(
&self,
) -> impl '_ + ExactSizeIterator<Item = (E, (V, V))> + FusedIterator + Clone + Debug
pub fn edges( &self, ) -> impl '_ + ExactSizeIterator<Item = (E, (V, V))> + FusedIterator + Clone + Debug
Return an iterator over all edges in form (E, (V, V))
.
sourcepub fn successor_edges(&self, v: V) -> Copied<Iter<'_, E>>
pub fn successor_edges(&self, v: V) -> Copied<Iter<'_, E>>
Return an iterator of all edge IDs coming out of v
.
sourcepub fn predecessor_edges(&self, v: V) -> Copied<Iter<'_, E>>
pub fn predecessor_edges(&self, v: V) -> Copied<Iter<'_, E>>
Return an iterator of all edge IDs going into v
.
sourcepub fn successor_vertices(
&self,
v: V,
) -> impl '_ + DoubleEndedIterator<Item = V> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn successor_vertices( &self, v: V, ) -> impl '_ + DoubleEndedIterator<Item = V> + ExactSizeIterator + FusedIterator + Clone + Debug
Return an iterator of all successor vertex IDs of v
.
sourcepub fn predecessor_vertices(
&self,
v: V,
) -> impl '_ + DoubleEndedIterator<Item = V> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn predecessor_vertices( &self, v: V, ) -> impl '_ + DoubleEndedIterator<Item = V> + ExactSizeIterator + FusedIterator + Clone + Debug
Return an iterator of all predecessor vertex IDs of v
.
sourcepub fn successors(
&self,
v: V,
) -> impl '_ + DoubleEndedIterator<Item = (E, V)> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn successors( &self, v: V, ) -> impl '_ + DoubleEndedIterator<Item = (E, V)> + ExactSizeIterator + FusedIterator + Clone + Debug
Return an iterator of all successor edge IDs and vertex IDs of v
in form (E, V)
.
sourcepub fn predecessors(
&self,
v: V,
) -> impl '_ + DoubleEndedIterator<Item = (E, V)> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn predecessors( &self, v: V, ) -> impl '_ + DoubleEndedIterator<Item = (E, V)> + ExactSizeIterator + FusedIterator + Clone + Debug
Return an iterator of all predecessor edge IDs and vertex IDs of v
in form (E, V)
.
sourcepub fn degree_out(&self, v: V) -> usize
pub fn degree_out(&self, v: V) -> usize
The degree (number of edges/vertices) coming out of v
, i.e. the number of successors.
Trait Implementations§
source§impl<V, E> Clone for DiMulGraph<V, E>
impl<V, E> Clone for DiMulGraph<V, E>
source§fn clone(&self) -> DiMulGraph<V, E>
fn clone(&self) -> DiMulGraph<V, E>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<V, E> Debug for DiMulGraph<V, E>
impl<V, E> Debug for DiMulGraph<V, E>
source§impl<V, E> Default for DiMulGraph<V, E>
impl<V, E> Default for DiMulGraph<V, E>
source§impl<'de, V, E> Deserialize<'de> for DiMulGraph<V, E>
impl<'de, V, E> Deserialize<'de> for DiMulGraph<V, E>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<V, E> From<DiMulGraph<V, E>> for SlotMap<E, (V, V)>
impl<V, E> From<DiMulGraph<V, E>> for SlotMap<E, (V, V)>
source§fn from(value: DiMulGraph<V, E>) -> Self
fn from(value: DiMulGraph<V, E>) -> Self
Auto Trait Implementations§
impl<V, E> Freeze for DiMulGraph<V, E>
impl<V, E> RefUnwindSafe for DiMulGraph<V, E>where
V: RefUnwindSafe,
E: RefUnwindSafe,
impl<V, E> Send for DiMulGraph<V, E>
impl<V, E> Sync for DiMulGraph<V, E>
impl<V, E> Unpin for DiMulGraph<V, E>
impl<V, E> UnwindSafe for DiMulGraph<V, E>where
V: UnwindSafe,
E: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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>
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>
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