Skip to main content

Graph

Struct Graph 

Source
pub struct Graph<F: SemiflowFloat = f64> { /* private fields */ }
Expand description

Frozen sparse weighted graph in symmetric CSR layout. See ADR-0048.

Immutable post-construction — no mutator methods. Invariants I1–I7 hold.

Implementations§

Source§

impl<F: SemiflowFloat> Graph<F>

Source

pub fn n_nodes(&self) -> usize

Number of nodes. O(1).

Source

pub fn n_directed_edges(&self) -> usize

Number of directed edge-entries stored (= 2 · undirected_edges).

Source

pub fn row_ptr(&self) -> &[usize]

Row-pointer slice. Length n_nodes + 1.

Source

pub fn col_idx(&self) -> &[u32]

Column-index slice (neighbour node ids).

Source

pub fn vals(&self) -> &[F]

Edge-weight slice (same length as col_idx).

Source

pub fn path(n: usize) -> Self

Path graph 0 — 1 — 2 — … — (n − 1) with unit edge weights.

§Panics

Panics if n == 0.

Source

pub fn cycle(n: usize) -> Self

Cycle graph: path graph plus edge (n − 1) — 0, all unit weights.

§Panics

Panics if n < 3 (cycle on 1 or 2 nodes is degenerate).

Source

pub fn from_edges( n_nodes: usize, edges: impl IntoIterator<Item = (u32, u32, F)>, ) -> Result<Self, SemiflowError>

Build from an iterator of undirected edges (u, v, w).

§Errors

SemiflowError::DomainViolation: self-loop, node out of range, bad weight, duplicate edge, or a weighted degree dᵢ that overflows to ∞ (it is the combinatorial Laplacian’s diagonal entry).

Source

pub fn erdos_renyi(n_nodes: usize, p: f64, seed: u64) -> Self

Erdős–Rényi G(n_nodes, p) with seeded splitmix64 RNG. All weights = 1.

Auto Trait Implementations§

§

impl<F> Freeze for Graph<F>
where Vec<F>: Freeze,

§

impl<F> RefUnwindSafe for Graph<F>
where Vec<F>: RefUnwindSafe,

§

impl<F> Send for Graph<F>
where Vec<F>: Send,

§

impl<F> Sync for Graph<F>
where Vec<F>: Sync,

§

impl<F> Unpin for Graph<F>
where Vec<F>: Unpin,

§

impl<F> UnsafeUnpin for Graph<F>
where Vec<F>: UnsafeUnpin,

§

impl<F> UnwindSafe for Graph<F>
where Vec<F>: 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.