public class HashMutableDirectedGraph<N> extends java.lang.Object implements MutableDirectedGraph<N>
Modifier and Type | Field and Description |
---|---|
protected java.util.Set<N> |
heads |
protected java.util.Map<N,java.util.Set<N>> |
nodeToPreds |
protected java.util.Map<N,java.util.Set<N>> |
nodeToSuccs |
protected java.util.Set<N> |
tails |
Constructor and Description |
---|
HashMutableDirectedGraph() |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(N from,
N to)
Adds an edge to the graph between 2 nodes.
|
void |
addNode(N node)
Adds a node to the graph.
|
void |
clearAll()
Removes all nodes and edges.
|
java.lang.Object |
clone() |
boolean |
containsEdge(N from,
N to) |
boolean |
containsNode(java.lang.Object node) |
java.util.List<N> |
getHeads()
Returns a list of entry points for this graph.
|
java.util.List<N> |
getNodes() |
java.util.List<N> |
getPredsOf(N s)
Returns a list of predecessors for the given node in the graph.
|
java.util.Set<N> |
getPredsOfAsSet(N s)
Same as
getPredsOf(Object) but returns a set. |
java.util.List<N> |
getSuccsOf(N s)
Returns a list of successors for the given node in the graph.
|
java.util.Set<N> |
getSuccsOfAsSet(N s)
Same as
getSuccsOf(Object) but returns a set. |
java.util.List<N> |
getTails()
Returns a list of exit points for this graph.
|
java.util.Iterator<N> |
iterator()
Returns an iterator for the nodes in this graph.
|
void |
printGraph() |
void |
removeEdge(N from,
N to)
Removes an edge between 2 nodes in the graph.
|
void |
removeNode(N node)
Removes a node from the graph.
|
int |
size()
Returns the node count for this graph.
|
public void clearAll()
public java.lang.Object clone()
clone
in class java.lang.Object
public java.util.List<N> getHeads()
DirectedGraph
getHeads
in interface DirectedGraph<N>
public java.util.List<N> getTails()
DirectedGraph
getTails
in interface DirectedGraph<N>
public java.util.List<N> getPredsOf(N s)
DirectedGraph
getPredsOf
in interface DirectedGraph<N>
public java.util.Set<N> getPredsOfAsSet(N s)
getPredsOf(Object)
but returns a set.
This is faster than calling getPredsOf(Object)
.
Also, certain operations like Collection.contains(Object)
execute faster on the set than on the list.
The returned set is unmodifiable.public java.util.List<N> getSuccsOf(N s)
DirectedGraph
getSuccsOf
in interface DirectedGraph<N>
public java.util.Set<N> getSuccsOfAsSet(N s)
getSuccsOf(Object)
but returns a set.
This is faster than calling getSuccsOf(Object)
.
Also, certain operations like Collection.contains(Object)
execute faster on the set than on the list.
The returned set is unmodifiable.public int size()
DirectedGraph
size
in interface DirectedGraph<N>
public java.util.Iterator<N> iterator()
DirectedGraph
iterator
in interface java.lang.Iterable<N>
iterator
in interface DirectedGraph<N>
public void addEdge(N from, N to)
MutableDirectedGraph
addEdge
in interface MutableDirectedGraph<N>
from
- out node for the edge.to
- in node for the edge.public void removeEdge(N from, N to)
MutableDirectedGraph
removeEdge
in interface MutableDirectedGraph<N>
from
- out node for the edge to remove.to
- in node for the edge to remove.public boolean containsEdge(N from, N to)
containsEdge
in interface MutableDirectedGraph<N>
public boolean containsNode(java.lang.Object node)
containsNode
in interface MutableDirectedGraph<N>
node
- node that we want to know if the graph constains.public java.util.List<N> getNodes()
getNodes
in interface MutableDirectedGraph<N>
public void addNode(N node)
MutableDirectedGraph
addNode
in interface MutableDirectedGraph<N>
node
- a node to add to the graph.DirectedGraph.getHeads()
,
DirectedGraph.getTails()
public void removeNode(N node)
MutableDirectedGraph
removeNode
in interface MutableDirectedGraph<N>
node
- the node to be removed.public void printGraph()