|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectchord.util.graph.AbstractGraph<Node>
chord.util.graph.MutableGraph<Node>
Node - The type of the graph's nodes.public class MutableGraph<Node>
Complete implementation of a mutable, unlabeled, directed graph with useful operations on it.
This class must be used by clients who wish to use both, the operations inherited by it (e.g., computing SCCs, ordering nodes in RPO, etc.) and the representation of the graph provided by it.
This class must be used regardless of whether the desired kind of unlabeled, directed graph is immutable or mutable. The appropriate interface must be used to convey these characteristics, namely:
IGraph for the immutable case, andIMutableGraph for the mutable case.
| Field Summary | |
|---|---|
protected java.util.Map<Node,java.util.Set<Node>> |
nodeToPreds
Map from each node in the graph to the set of all its immediate predecessors. |
protected java.util.Map<Node,java.util.Set<Node>> |
nodeToSuccs
Map from each node in the graph to the set of all its immediate successors. |
protected java.util.Set<Node> |
roots
Set of root nodes of the graph. |
| Fields inherited from class chord.util.graph.AbstractGraph |
|---|
cached |
| Constructor Summary | |
|---|---|
MutableGraph()
Constructs an empty mutable, unlabeled, directed graph. |
|
MutableGraph(IGraph<Node> graph)
Constructs a mutable, unlabeled directed graph as a copy of the specified graph. |
|
MutableGraph(java.util.Set<Node> roots,
java.util.Map<Node,java.util.Set<Node>> nodeToPreds,
java.util.Map<Node,java.util.Set<Node>> nodeToSuccs)
Constructs a mutable, unlabeled, directed graph with the provided roots, nodes, and edges. |
|
| Method Summary | |
|---|---|
boolean |
bypassNode(Node v)
Removes a given node from the graph while preserving edges incident upon it. |
void |
computeTransitiveClosure()
Computes the transitive closure of the graph. |
java.util.Set<Node> |
getNodes()
Provides all nodes in this graph. |
java.util.Set<Node> |
getPreds(Node node)
Provides all immediate predecessors of a given node in this graph. |
java.util.Set<Node> |
getRoots()
Provides all root nodes of this graph. |
java.util.Set<Node> |
getSuccs(Node node)
Provides all immediate successors of a given node in this graph. |
boolean |
hasEdge(Node node1,
Node node2)
Determines whether this graph contains a given directed edge. |
boolean |
hasNode(Node node)
Determines whether this graph contains a given node. |
boolean |
hasRoot(Node node)
Determines whether this graph contains a given node as a root node. |
boolean |
insertEdge(Node u,
Node v)
Inserts a given directed edge into the graph, also inserting the nodes of the edge if they do not exist in the graph. |
boolean |
insertEdgeStrict(Node u,
Node v)
Inserts a given directed edge into the graph, presuming that the nodes of the edge exist in the graph. |
boolean |
insertNode(Node v)
Inserts a given node as a non-root node into the graph. |
boolean |
insertRoot(Node v)
Inserts a given node as a root node into the graph. |
boolean |
insertRootStrict(Node v)
Designates a given node in the graph as a root node. |
int |
numNodes()
Provides the total number of nodes in this graph. |
int |
numPreds(Node node)
Provides the number of immediate predecessors of a given node in this graph. |
int |
numRoots()
Provides the total number of roots of this graph. |
int |
numSuccs(Node node)
Provides the number of immediate successors of a given node in this graph. |
boolean |
removeEdge(Node u,
Node v)
Removes a given directed edge from the graph. |
boolean |
removeNode(Node v)
Removes a given node from the graph along with edges incident upon it. |
boolean |
removeRootStrict(Node v)
Designates a given node in the graph as a non-root node. |
boolean |
replaceNode(Node oldNode,
Node newNode)
Replaces a given node in the graph by another given node. |
void |
union(IGraph<Node> that)
Computes the union of this graph with a given directed graph, and updates this graph with the result. |
void |
validate()
|
| Methods inherited from class chord.util.graph.AbstractGraph |
|---|
equals, evictCache, getAllPathsBuilder, getBackEdges, getNodeMap, getNodesInCycles, getNodesInRPO, getShortestPathsBuilder, getSimpleCycles, getTopSortedSCCs, hasCycles, hashCode, isConnected, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface chord.util.graph.IGraph |
|---|
getAllPathsBuilder, getBackEdges, getNodeMap, getNodesInCycles, getNodesInRPO, getShortestPathsBuilder, getSimpleCycles, getTopSortedSCCs, hasCycles, isConnected |
| Field Detail |
|---|
protected java.util.Set<Node> roots
protected java.util.Map<Node,java.util.Set<Node>> nodeToPreds
protected java.util.Map<Node,java.util.Set<Node>> nodeToSuccs
| Constructor Detail |
|---|
public MutableGraph()
public MutableGraph(IGraph<Node> graph)
public MutableGraph(java.util.Set<Node> roots,
java.util.Map<Node,java.util.Set<Node>> nodeToPreds,
java.util.Map<Node,java.util.Set<Node>> nodeToSuccs)
If both maps nodeToPreds and nodeToSuccs are null, then an empty graph is constructed.
If both maps nodeToPreds and nodeToSuccs are non-null, then they are checked for consistency, namely, node1 must be specified as an immediate predecessor of node2 in map nodeToPreds iff node2 is specified as an immediate successor of node1 in map nodeToSuccs.
If map nodeToPreds is non-null, then the following three conditions must hold:
If map nodeToSuccs is non-null, then the following three conditions must hold:
roots - A set of nodes designated as roots of
the graph.
It may be null, in which case every node in the
graph is treated as a root node.nodeToPreds - A map from each node in the graph to
the set of all its immediate predecessor nodes.
It may be null.nodeToSuccs - A map from each node in the graph to
the set of all its immediate successor nodes.
It may be null.| Method Detail |
|---|
public int numRoots()
IGraph
numRoots in interface IGraph<Node>public int numNodes()
IGraph
numNodes in interface IGraph<Node>public int numPreds(Node node)
IGraph
numPreds in interface IGraph<Node>node - A node.
public int numSuccs(Node node)
IGraph
numSuccs in interface IGraph<Node>node - A node.
public boolean hasRoot(Node node)
IGraph
hasRoot in interface IGraph<Node>node - A node.
public boolean hasNode(Node node)
IGraph
hasNode in interface IGraph<Node>node - A node.
public boolean hasEdge(Node node1,
Node node2)
IGraph
hasEdge in interface IGraph<Node>node1 - A node.node2 - A node.
public java.util.Set<Node> getRoots()
IGraph
getRoots in interface IGraph<Node>public java.util.Set<Node> getNodes()
IGraph
getNodes in interface IGraph<Node>public java.util.Set<Node> getPreds(Node node)
IGraph
getPreds in interface IGraph<Node>node - A node.
public java.util.Set<Node> getSuccs(Node node)
IGraph
getSuccs in interface IGraph<Node>node - A node.
public boolean insertNode(Node v)
IMutableGraph
insertNode in interface IMutableGraph<Node>v - The node to be inserted.
public boolean insertRoot(Node v)
IMutableGraph
insertRoot in interface IMutableGraph<Node>v - The node to be inserted.
public boolean insertRootStrict(Node v)
IMutableGraph
insertRootStrict in interface IMutableGraph<Node>v - A node in the graph.
public boolean bypassNode(Node v)
IMutableGraph1. for each immed. pred. node1 of node: edge (node1,node) 2. for each immed. succ. node2 of node: edge (node,node2)This operation inserts the following edges into the graph:
for each immed. pred. node1 of node such that node1 != node:
for each immed. succ. node2 of node such that node2 != node:
edge (node1,node2)
Moreover, if node is a root node, then each of its
immediate successors is designated a root node.
bypassNode in interface IMutableGraph<Node>v - The node to be removed.
IMutableGraph.removeNode(Node)public boolean removeRootStrict(Node v)
IMutableGraph
removeRootStrict in interface IMutableGraph<Node>v - A node in the graph.
public boolean removeNode(Node v)
IMutableGraph
removeNode in interface IMutableGraph<Node>v - A node.
IMutableGraph.bypassNode(Node)
public boolean replaceNode(Node oldNode,
Node newNode)
IMutableGraph
replaceNode in interface IMutableGraph<Node>oldNode - The old node.newNode - The new node.
public boolean insertEdge(Node u,
Node v)
IMutableGraph
insertEdge in interface IMutableGraph<Node>u - The source node of the edge to be inserted.v - The target node of the edge to be inserted.
public boolean insertEdgeStrict(Node u,
Node v)
IMutableGraph
insertEdgeStrict in interface IMutableGraph<Node>u - The source node of the edge to be inserted.v - The target node of the edge to be inserted.
public boolean removeEdge(Node u,
Node v)
IMutableGraph
removeEdge in interface IMutableGraph<Node>u - The source node of the edge to be removed.v - The target node of the edge to be removed.
public void computeTransitiveClosure()
computeTransitiveClosure in interface IMutableGraph<Node>public void union(IGraph<Node> that)
IMutableGraph
union in interface IMutableGraph<Node>that - A directed graph.
It must be non-null.public void validate()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||