Struct prepona::algo::Eulerian[][src]

pub struct Eulerian<W, E: Edge<W>, Ty: EdgeDir, G: Graph<W, E, Ty>> { /* fields omitted */ }

Finds Eulerian trail and circuit.

Examples

use prepona::prelude::*;
use prepona::algo::Eulerian;
use prepona::storage::Mat;
use prepona::graph::MatGraph;

// Given:
//
//      a --- b --.
//     /  \       |
//    e    \      |
//     \    \     |
//      c -- d    |
//      |_________'
//
let mut graph = MatGraph::init(Mat::<usize>::init());
let a = graph.add_vertex();
let b = graph.add_vertex();
let c = graph.add_vertex();
let d = graph.add_vertex();
let e = graph.add_vertex();
graph.add_edge_unchecked(a, b, 1.into());
graph.add_edge_unchecked(a, e, 1.into());
graph.add_edge_unchecked(a, d, 1.into());
graph.add_edge_unchecked(b, c, 1.into());
graph.add_edge_unchecked(c, d, 1.into());
graph.add_edge_unchecked(c, e, 1.into());

// When: Performing Eulerian trail detection algorithm.
let trail = Eulerian::init(&graph).find_trail(&graph).unwrap();

// Then:
assert_eq!(trail.len(), 7);
assert_eq!(trail, vec![a, b, c, d, a, e, c]);

Implementations

impl<W, E, Ty, G> Eulerian<W, E, Ty, G> where
    E: Edge<W>,
    Ty: EdgeDir,
    G: Graph<W, E, Ty> + Vertices + Edges<W, E>, 
[src]

pub fn init(graph: &G) -> Self[src]

Initializes the structure.

Arguments

graph: The graph to find the Eulerian trail or circuit in.

pub fn start_of_eulerian_trail(&self) -> Option<usize>[src]

Finds id of the vertex to start the Eulerian trail from.

Returns

  • Some: Containing the id of the starting vertex of Eulerian trail.
  • None: If can not find a starting vertex for Eulerian trail.

pub fn start_of_eulerian_circuit(&self) -> Option<usize>[src]

Finds id of the vertex to start the Eulerian circuit from.

Returns

  • Some: Containing the id of the starting vertex.
  • None: If can not find a starting vertex for Eulerian circuit.

pub fn find_trail(self, graph: &G) -> Result<Vec<usize>>[src]

Finds the Eulerian trail if there is one.

Arguments

graph: Graph to search the Eulerian trail in it.

Returns

  • Ok: Containing list of vector ids that will get visited during the Eulerian trail.
  • Err: If graph does not have Eulerian trail.

pub fn find_circuit(self, graph: &G) -> Result<Vec<usize>>[src]

Finds the Eulerian circuit if there is one.

Arguments

graph: Graph to search the eulerian circuit in it.

Returns

  • Ok: Containing list of vector ids that will get visited during the eulerian circuit.
  • Err: If graph does not have Eulerian circuit.

Auto Trait Implementations

impl<W, E, Ty, G> RefUnwindSafe for Eulerian<W, E, Ty, G> where
    E: RefUnwindSafe,
    G: RefUnwindSafe,
    Ty: RefUnwindSafe,
    W: RefUnwindSafe

impl<W, E, Ty, G> Send for Eulerian<W, E, Ty, G> where
    E: Send,
    G: Send,
    Ty: Send,
    W: Send

impl<W, E, Ty, G> Sync for Eulerian<W, E, Ty, G> where
    E: Sync,
    G: Sync,
    Ty: Sync,
    W: Sync

impl<W, E, Ty, G> Unpin for Eulerian<W, E, Ty, G> where
    E: Unpin,
    G: Unpin,
    Ty: Unpin,
    W: Unpin

impl<W, E, Ty, G> UnwindSafe for Eulerian<W, E, Ty, G> where
    E: UnwindSafe,
    G: UnwindSafe,
    Ty: UnwindSafe,
    W: UnwindSafe

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