Struct Graph

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

A compact graph representation. Edges are numbered in order of insertion. Each adjacency list consists of all edges pointing out from a given vertex.

Implementations§

Source§

impl Graph

Source

pub fn euler_path(&self, u: usize) -> Vec<usize>

Finds the sequence of edges in an Euler path starting from u, assuming it exists and that the graph is directed. Undefined behavior if this precondition is violated. To extend this to undirected graphs, maintain a visited array to skip the reverse edge.

Source

pub fn min_spanning_tree(&self, weights: &[i64]) -> Vec<usize>

Kruskal’s minimum spanning tree algorithm on an undirected graph.

Source

pub fn dijkstra(&self, weights: &[u64], u: usize) -> Vec<u64>

Source

pub fn dfs(&self, root: usize) -> DfsIterator<'_>

Source§

impl Graph

Source

pub fn new(vmax: usize, emax_hint: usize) -> Self

Initializes a graph with vmax vertices and no edges. To reduce unnecessary allocations, emax_hint should be close to the number of edges that will be inserted.

Source

pub fn num_v(&self) -> usize

Returns the number of vertices.

Source

pub fn num_e(&self) -> usize

Returns the number of edges, double-counting undirected edges.

Source

pub fn add_edge(&mut self, u: usize, v: usize)

Adds a directed edge from u to v.

Source

pub fn add_undirected_edge(&mut self, u: usize, v: usize)

An undirected edge is two directed edges. If edges are added only via this funcion, the reverse of any edge e can be found at e^1.

Source

pub fn add_two_sat_clause(&mut self, u: usize, v: usize)

If we think of each even-numbered vertex as a variable, and its odd-numbered successor as its negation, then we can build the implication graph corresponding to any 2-CNF formula. Note that u||v == !u -> v == !v -> u.

Source

pub fn adj_list(&self, u: usize) -> AdjListIterator<'_>

Gets vertex u’s adjacency list.

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

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