[][src]Struct structures::graph::Graph

pub struct Graph { /* fields omitted */ }

Directed Graph

Examples

use structures::graph::Graph;

let graph: Graph = vec![
  (1, 2, 7), (1, 3, 9), (1, 6, 14),
  (2, 3, 10), (2, 4, 15), (3, 4, 11),
  (3, 6, 2), (4, 5, 6), (6, 5, 9),
].into_iter().collect();

assert_eq!(graph.shortest_path(1, Some(5))[&5], (20, vec![1, 3, 6, 5]));

assert_eq!(graph.shortest_paths()[&1][&5], (20, vec![1, 3, 6, 5]));

dijkstra-animation

Methods

impl Graph[src]

pub fn new() -> Self[src]

pub fn vertices(&self) -> Vertices[src]

pub fn vertices_outgoing_from(&self, source: Vertex) -> Vertices[src]

pub fn edges(&self) -> Edges[src]

pub fn weight(&self, source: Vertex, target: Vertex) -> Option<Weight>[src]

pub fn add_edge(&mut self, source: Vertex, target: Vertex, weight: Weight)[src]

impl Graph[src]

pub fn shortest_path(
    &self,
    source: Vertex,
    target: Option<Vertex>
) -> HashMap<Vertex, (Weight, Path)>
[src]

Dijkstra's Algorithm

pub fn shortest_paths(&self) -> HashMap<Vertex, HashMap<Vertex, (Weight, Path)>>[src]

Floyd-Warshall Algorithm

pub fn topo_sort(&self) -> Option<Path>[src]

Topological Sorting

Trait Implementations

impl Extend<(usize, usize, usize)> for Graph[src]

impl Default for Graph[src]

impl FromIterator<(usize, usize, usize)> for Graph[src]

Auto Trait Implementations

impl Send for Graph

impl Sync for Graph

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.