Struct UnweightedAdjacencyList

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

An unweighted graph represented by an unweighted adjacency list. This is in principle the same as WeightedAdjacencyList, except that no weights are involved and thus a simple usize is able to represent an outgoing edge.

Implementations§

Source§

impl UnweightedAdjacencyList

Source

pub fn bfs(&self, start: usize) -> BfsResult

Perform a breadth first search on a graph a starting node start.

Source§

impl UnweightedAdjacencyList

Source

pub fn dfs_recursive(&self, start: usize) -> usize

Source§

impl UnweightedAdjacencyList

Source

pub fn eulerian_path(&self) -> Result<Vec<usize>, EulerianPathError>

Returns a list of edge_count + 1 node ids that give the Eulerian path or an EulerianPathError if no path exists or the graph is disconnected.

Source§

impl UnweightedAdjacencyList

Source

pub fn scc(&self) -> SccResult

Source§

impl UnweightedAdjacencyList

Source

pub fn center(&self) -> Center

Finds the center(s) of an undirected tree. The adjacency list must be build with undirected edges, and does not contain cycles, so that it qualifies the definition for a tree.

Source§

impl UnweightedAdjacencyList

Source§

impl UnweightedAdjacencyList

Source

pub fn with_size(n: usize) -> Self

Initialize an empty adjacency list that can hold up to n nodes.

Source

pub fn is_empty(&self) -> bool

Source

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

Add a directed edge from node u to node v

Source

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

Add an undirected edge between nodes u and v.

Source

pub fn new_directed(size: usize, edges: &[[usize; 2]]) -> Self

Source

pub fn new_undirected(size: usize, edges: &[[usize; 2]]) -> Self

Source

pub fn edges(&self) -> impl Iterator<Item = [usize; 2]> + '_

Iterates over all edges in the gragh. Each item is an array of length 2, showing the source and destination of this edge.

Source

pub fn edge_count(&self) -> usize

Number of edges in the graph

Source

pub fn nodes(&self) -> impl Iterator<Item = (usize, &Vec<usize>)>

Iterates over all nodes in the graph. Each item is a tuple of the node id and a Vec of all its outgoing edges

Source

pub fn node_count(&self) -> usize

Number of nodes (vertices) in the graph

Trait Implementations§

Source§

impl BfsReconstructPath for UnweightedAdjacencyList

Source§

fn bfs<T: Queue<usize>>(&self, start: usize) -> Vec<Option<usize>>

Perform a breadth first search on a graph a starting node start.

Source§

fn reconstruct_path<T: Queue<usize>>( &self, start: usize, end: usize, ) -> Vec<usize>

Source§

impl Debug for UnweightedAdjacencyList

Source§

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

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

impl Index<usize> for UnweightedAdjacencyList

Allows the outgoing edges of a node to be accessed easily.

Source§

type Output = Vec<usize>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. 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> 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.