Struct dfir_lang::graph::DiMulGraph

source ·
pub struct DiMulGraph<V, E>
where V: Key, E: Key,
{ /* 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>
where V: Key, E: Key,

source

pub fn new() -> Self

Creates an empty DiMulGraph.

source

pub fn with_capacity(capacity: usize) -> Self

Creates a DiMulGraph with pre-allocated memory for capacity vertices and capacity edges.

source

pub fn assert_valid(&self)

Assert that self is in a consistent state, for debugging. This is computationally expensive for large graphs.

source

pub fn insert_edge(&mut self, src: V, dst: V) -> E

Creates an edge going from src to dst and returns the edge ID.

source

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.

source

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.

source

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.

source

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.

source

pub fn edge(&self, e: E) -> Option<(V, V)>

Get the source and destination vertex IDs for the given edge ID.

source

pub fn edge_ids(&self) -> Keys<'_, E, (V, V)>

Return an iterator over all edge IDs E.

source

pub fn edges( &self, ) -> impl '_ + ExactSizeIterator<Item = (E, (V, V))> + FusedIterator + Clone + Debug

Return an iterator over all edges in form (E, (V, V)).

source

pub fn successor_edges(&self, v: V) -> Copied<Iter<'_, E>>

Return an iterator of all edge IDs coming out of v.

source

pub fn predecessor_edges(&self, v: V) -> Copied<Iter<'_, E>>

Return an iterator of all edge IDs going into v.

source

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.

source

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.

source

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).

source

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).

source

pub fn degree_out(&self, v: V) -> usize

The degree (number of edges/vertices) coming out of v, i.e. the number of successors.

source

pub fn degree_in(&self, v: V) -> usize

The degree (number of edges/vertices) going into v, i.e. the number of predecessors.

Trait Implementations§

source§

impl<V, E> Clone for DiMulGraph<V, E>
where V: Key + Clone, E: Key + Clone,

source§

fn clone(&self) -> DiMulGraph<V, E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V, E> Debug for DiMulGraph<V, E>
where V: Key + Debug, E: Key + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<V, E> Default for DiMulGraph<V, E>
where V: Key, E: Key,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, V, E> Deserialize<'de> for DiMulGraph<V, E>
where V: Key + Deserialize<'de>, E: Key + Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<V, E> From<DiMulGraph<V, E>> for SlotMap<E, (V, V)>
where V: Key, E: Key,

source§

fn from(value: DiMulGraph<V, E>) -> Self

Converts to this type from the input type.
source§

impl<V, E> From<SlotMap<E, (V, V)>> for DiMulGraph<V, E>
where V: Key, E: Key,

source§

fn from(edges: SlotMap<E, (V, V)>) -> Self

Converts to this type from the input type.
source§

impl<V, E> Serialize for DiMulGraph<V, E>
where V: Key + Serialize, E: Key + Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<V, E> Freeze for DiMulGraph<V, E>

§

impl<V, E> RefUnwindSafe for DiMulGraph<V, E>

§

impl<V, E> Send for DiMulGraph<V, E>
where V: Send, E: Send,

§

impl<V, E> Sync for DiMulGraph<V, E>
where V: Sync, E: Sync,

§

impl<V, E> Unpin for DiMulGraph<V, E>
where V: Unpin, E: Unpin,

§

impl<V, E> UnwindSafe for DiMulGraph<V, E>
where V: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,