Package dev.nm.graph.type
Class SparseGraph<V,E extends HyperEdge<V>>
- java.lang.Object
-
- dev.nm.graph.type.SparseGraph<V,E>
-
- Type Parameters:
V
- vertex typeE
- 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 Summary
Constructors Constructor Description SparseGraph()
Construct an empty graph.SparseGraph(Graph<V,E> g)
(Copy) construct a graph from another graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SparseGraph<V,E>
addEdge(E e)
Adds an edge to this graph.SparseGraph<V,E>
addVertex(V v)
Adds a vertex to this graph.boolean
contains(V v)
Check if this graph contains a vertex.Set<E>
edges()
Gets the set of all edges in this graph.Set<E>
edges(V v)
Gets the set of all edges associated with a vertex in this graph.SparseGraph<V,E>
removeEdge(E e)
Removes an edge from this graph.SparseGraph<V,E>
removeVertex(V v)
Removes a vertex from this graph.String
toString()
Set<V>
vertices()
Gets the set of all vertices in this graph.
-
-
-
Method Detail
-
vertices
public Set<V> vertices()
Description copied from interface:Graph
Gets the set of all vertices in this graph.
-
edges
public Set<E> edges()
Description copied from interface:Graph
Gets the set of 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.
-
addVertex
public SparseGraph<V,E> addVertex(V v)
Description copied from interface:Graph
Adds a vertex to this graph. Does nothing ifv
is already in the graph.
-
addEdge
public SparseGraph<V,E> addEdge(E e)
Description copied from interface:Graph
Adds an edge to this graph. Does nothing ife
is already in the graph. If the edge contains new vertices, those will be added to the graph.
-
removeVertex
public SparseGraph<V,E> removeVertex(V v)
Description copied from interface:Graph
Removes a vertex from this graph. Does nothing ifv
is not in the graph. The edges associated with this vertex are also removed.
-
removeEdge
public SparseGraph<V,E> removeEdge(E e)
Description copied from interface:Graph
Removes an edge from this graph. Does nothing ife
is not in the graph. The vertices associated with the edge is not removed.
-
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
-
-