public class DirectedSparseGraph<V,E> extends AbstractTypedGraph<V,E> implements DirectedGraph<V,E>
DirectedGraph suitable for sparse graphs.| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<E,Pair<V>> |
edges |
protected java.util.Map<V,Pair<java.util.Map<V,E>>> |
vertices |
edgeType| Constructor and Description |
|---|
DirectedSparseGraph()
Creates an instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdgeWithEndpoints(E edge,
Pair<? extends V> endpoints,
EdgeType edgeType)
Adds
edge to this graph with the specified endpoints
and EdgeType. |
boolean |
addVertex(V vertex)
Adds
vertex to this graph. |
boolean |
containsEdge(E edge)
Returns true if this graph's edge collection contains
edge. |
boolean |
containsVertex(V vertex)
Returns true if this graph's vertex collection contains
vertex. |
E |
findEdge(V v1,
V v2)
Returns an edge that connects this vertex to
v. |
java.util.Collection<E> |
findEdgeSet(V v1,
V v2)
Returns all edges that connects this vertex to
v. |
V |
getDest(E directed_edge)
If
directed_edge is a directed edge in this graph, returns the destination;
otherwise returns null. |
int |
getEdgeCount()
Returns the number of edges in this graph.
|
java.util.Collection<E> |
getEdgesView()
Returns a view of all edges in this graph.
|
Pair<V> |
getEndpoints(E edge)
Returns the endpoints of
edge as a Pair. |
static <V,E> Factory<DirectedGraph<V,E>> |
getFactory()
Returns a
Factory that creates an instance of this graph type. |
java.util.Collection<E> |
getIncidentEdges(V vertex)
Returns the collection of edges in this graph which are connected to
vertex. |
protected java.util.Collection<E> |
getIncoming_internal(V vertex) |
java.util.Collection<E> |
getInEdges(V vertex)
Returns a
Collection view of the incoming edges incident to vertex in this graph. |
java.util.Collection<V> |
getNeighbors(V vertex)
Returns the collection of vertices which are connected to
vertex via any edges in this graph. |
java.util.Collection<E> |
getOutEdges(V vertex)
Returns a
Collection view of the outgoing edges incident to vertex
in this graph. |
protected java.util.Collection<E> |
getOutgoing_internal(V vertex) |
java.util.Collection<V> |
getPredecessors(V vertex)
Returns a
Collection view of the predecessors of vertex
in this graph. |
protected java.util.Collection<V> |
getPreds_internal(V vertex) |
V |
getSource(E directed_edge)
If
directed_edge is a directed edge in this graph, returns the source;
otherwise returns null. |
java.util.Collection<V> |
getSuccessors(V vertex)
Returns a
Collection view of the successors of vertex
in this graph. |
protected java.util.Collection<V> |
getSuccs_internal(V vertex) |
int |
getVertexCount()
Returns the number of vertices in this graph.
|
java.util.Collection<V> |
getVerticesView()
Returns a view of all vertices in this graph.
|
boolean |
isDest(V vertex,
E edge)
Returns
true if vertex is the destination of edge. |
boolean |
isSource(V vertex,
E edge)
Returns
true if vertex is the source of edge. |
boolean |
removeEdge(E edge)
Removes
edge from this graph. |
boolean |
removeVertex(V vertex)
Removes
vertex from this graph. |
getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, hasEqualEdgeType, validateEdgeTypeaddEdge, addEdge, addEdgeWithEndPoints, addEdgeWithVertices, addEdgeWithVertices, degree, getIncidentCount, getIncidentVertices, getNeighborCount, getOpposite, getPredecessorCount, getSuccessorCount, getValidatedEndpoints, inDegree, isIncident, isNeighbor, isPredecessor, isSuccessor, outDegreeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddEdge, addEdge, getOpposite, getPredecessorCount, getSuccessorCount, inDegree, isPredecessor, isSuccessor, outDegreeaddEdgeWithVertices, addEdgeWithVertices, degree, getDefaultEdgeType, getEdgeCount, getEdges, getEdgeType, getIncidentCount, getIncidentVertices, getNeighborCount, isIncident, isNeighborpublic static final <V,E> Factory<DirectedGraph<V,E>> getFactory()
Factory that creates an instance of this graph type.V - the vertex type for the graph factoryE - the edge type for the graph factorypublic boolean addEdgeWithEndpoints(E edge, Pair<? extends V> endpoints, EdgeType edgeType)
AbstractGraphedge to this graph with the specified endpoints
and EdgeType.addEdgeWithEndpoints in class AbstractGraph<V,E>public E findEdge(V v1, V v2)
Hypergraphv. If this edge is not uniquely defined (that is, if the graph
contains more than one edge connecting v1 to v2), any of these edges may be returned.
findEdgeSet(v1, v2) may be used to return all such edges.
Returns null if either of the following is true:
v2 is not connected to v1v1 or v2 are not present in this graphv1 is only considered to be connected to
v2 via a given directed edge e if
v1 == e.getSource() && v2 == e.getDest() evaluates to true.
(v1 and v2 are connected by an undirected edge u if
u is incident to both v1 and v2.)findEdge in interface Hypergraph<V,E>findEdge in class AbstractGraph<V,E>v1 - the first vertexv2 - the second vertexv1 to v2, or null if no such edge exists (or either
vertex is not present)Hypergraph.findEdgeSet(Object, Object)public java.util.Collection<E> findEdgeSet(V v1, V v2)
Hypergraphv. If this edge is not uniquely defined (that is, if the graph
contains more than one edge connecting v1 to v2), any of these edges may be returned.
findEdgeSet(v1, v2) may be used to return all such edges.
Returns null if v2 is not connected to v1. Returns an empty collection if either v1
or v2 are not present in this graph.
Note: for purposes of this method, v1 is only considered to be connected to
v2 via a given directed edge d if
v1 == d.getSource() && v2 == d.getDest() evaluates to true.
(v1 and v2 are connected by an undirected edge u if
u is incident to both v1 and v2.)findEdgeSet in interface Hypergraph<V,E>findEdgeSet in class AbstractGraph<V,E>v1 - the first vertexv2 - the second vertexv1 to v2,
or null if either vertex is not presentHypergraph.findEdge(Object, Object)public java.util.Collection<E> getInEdges(V vertex)
GraphCollection view of the incoming edges incident to vertex in this graph.getInEdges in interface Graph<V,E>getInEdges in interface Hypergraph<V,E>vertex - the vertex whose incoming edges are to be returnedCollection view of the incoming edges incident
to vertex in this graphpublic java.util.Collection<E> getOutEdges(V vertex)
GraphCollection view of the outgoing edges incident to vertex
in this graph.getOutEdges in interface Graph<V,E>getOutEdges in interface Hypergraph<V,E>vertex - the vertex whose outgoing edges are to be returnedCollection view of the outgoing edges incident
to vertex in this graphpublic java.util.Collection<V> getPredecessors(V vertex)
GraphCollection view of the predecessors of vertex
in this graph. A predecessor of vertex is defined as a vertex v
which is connected to
vertex by an edge e, where e is an outgoing edge of
v and an incoming edge of vertex.getPredecessors in interface Graph<V,E>getPredecessors in interface Hypergraph<V,E>vertex - the vertex whose predecessors are to be returnedCollection view of the predecessors of
vertex in this graphpublic java.util.Collection<V> getSuccessors(V vertex)
GraphCollection view of the successors of vertex
in this graph. A successor of vertex is defined as a vertex v
which is connected to
vertex by an edge e, where e is an incoming edge of
v and an outgoing edge of vertex.getSuccessors in interface Graph<V,E>getSuccessors in interface Hypergraph<V,E>vertex - the vertex whose predecessors are to be returnedCollection view of the successors of
vertex in this graphpublic Pair<V> getEndpoints(E edge)
Graphedge as a Pair.getEndpoints in interface Graph<V,E>edge - the edge whose endpoints are to be returnededgepublic V getSource(E directed_edge)
Graphdirected_edge is a directed edge in this graph, returns the source;
otherwise returns null.
The source of a directed edge d is defined to be the vertex for which
d is an outgoing edge.
directed_edge is guaranteed to be a directed edge if
its EdgeType is DIRECTED.public V getDest(E directed_edge)
Graphdirected_edge is a directed edge in this graph, returns the destination;
otherwise returns null.
The destination of a directed edge d is defined to be the vertex
incident to d for which
d is an incoming edge.
directed_edge is guaranteed to be a directed edge if
its EdgeType is DIRECTED.public boolean isSource(V vertex, E edge)
Graphtrue if vertex is the source of edge.
Equivalent to getSource(edge).equals(vertex).public boolean isDest(V vertex, E edge)
Graphtrue if vertex is the destination of edge.
Equivalent to getDest(edge).equals(vertex).public java.util.Collection<E> getEdgesView()
HypergraphCollection contract, and therefore
makes no guarantees about the ordering of the vertices within the set.getEdgesView in interface Hypergraph<V,E>Collection view of all edges in this graphpublic java.util.Collection<V> getVerticesView()
HypergraphCollection contract, and therefore makes no guarantees
about the ordering of the vertices within the set.getVerticesView in interface Hypergraph<V,E>Collection view of all vertices in this graphpublic boolean containsVertex(V vertex)
Hypergraphvertex. Equivalent to
getVertices().contains(vertex).containsVertex in interface Hypergraph<V,E>vertex - the vertex whose presence is being queriedvertexpublic boolean containsEdge(E edge)
Hypergraphedge.
Equivalent to getEdges().contains(edge).containsEdge in interface Hypergraph<V,E>edge - the edge whose presence is being queriededgepublic int getEdgeCount()
HypergraphgetEdgeCount in interface Hypergraph<V,E>public int getVertexCount()
HypergraphgetVertexCount in interface Hypergraph<V,E>public java.util.Collection<V> getNeighbors(V vertex)
Hypergraphvertex via any edges in this graph.
If vertex is connected to itself with a self-loop, then it will be included in the collection returned.getNeighbors in interface Hypergraph<V,E>vertex - the vertex whose neighbors are to be returnedvertex,
or null if vertex is not presentpublic java.util.Collection<E> getIncidentEdges(V vertex)
Hypergraphvertex.getIncidentEdges in interface Hypergraph<V,E>vertex - the vertex whose incident edges are to be returnedvertex,
or null if vertex is not presentpublic boolean addVertex(V vertex)
Hypergraphvertex to this graph. Fails if vertex is null or already in the graph.addVertex in interface Hypergraph<V,E>vertex - the vertex to addtrue if the add is successful, and false otherwisepublic boolean removeVertex(V vertex)
Hypergraphvertex from this graph. As a side effect, removes any edges e incident to vertex if the
removal of vertex would cause e to be incident to an illegal number of vertices. (Thus, for example,
incident hyperedges are not removed, but incident edges--which must be connected to a vertex at both endpoints--are removed.)
Fails under the following circumstances:
vertex is not an element of this graphvertex is nullremoveVertex in interface Hypergraph<V,E>vertex - the vertex to removetrue if the removal is successful, false otherwisepublic boolean removeEdge(E edge)
Hypergraphedge from this graph.
Fails if edge is null, or is otherwise not an element of this graph.removeEdge in interface Hypergraph<V,E>edge - the edge to removetrue if the removal is successful, false otherwiseCopyright © 2021, 2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence