|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectGraph.Graph
Graph.AdjListsGraph
public class AdjListsGraph
This is a graph implementation that uses adjacency lists to store edges. It contains two linked-lists for every node i of the graph. The first list for node i, the "from i" list, contains edges from i to other nodes. The second list for node i, the "to i" list, contains edges from other nodes to i. The lists are not sorted; they contain the adjacent nodes in the order of edge insertion. In other words, the edge at the tail of the "from i" list of some node i corresponds to the edge *with source* i that was added to the graph most recently (and has not been removed, yet) and the edge at the tail of the "to i" list of some node i corresponds to the edge *with target* i that was added to the graph most recently (and has not been removed, yet).
Field Summary | |
---|---|
protected java.util.Vector<java.util.LinkedList<Edge>> |
fromLists
The vector of "from i" adjacency lists. |
protected java.util.Vector<java.util.LinkedList<Edge>> |
toLists
The vector of "to i" adjacency lists. |
Fields inherited from class Graph.Graph |
---|
nNodes |
Constructor Summary | |
---|---|
AdjListsGraph()
Empty class constructor. |
|
AdjListsGraph(int nodes)
Class Constructor. |
Method Summary | |
---|---|
boolean |
addEdge(Edge e)
This is method adds safely an edge to the graph, when the edge is given as an object. |
boolean |
addEdgeUnsafely(Edge e)
This is method adds an edge to the graph, when the edge is given as an object. |
java.util.LinkedList<Edge> |
getEdges(int i)
This is method returns the edges starting from a source node. |
java.util.LinkedList<Edge> |
getEdges(int source,
int target)
This is method returns the edges between a source node and a target node. |
void |
removeAllEdges()
This method removes all edges in the graph. |
boolean |
removeEdge(Edge e)
This method removes an edge given as an object. |
Graph |
toAltGraphRepr(Graph g)
If G has the same number of nodes as this graph then the method copies this graph to graph G. |
java.lang.String |
toString()
|
Methods inherited from class Graph.Graph |
---|
getNNodes |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Vector<java.util.LinkedList<Edge>> fromLists
protected java.util.Vector<java.util.LinkedList<Edge>> toLists
Constructor Detail |
---|
public AdjListsGraph()
public AdjListsGraph(int nodes)
nodes
- the number of nodes.Method Detail |
---|
public boolean addEdge(Edge e)
Graph
addEdge
in class Graph
e
- the edge to be added.
public boolean addEdgeUnsafely(Edge e)
Graph
addEdgeUnsafely
in class Graph
e
- the edge to be added.
public java.util.LinkedList<Edge> getEdges(int source, int target)
Graph
getEdges
in class Graph
source
- the source node.target
- the target node.
public java.util.LinkedList<Edge> getEdges(int i)
Graph
getEdges
in class Graph
i
- the source node.
public boolean removeEdge(Edge e)
Graph
removeEdge
in class Graph
e
- the edge to remove.
public void removeAllEdges()
Graph
removeAllEdges
in class Graph
public java.lang.String toString()
toString
in class java.lang.Object
public Graph toAltGraphRepr(Graph g)
Graph
toAltGraphRepr
in class Graph
g
- the graph to copy this graph to.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |