Package org.simplegraph.impl
Class DirectedSparseGraph<V>
java.lang.Object
org.simplegraph.impl.DirectedSparseGraph<V>
- All Implemented Interfaces:
DirectedGraph<V>,Graph<V>
Sparse graph implementation for directed graphs.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructorDirectedSparseGraph(int size) Create a graph with a starting size.DirectedSparseGraph(DirectedSparseGraph<V> graph) -
Method Summary
Modifier and TypeMethodDescriptionprotected intprotected boolean_removeEdge(V v1, V v2) booleanAdd an edge between two vertices.protected booleanaddSingleEdge(V v1, V v2, Boolean edge) booleanAdd a vertex to the graph.booleancontainsVertex(V vertex) Check the existence of a vertex in the graph.voidintGet the number of edges in the graph.intcountNeighbors(V vertex) Get the number of neighbors for a vertex.intGet the number of vertices in the graph.booleanexistsEdge(V v1, V v2) Check the existence of an edge that goes from the first vertex to the second.booleanexistsPath(V source, V destination) Does a path exists between source and destination.intgetInDegree(V vertex) Get the number of incident vertices of a vertex.getInVertices(V vertex) Get the incident vertices of a vertex.getNeighbors(V vertex) Get the neighbors of a vertex, both incident and outer vertices.intgetOutDegree(V vertex) Get the number of outer vertices of a vertex.getOutVertices(V vertex) Get the outer vertices of a vertex.Get a path between a source and a destinationprotected BooleangetSingleEdge(V v1, V v2) Get all the vertices in the graphbooleanremoveEdge(V v1, V v2) Remove an edge that goes from the first vertex to the second.booleanremoveVertex(V vertex) Remove a vertex from the graphMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.simplegraph.Graph
countEdges
-
Field Details
-
DEFAULT_SIZE
protected static final int DEFAULT_SIZE- See Also:
-
edges
-
-
Constructor Details
-
DirectedSparseGraph
public DirectedSparseGraph()Default constructor -
DirectedSparseGraph
public DirectedSparseGraph(int size) Create a graph with a starting size.- Parameters:
size- starting size
-
DirectedSparseGraph
-
-
Method Details
-
addEdge
Description copied from interface:GraphAdd an edge between two vertices. Add the two vertices in the graph if they don't exists -
addVertex
Add a vertex to the graph.- Parameters:
vertex- the vertex to add- Returns:
- true if the the graph has been modified
-
containsVertex
Check the existence of a vertex in the graph.- Parameters:
vertex- the vertex to check- Returns:
- true if the graph contains vertex
-
countVertices
public int countVertices()Get the number of vertices in the graph.- Returns:
- number of vertices
-
existsPath
Does a path exists between source and destination.- Parameters:
source- source vertexdestination- destination vertex- Returns:
- true if a path exists
-
existsEdge
Check the existence of an edge that goes from the first vertex to the second.- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if an edge from v1 to v2 exists
-
countNeighbors
Get the number of neighbors for a vertex.- Parameters:
vertex- the spefied vertex- Returns:
- number of neighbors, -1 if vertex does not exists
-
getPath
Get a path between a source and a destination- Parameters:
source- source vertexdestination- destination vertex- Returns:
- a list containing the vertices that compose the path, in order; an empty LinkedList if there is no path, null if the source and the destination are equals or are not contained in the graph
-
removeEdge
Remove an edge that goes from the first vertex to the second.- Parameters:
v1- first vertexv2- second vertex- Returns:
- true if the graph has been changed
-
removeVertex
Remove a vertex from the graph- Parameters:
vertex- the vertex to remove- Returns:
- true if the graph has been modified
-
getVertices
Get all the vertices in the graph- Returns:
- a list containing all the graph vertices
-
getNeighbors
Get the neighbors of a vertex, both incident and outer vertices.- Parameters:
vertex- the specified vertex- Returns:
- the list of vertices that are neighbors of vertex null if the vertex is not contained in the graph
-
getInVertices
Get the incident vertices of a vertex.- Specified by:
getInVerticesin interfaceDirectedGraph<V>- Parameters:
vertex- the specified vertex- Returns:
- a list containing the incident vertices of vertex, null if vertex is not contained in the graph
-
getOutVertices
Get the outer vertices of a vertex.- Specified by:
getOutVerticesin interfaceDirectedGraph<V>- Parameters:
vertex- the specified vertex- Returns:
- a list containing the outer vertices of vertex, null if vertex is not contained in the graph
-
getInDegree
Get the number of incident vertices of a vertex.- Specified by:
getInDegreein interfaceDirectedGraph<V>- Parameters:
vertex- the specified vertex- Returns:
- the number of incident vertices of vertex, -1 if vertex is not contained in the graph
-
getOutDegree
Get the number of outer vertices of a vertex.- Specified by:
getOutDegreein interfaceDirectedGraph<V>- Parameters:
vertex- the specified vertex- Returns:
- the number of outer vertices of vertex, -1 if vertex is not contained in the graph
-
getSpanningTree
- Specified by:
getSpanningTreein interfaceGraph<V>
-
countEdges
public int countEdges()Get the number of edges in the graph.- Returns:
- number of edges
-
copy
-
addSingleEdge
-
getSingleEdge
-
_removeEdge
-
_countEdges
protected int _countEdges()
-