extern crate collections_rs as collections;
pub mod vec;
mod map;
pub use map::MapGraph;
pub trait DirectedWeightedGraph<'g, N, W>
where
N: 'g + Eq,
W: 'g,
{
type AllWeightedEdges: Iterator<Item = (&'g N, &'g N, &'g W)>;
type AllWeightedEdgesMut: Iterator<Item = (&'g N, &'g N, &'g mut W)>;
fn all_edges(&'g self) -> Self::AllWeightedEdges;
fn all_edges_mut(&'g mut self) -> Self::AllWeightedEdgesMut;
fn add_edge(&'g mut self, N, N, W) -> Option<(N, N, W)>;
fn remove_edge(&'g mut self, &N, &N) -> Option<(N, N, W)>;
fn has_edge(&'g self, source: &N, sink: &N) -> bool {
self.edge_weight(source, sink).is_some()
}
fn edge_weight(&'g self, source: &N, sink: &N) -> Option<&W> {
self.all_edges()
.find(|&(n1, n2, _)| n1 == source && n2 == sink)
.map(|(_, _, weight)| weight)
}
fn edge_weight_mut(&'g mut self, source: &N, sink: &N) -> Option<&mut W> {
self.all_edges_mut()
.find(|&(n1, n2, _)| n1 == source && n2 == sink)
.map(|(_, _, weight)| weight)
}
}