Class LinkedDirectedGraph<N,E>
java.lang.Object
com.google.javascript.jscomp.graph.Graph<N,E>
com.google.javascript.jscomp.graph.DiGraph<N,E>
com.google.javascript.jscomp.graph.LinkedDirectedGraph<N,E>
- Type Parameters:
N- Value type that the graph node stores.E- Value type that the graph edge stores.
- All Implemented Interfaces:
AdjacencyGraph<N,,E> GraphvizGraph
- Direct Known Subclasses:
ControlFlowGraph
A directed graph using ArrayLists within nodes to store edge information.
This implementation favors directed graph operations inherited from
DirectedGraph. Operations from Graph would tend to be slower.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA directed graph edge that stores the source and destination nodes at each edge.static classA directed graph node that stores outgoing edges and incoming edges as an list within the node itself.Nested classes/interfaces inherited from class com.google.javascript.jscomp.graph.DiGraph
DiGraph.DiGraphEdge<N,E>, DiGraph.DiGraphNode<N, E> Nested classes/interfaces inherited from class com.google.javascript.jscomp.graph.Graph
Graph.GraphEdge<N,E> Nested classes/interfaces inherited from interface com.google.javascript.jscomp.graph.GraphvizGraph
GraphvizGraph.GraphvizEdge, GraphvizGraph.GraphvizNode -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLinkedDirectedGraph(boolean useNodeAnnotations, boolean useEdgeAnnotations) -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(DiGraph.DiGraphNode<N, E> src, E edgeValue, DiGraph.DiGraphNode<N, E> dest) DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNode available.voidConnects two nodes in the graph with an edge.voidconnectIfNotConnectedInDirection(N srcValue, E edgeValue, N destValue) DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNode available.static <N,E> LinkedDirectedGraph <N, E> create()createNode(N nodeValue) Gets a node from the graph given a value.static <N,E> LinkedDirectedGraph <N, E> voiddisconnect(N n1, N n2) Disconnects two nodes in the graph by removing all edges between them.voiddisconnectInDirection(N srcValue, N destValue) Disconnects all edges from n1 to n2.getDirectedPredNodes(DiGraph.DiGraphNode<N, E> dNode) getDirectedPredNodes(N nodeValue) getDirectedSuccNodes(DiGraph.DiGraphNode<N, E> dNode) getDirectedSuccNodes(N nodeValue) getEdges()Gets an immutable list of all edges.Retrieves an edge from the graph.getEdgesInDirection(N n1, N n2) @Nullable Graph.GraphEdge<N, E> getFirstEdge(N n1, N n2) Retrieves any edge from the graph.Retrieve a list of edges in the graph.Retrieve a list of nodes in the graph.getInEdges(N nodeValue) Gets an immutable list of in edges of the given node.getName()Name of the graph.getNeighborNodes(N value) Gets the neighboring nodes.Gets a node from the graph given a value.intintgetNodeDegree(N value) Gets the degree of a node.getNodes()Gets an immutable list of all nodes.getOutEdges(N nodeValue) Gets an immutable list of out edges of the given node.booleanisConnectedInDirection(LinkedDirectedGraph.LinkedDiGraphNode<N, E> source, com.google.common.base.Predicate<E> edgeFilter, LinkedDirectedGraph.LinkedDiGraphNode<N, E> dest) DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNodes available.booleanisConnectedInDirection(N source, E edgeValue, N dest) DiGraphNode look ups can be expensive for a large graph operation, prefer the version below that takes DiGraphNodes, if you have them available.booleanisConnectedInDirection(N source, N dest) DiGraphNode look ups can be expensive for a large graph operation, prefer the version below that takes DiGraphNodes, if you have them available.booleanGraph type.Returns an empty SubGraph for this Graph.Methods inherited from class com.google.javascript.jscomp.graph.DiGraph
isConnected, isConnectedMethods inherited from class com.google.javascript.jscomp.graph.Graph
clearEdgeAnnotations, clearNodeAnnotations, connectIfNotFound, getWeight, hasNode, popEdgeAnnotations, popNodeAnnotations, pushEdgeAnnotations, pushNodeAnnotations
-
Field Details
-
nodes
-
-
Constructor Details
-
LinkedDirectedGraph
protected LinkedDirectedGraph(boolean useNodeAnnotations, boolean useEdgeAnnotations)
-
-
Method Details
-
newSubGraph
Description copied from interface:AdjacencyGraphReturns an empty SubGraph for this Graph.- Specified by:
newSubGraphin interfaceAdjacencyGraph<N,E>
-
createWithoutAnnotations
-
create
-
connect
Description copied from class:GraphConnects two nodes in the graph with an edge. -
connect
DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNode available. -
connectIfNotConnectedInDirection
DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNode available. -
disconnect
Description copied from class:GraphDisconnects two nodes in the graph by removing all edges between them.- Specified by:
disconnectin classGraph<N,E> - Parameters:
n1- First node.n2- Second node.
-
disconnectInDirection
Description copied from class:DiGraphDisconnects all edges from n1 to n2.- Specified by:
disconnectInDirectionin classDiGraph<N,E> - Parameters:
srcValue- Source node.destValue- Destination node.
-
getNodes
Description copied from class:GraphGets an immutable list of all nodes. -
getNode
Description copied from interface:AdjacencyGraphGets a node from the graph given a value. Values equality are compared usingObject.equals. -
getInEdges
Description copied from class:DiGraphGets an immutable list of in edges of the given node.- Specified by:
getInEdgesin classDiGraph<N,E>
-
getOutEdges
Description copied from class:DiGraphGets an immutable list of out edges of the given node.- Specified by:
getOutEdgesin classDiGraph<N,E>
-
createNode
Description copied from class:GraphGets a node from the graph given a value. New nodes are created if that value has not been assigned a graph node. Values equality are compared usingObject.equals.- Specified by:
createNodein classDiGraph<N,E> - Parameters:
nodeValue- The node's value.- Returns:
- The corresponding node in the graph.
-
getEdges
Description copied from class:GraphRetrieves an edge from the graph. -
getEdges
Description copied from class:GraphGets an immutable list of all edges. -
getFirstEdge
Description copied from class:GraphRetrieves any edge from the graph.- Specified by:
getFirstEdgein classGraph<N,E> - Parameters:
n1- Node one.n2- Node two.- Returns:
- The first edges between those two values in the graph. null if there are none.
-
getEdgesInDirection
- Specified by:
getEdgesInDirectionin classDiGraph<N,E>
-
isConnectedInDirection
DiGraphNode look ups can be expensive for a large graph operation, prefer the version below that takes DiGraphNodes, if you have them available.- Specified by:
isConnectedInDirectionin classDiGraph<N,E> - Parameters:
source- the source node from which we traverse outwardsdest- Node 2.- Returns:
trueif the graph contains edge from n1 to n2.
-
isConnectedInDirection
DiGraphNode look ups can be expensive for a large graph operation, prefer the version below that takes DiGraphNodes, if you have them available.- Specified by:
isConnectedInDirectionin classDiGraph<N,E> - Parameters:
source- the source node from which we traverse outwardsedgeValue- only edges equal to the given value will be traverseddest- Node 2.- Returns:
trueif the edge exists.
-
isConnectedInDirection
public boolean isConnectedInDirection(LinkedDirectedGraph.LinkedDiGraphNode<N, E> source, com.google.common.base.Predicate<E> edgeFilter, LinkedDirectedGraph.LinkedDiGraphNode<N, E> dest) DiGraphNode look ups can be expensive for a large graph operation, prefer this method if you have the DiGraphNodes available.- Parameters:
source- the source node from which we traverse outwardsedgeFilter- only edges matching this filter will be traverseddest- the destination node
-
getDirectedPredNodes
- Specified by:
getDirectedPredNodesin classDiGraph<N,E>
-
getDirectedPredNodes
public List<LinkedDirectedGraph.LinkedDiGraphNode<N,E>> getDirectedPredNodes(DiGraph.DiGraphNode<N, E> dNode) - Specified by:
getDirectedPredNodesin classDiGraph<N,E>
-
getDirectedSuccNodes
- Specified by:
getDirectedSuccNodesin classDiGraph<N,E>
-
getDirectedSuccNodes
public List<LinkedDirectedGraph.LinkedDiGraphNode<N,E>> getDirectedSuccNodes(DiGraph.DiGraphNode<N, E> dNode) - Specified by:
getDirectedSuccNodesin classDiGraph<N,E>
-
getGraphvizEdges
Description copied from interface:GraphvizGraphRetrieve a list of edges in the graph.- Specified by:
getGraphvizEdgesin interfaceGraphvizGraph- Returns:
- A list of edges in the graph.
-
getGraphvizNodes
Description copied from interface:GraphvizGraphRetrieve a list of nodes in the graph.- Specified by:
getGraphvizNodesin interfaceGraphvizGraph- Returns:
- A list of nodes in the graph.
-
getName
Description copied from interface:GraphvizGraphName of the graph.- Specified by:
getNamein interfaceGraphvizGraph- Returns:
- Name of the graph.
-
isDirected
public boolean isDirected()Description copied from interface:GraphvizGraphGraph type.- Specified by:
isDirectedin interfaceGraphvizGraph- Returns:
- True if the graph is a directed graph.
-
getNodeCount
public int getNodeCount()- Specified by:
getNodeCountin interfaceAdjacencyGraph<N,E> - Specified by:
getNodeCountin classGraph<N,E>
-
getNeighborNodes
Description copied from class:GraphGets the neighboring nodes.- Specified by:
getNeighborNodesin classGraph<N,E> - Parameters:
value- The node's value.- Returns:
- A list of neighboring nodes.
-
getNodeDegree
Description copied from class:GraphGets the degree of a node.- Specified by:
getNodeDegreein classGraph<N,E> - Parameters:
value- The node's value.- Returns:
- The degree of the node.
-