Skip to main content

DynamicGraph

Struct DynamicGraph 

Source
pub struct DynamicGraph { /* private fields */ }
Expand description

Mutable directed graph with incremental add/remove and a reverse index.

Implementations§

Source§

impl DynamicGraph

Source

pub fn new(n: usize) -> Self

Create an edgeless dynamic graph on n vertices.

Source

pub fn from_adjacency_list(g: &AdjacencyList) -> GraphalgResult<Self>

Build a dynamic graph from a static AdjacencyList (directed).

Parallel edges in the source list increment the multiplicity.

Source

pub fn num_nodes(&self) -> usize

Number of vertices.

Source

pub fn num_distinct_edges(&self) -> usize

Number of distinct directed edges (ignoring multiplicity).

Source

pub fn num_edges(&self) -> usize

Total number of directed edges counting multiplicity.

Source

pub fn out_neighbors(&self, u: usize) -> GraphalgResult<&[usize]>

Out-neighbours of u (distinct, unsorted).

Source

pub fn in_neighbors(&self, u: usize) -> GraphalgResult<&[usize]>

In-neighbours of u (distinct, unsorted).

Source

pub fn out_degree(&self, u: usize) -> GraphalgResult<usize>

Out-degree of u counting multiplicity.

Source

pub fn edge_multiplicity(&self, u: usize, v: usize) -> u32

Multiplicity of the ordered pair (u, v) (zero if absent).

Source

pub fn has_edge(&self, u: usize, v: usize) -> bool

Whether the directed edge u -> v is present.

Source

pub fn add_edge(&mut self, u: usize, v: usize) -> GraphalgResult<bool>

Insert a directed edge u -> v, incrementing multiplicity.

Returns true if this introduced a new distinct edge (the pair was not previously present), false if it only bumped an existing multiplicity.

Source

pub fn remove_edge(&mut self, u: usize, v: usize) -> GraphalgResult<bool>

Remove one unit of multiplicity from the directed edge u -> v.

Returns true if the distinct edge was fully removed (multiplicity hit zero), false if it merely decremented. Errors with GraphalgError::NoSolution when the edge is absent.

Source

pub fn to_adjacency_list(&self) -> AdjacencyList

Materialise the current state as a static AdjacencyList, expanding each pair to its multiplicity (so parallel edges reappear).

Trait Implementations§

Source§

impl Clone for DynamicGraph

Source§

fn clone(&self) -> DynamicGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DynamicGraph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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.