Class SparseGraph<V,​E extends HyperEdge<V>>

  • Type Parameters:
    V - vertex type
    E - edge type
    All Implemented Interfaces:
    Graph<V,​E>
    Direct Known Subclasses:
    SparseDiGraph, SparseUnDiGraph

    public class SparseGraph<V,​E extends HyperEdge<V>>
    extends Object
    implements Graph<V,​E>
    This class implements the sparse graph representation.
    • Constructor Detail

      • SparseGraph

        public SparseGraph()
        Construct an empty graph.
      • SparseGraph

        public SparseGraph​(Graph<V,​E> g)
        (Copy) construct a graph from another graph.
        Parameters:
        g - a graph
    • Method Detail

      • vertices

        public Set<V> vertices()
        Description copied from interface: Graph
        Gets the set of all vertices in this graph.
        Specified by:
        vertices in interface Graph<V,​E extends HyperEdge<V>>
        Returns:
        all vertices in this graph
      • edges

        public Set<E> edges()
        Description copied from interface: Graph
        Gets the set of all edges in this graph.
        Specified by:
        edges in interface Graph<V,​E extends HyperEdge<V>>
        Returns:
        all edges in this graph
      • edges

        public Set<E> edges​(V v)
        Description copied from interface: Graph
        Gets the set of all edges associated with a vertex in this graph.
        Specified by:
        edges in interface Graph<V,​E extends HyperEdge<V>>
        Parameters:
        v - a vertex
        Returns:
        all edges associated with a vertex
      • addVertex

        public SparseGraph<V,​E> addVertex​(V v)
        Description copied from interface: Graph
        Adds a vertex to this graph. Does nothing if v is already in the graph.
        Specified by:
        addVertex in interface Graph<V,​E extends HyperEdge<V>>
        Parameters:
        v - the vertex to add
        Returns:
        this graph (for builder pattern)
      • addEdge

        public SparseGraph<V,​E> addEdge​(E e)
        Description copied from interface: Graph
        Adds an edge to this graph. Does nothing if e is already in the graph. If the edge contains new vertices, those will be added to the graph.
        Specified by:
        addEdge in interface Graph<V,​E extends HyperEdge<V>>
        Parameters:
        e - the edge to add
        Returns:
        this graph (for builder pattern)
      • removeVertex

        public SparseGraph<V,​E> removeVertex​(V v)
        Description copied from interface: Graph
        Removes a vertex from this graph. Does nothing if v is not in the graph. The edges associated with this vertex are also removed.
        Specified by:
        removeVertex in interface Graph<V,​E extends HyperEdge<V>>
        Parameters:
        v - the vertex to be removed
        Returns:
        this graph (for builder pattern)
      • removeEdge

        public SparseGraph<V,​E> removeEdge​(E e)
        Description copied from interface: Graph
        Removes an edge from this graph. Does nothing if e is not in the graph. The vertices associated with the edge is not removed.
        Specified by:
        removeEdge in interface Graph<V,​E extends HyperEdge<V>>
        Parameters:
        e - the edge to be removed
        Returns:
        this graph (for builder pattern)
      • contains

        public boolean contains​(V v)
        Check if this graph contains a vertex.
        Parameters:
        v - a vertex
        Returns:
        true if this graph contains the vertex