[][src]Struct algorithms_edu::algo::graph::WeightedAdjacencyList

pub struct WeightedAdjacencyList { /* fields omitted */ }

A graph represented by a weighted adjacency list. Under the hood, a weighted adjacency list is a Vec of Vec of Edges. For an adjacency list g, g[i] is a Vec of edges pointing from i to other nodes (vertices). Thus, the number of nodes is implied by the len of the (outer) Vec. For each node i that do not have outgoing edges, g[i] is an empty vector.

Implementations

impl WeightedAdjacencyList[src]

impl WeightedAdjacencyList[src]

pub fn dfs(&self, start: usize) -> usize[src]

Perform a depth first search on a graph with n nodes from a starting point to count the number of nodes in a given component.

In this particular implementation we just increment a counter each time we visit a new node. This, by itself, is not of much use, but you'll soon see that many other advanced algorithms are based on this DFS prototype.

impl WeightedAdjacencyList[src]

impl WeightedAdjacencyList[src]

impl WeightedAdjacencyList[src]

pub fn bellman_ford(&self, start: usize) -> Vec<f64>[src]

impl WeightedAdjacencyList[src]

pub fn dijkstra(&self, start: usize, end: usize) -> Option<(f64, Vec<usize>)>[src]

impl WeightedAdjacencyList[src]

pub fn toposort(&self) -> Vec<usize>[src]

pub fn toposort_khan(&self) -> Vec<usize>[src]

Imagine building a program with dependencies

pub fn dag_shortest_path(&self, start: usize) -> Vec<f64>[src]

impl WeightedAdjacencyList[src]

pub fn with_size(n: usize) -> Self[src]

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

pub fn is_empty(&self) -> bool[src]

Is the graph devoid of vertices?

pub fn add_directed_edge(&mut self, u: usize, v: usize, weight: f64)[src]

Add a directed edge from node u to node v with weight weight.

pub fn add_undirected_edge(&mut self, u: usize, v: usize, weight: f64)[src]

Add an undirected edge between nodes u and v.

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

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

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

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

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

Iterates over all edges in the gragh. Each item is a tuples of 3: (from, to, weight)

pub fn edge_count(&self) -> usize[src]

Number of edges in the graph

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

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

pub fn node_count(&self) -> usize[src]

Number of nodes (vertices) in the graph

Trait Implementations

impl Debug for WeightedAdjacencyList[src]

impl Display for WeightedAdjacencyList[src]

Pretty-prints a small graph represented by a weighted adjacency list The graph is first converted to a WeightedAdjacencyMatrix before being printed

impl From<WeightedAdjacencyList> for WeightedAdjacencyMatrix[src]

For convinience

impl From<WeightedAdjacencyList> for WeightedUndirectedAdjacencyMatrixCondensed[src]

impl Index<usize> for WeightedAdjacencyList[src]

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

type Output = Vec<Edge>

The returned type after indexing.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,