public class SparseUndirectedGraph extends AbstractGraph<Edge,SparseUndirectedEdgeSet>
Graph
that uses a sparse backing
representation. This implementation assumes that the total number of edges
is less than the n
2 possible, where n
is the
number of vertices.
This class supports all optional Graph
. All returned Edge
-based collections will reflect the state of the graph and may be
modified to change the graph; i.e., adding an edge to the adjacency list of a
vertex or edge list of the graph will add that edge in the backing graph.
Adding vertices by adding to the AbstractGraph.vertices()
set is supported.
Adding edges by adding a vertex to the set of adjacent vertex is not
supported.
AbstractGraph.Subgraph
Constructor and Description |
---|
SparseUndirectedGraph()
Creates an empty undirected graph
|
SparseUndirectedGraph(Graph<? extends Edge> g)
Creates an undirected graph with a copy of all the vertices and edges in
g . |
SparseUndirectedGraph(Set<Integer> vertices)
Creates an undirected graph with no edges and the provided set of vertices
|
Modifier and Type | Method and Description |
---|---|
Graph<Edge> |
copy(Set<Integer> vertices)
Creates a copy of this graph containing only the specified number of
vertices and all edges between those vertices.
|
protected SparseUndirectedEdgeSet |
createEdgeSet(int vertex)
Creates a sparse edge set that treats all edges as symmetric.
|
add, add, clear, clearEdges, contains, contains, contains, degree, edges, equals, getAdjacencyList, getEdges, getEdgeSet, getNeighbors, hasCycles, hashCode, iterator, order, remove, remove, size, subgraph, toString, vertices
public SparseUndirectedGraph()
public SparseUndirectedGraph(Set<Integer> vertices)
public Graph<Edge> copy(Set<Integer> vertices)
vertices
is
empty a new, empty graph of this instance's type is returned. Any
changes made to this graph will not be reflected in returned copy or
vice-versa.copy
in interface Graph<Edge>
copy
in class AbstractGraph<Edge,SparseUndirectedEdgeSet>
protected SparseUndirectedEdgeSet createEdgeSet(int vertex)
createEdgeSet
in class AbstractGraph<Edge,SparseUndirectedEdgeSet>
Copyright © 2012. All Rights Reserved.