public class Graph
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
edgeModCount |
protected int |
nodeModCount |
protected int |
removingEdge |
protected int |
removingNode |
protected int |
revRootEdgeModCount |
protected int |
rootEdgeModCount |
| Constructor and Description |
|---|
Graph()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEdge(GraphNode v,
GraphNode w)
Adds a directed edge from node v to node w.
|
void |
addNode(java.lang.Object key,
GraphNode node)
Insertes a node (and its associated key) into this Graph.
|
GraphNode |
getNode(java.lang.Object key)
Returns the node in this Graph with a given key.
|
boolean |
hasEdge(GraphNode v,
GraphNode w)
Searches this Graph for an (directed) edge between two GraphNodes.
|
boolean |
hasNode(GraphNode v)
Searchs this Graph for a given GraphNode.
|
boolean |
isAncestorToDescendent(GraphNode v,
GraphNode w)
Determines whether or not a node v is an ancestor (has a lower pre-order
index and a higher post-order index) of a node w.
|
java.util.Set |
keySet()
Returns a Set of the keys used to uniquely identify the nodes in this
Graph.
|
java.util.Collection |
nodes()
Returns all the nodes in this Graph.
|
java.util.List |
postOrder()
Return the nodes in this Graph ordered by their post-order index.
|
int |
postOrderIndex(GraphNode node)
Returns the index of a given node in a post-order ordering of this Graph.
|
java.util.Collection |
preds(GraphNode v)
Returns the predacessors of a given node.
|
java.util.List |
preOrder()
Returns the nodes in this Graph ordered by their pre-order index.
|
int |
preOrderIndex(GraphNode node)
Returns the index of a given node in a pre-order ordering of this Graph.
|
void |
removeEdge(GraphNode v,
GraphNode w) |
void |
removeNode(java.lang.Object key)
Removes a node with a given key from the Graph.
|
void |
removeUnreachable()
Removes all nodes from this Graph that cannot be reached in a pre-order
traversal of the Graph.
|
java.util.Collection |
reverseRoots() |
java.util.Collection |
roots() |
int |
size()
Returns the number of nodes in this Graph.
|
java.util.Collection |
succs(GraphNode v)
Return the successors of a given node.
|
java.lang.String |
toString() |
protected int rootEdgeModCount
protected int revRootEdgeModCount
protected int nodeModCount
protected int edgeModCount
protected int removingNode
protected int removingEdge
public java.util.Collection roots()
public java.util.Collection reverseRoots()
public java.util.Collection succs(GraphNode v)
public java.util.Collection preds(GraphNode v)
public boolean isAncestorToDescendent(GraphNode v, GraphNode w)
v - Candidate ancestor node.w - Candidate descendent node.public int preOrderIndex(GraphNode node)
public int postOrderIndex(GraphNode node)
public java.util.List preOrder()
public java.util.List postOrder()
public void removeUnreachable()
public void addNode(java.lang.Object key,
GraphNode node)
key - A unique value associated with this node. For instance, if
this Graph represented a control flow graph, the key would be
a basic block.node - The node to be added.public GraphNode getNode(java.lang.Object key)
public java.util.Set keySet()
public void removeNode(java.lang.Object key)
key - The key associated with the node to remove.public void addEdge(GraphNode v, GraphNode w)
v - Source node.w - Destination node.public java.lang.String toString()
toString in class java.lang.Objectpublic boolean hasNode(GraphNode v)
v - GraphNode to search for.public boolean hasEdge(GraphNode v, GraphNode w)
v - Source node of desired edge.w - Destination node of desired edge.public java.util.Collection nodes()
public int size()