[][src]Trait generic_graph::DirectedGraph

pub trait DirectedGraph<T, E, K, V, W, C> where
    K: Hash + Eq + Clone,
    C: Hash + Eq + Clone,
    W: Add + Sub + Eq + Ord + Copy,
    T: Vertex<K, V>,
    E: Edge<K, W, C>, 
{ fn adjacent(&self, from: &K, to: &K) -> bool;
fn neighbors(&self, from: &K) -> Vec<&K>;
fn leading_to(&self, to: &K) -> Vec<&K>;
fn get_all_keys(&self) -> Vec<&K>;
fn get_all_pairs(&self) -> Vec<(&K, &K)>;
fn get_vertex(&self, key: &K) -> Option<&T>;
fn get_mut_vertex(&mut self, key: &K) -> Option<&mut T>;
fn get_edge(&self, pair: (&K, &K)) -> Option<&E>;
fn get_mut_edge(&mut self, pair: (&K, &K)) -> Option<&mut E>; }

This trait define the behaviour of a directed graph it requires the for vertexes (T), edges (E), vertex's keys (K), vertex's values (v), edge's weights (W) and edge's keys (C)

Required methods

fn adjacent(&self, from: &K, to: &K) -> bool

This method returns a boolean stating if exist an edge from the first vertex to the other

fn neighbors(&self, from: &K) -> Vec<&K>

This method returns a vector containing the keys of all the vertexes reached by edges starting from the argument

fn leading_to(&self, to: &K) -> Vec<&K>

This method returns a vector containing the keys of all the vertexes with by edges leading to the argument

fn get_all_keys(&self) -> Vec<&K>

This method returns a vector containing references to the keys of all vertexes in the graph

fn get_all_pairs(&self) -> Vec<(&K, &K)>

This method returns a vector containing the pairs of all edges in the graph

fn get_vertex(&self, key: &K) -> Option<&T>

fn get_mut_vertex(&mut self, key: &K) -> Option<&mut T>

fn get_edge(&self, pair: (&K, &K)) -> Option<&E>

fn get_mut_edge(&mut self, pair: (&K, &K)) -> Option<&mut E>

Loading content...

Implementors

impl<K: Hash + Eq + Clone, V, W: Add + Sub + Eq + Ord + Copy> DirectedGraph<SimpleVertex<K, V>, DirectedEdge<K, W>, K, V, W, CompoundKey<K>> for AdjacencyGraph<K, V, W>[src]

AdjacencyGraph implement the DirectedGraph trait Specifying the vertex type (DirectedVertex), the edge type (Directed Edge), and the edge key type (CompoundKey). But the vertex key type, the vertex value type and the edge weight type remain generics.

fn adjacent(&self, from: &K, to: &K) -> bool[src]

Check if an edge going from the first to the second vertex exists

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges, DirectedGraph};
use generic_graph::adjacency_list::elements::DirectedEdge;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));
graph.add_vertex(SimpleVertex::new(3, "c"));
graph.add_edge(DirectedEdge::new(2, 3, 3)).expect("Won't fail");
graph.add_edge(DirectedEdge::new(1, 3, 3)).expect("Won't fail");
assert_eq!(true, graph.adjacent(&1, &3));
assert_eq!(false, graph.adjacent(&3, &1));
assert_eq!(false, graph.adjacent(&2, &1));

fn neighbors(&self, from: &K) -> Vec<&K>[src]

Returns a Vector containing the keys of the vertexes reached by edges leaving from the vertex identified by the passed key

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges, DirectedGraph};
use generic_graph::adjacency_list::elements::DirectedEdge;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));
graph.add_vertex(SimpleVertex::new(3, "c"));
graph.add_edge(DirectedEdge::new(2, 3, 3)).expect("Won't fail");
graph.add_edge(DirectedEdge::new(2, 1, 3)).expect("Won't fail");
graph.add_edge(DirectedEdge::new(1, 3, 3)).expect("Won't fail");

let mut neighbors = graph.neighbors(&2);
neighbors.sort();
assert_eq!(neighbors, vec![&1,&3]);

fn leading_to(&self, to: &K) -> Vec<&K>[src]

Returns a vector containing the keys of the Vertexes from which an edge leave to reach the vertex identified by the passed key

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges, DirectedGraph};
use generic_graph::adjacency_list::elements::DirectedEdge;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));
graph.add_vertex(SimpleVertex::new(3, "c"));
graph.add_edge(DirectedEdge::new(2, 3, 3)).expect("Won't fail");
graph.add_edge(DirectedEdge::new(1, 3, 3)).expect("Won't fail");

let mut leading_to = graph.leading_to(&3);
leading_to.sort();
assert_eq!(leading_to, vec![&1,&2]);

fn get_all_keys(&self) -> Vec<&K>[src]

Returns a vector containing the references to keys of all vertexes in the graph

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges, DirectedGraph};
use generic_graph::adjacency_list::elements::DirectedEdge;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));
graph.add_vertex(SimpleVertex::new(3, "c"));
graph.add_edge(DirectedEdge::new(2, 3, 3)).expect("Won't fail");
graph.add_edge(DirectedEdge::new(1, 3, 3)).expect("Won't fail");

let mut keys = graph.get_all_keys();
keys.sort();
assert_eq!(keys, vec![&1, &2, &3]);

fn get_all_pairs(&self) -> Vec<(&K, &K)>[src]

Returns a vector containing the pairs of all edges in the graph

Examples

use generic_graph::adjacency_list::AdjacencyGraph;
use generic_graph::{SimpleVertex, VariableVertexes, VariableEdges, DirectedGraph};
use generic_graph::adjacency_list::elements::DirectedEdge;
let mut graph = AdjacencyGraph::new();
graph.add_vertex(SimpleVertex::new(1, "a"));
graph.add_vertex(SimpleVertex::new(2, "b"));
graph.add_vertex(SimpleVertex::new(3, "c"));
graph.add_edge(DirectedEdge::new(2, 3, 3)).expect("Won't fail");
graph.add_edge(DirectedEdge::new(1, 3, 3)).expect("Won't fail");

let mut pairs = graph.get_all_pairs();
pairs.sort();
assert_eq!(pairs, vec![(&1, &3), (&2, &3)]);

fn get_vertex(&self, key: &K) -> Option<&SimpleVertex<K, V>>[src]

Returns a reference to the vertex identified by the passed key

fn get_mut_vertex(&mut self, key: &K) -> Option<&mut SimpleVertex<K, V>>[src]

Returns a mutable reference to the vertex identified by the passed key

fn get_edge(&self, pair: (&K, &K)) -> Option<&DirectedEdge<K, W>>[src]

Returns a reference to the edge identified by the passed pair of keys

fn get_mut_edge(&mut self, pair: (&K, &K)) -> Option<&mut DirectedEdge<K, W>>[src]

Returns a mutable reference to the edge identified by the passed pair of keys

Loading content...