fera-graph 0.1.1

Graph data structures and algorithms.
Documentation
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// TODO: multi set
// TODO: iterator

pub type DefaultVertexSet<G> = <G as WithVertexSet>::VertexSet;
pub type DefaultEdgeSet<G> = <G as WithEdgeSet>::EdgeSet;

// Set

pub trait Set<Item> {
    fn insert(&mut self, item: Item) -> bool;

    fn remove(&mut self, item: Item) -> bool;

    fn contains(&self, item: Item) -> bool;

    fn len(&self) -> usize;

    fn is_empty(&self) -> bool {
        self.len() == 0
    }
}

pub trait VertexSet<G: WithVertex>: Set<Vertex<G>> {
    fn new_vertex_set(g: &G) -> Self;
}

pub trait WithVertexSet: WithVertex {
    type VertexSet: VertexSet<Self>;

    fn vertex_set<S>(&self) -> S
        where S: VertexSet<Self>
    {
        S::new_vertex_set(self)
    }

    fn default_vertex_set(&self) -> DefaultVertexSet<Self> {
        self.vertex_set()
    }
}

pub trait EdgeSet<G: WithEdge>: Set<Edge<G>> {
    fn new_edge_set(g: &G) -> Self;
}

pub trait WithEdgeSet: WithEdge {
    type EdgeSet: EdgeSet<Self>;

    fn edge_set<S>(&self) -> S
        where S: EdgeSet<Self>
    {
        S::new_edge_set(self)
    }

    fn default_edge_set(&self) -> DefaultEdgeSet<Self> {
        self.edge_set()
    }
}