org.amino.ds.graph
Class UndirectedGraph<E>

java.lang.Object
  extended by org.amino.ds.graph.AbstractGraph<E>
      extended by org.amino.ds.graph.UndirectedGraph<E>
Type Parameters:
E - type of element inside the graph node
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, Graph<E>

public class UndirectedGraph<E>
extends AbstractGraph<E>

Undirected graph. In this graph, if there is an edge between node A and node B, we can traverse from A to B and from B to A. It's the same to say edge A-B or B-A. This graph doesn't allow duplicated key for all nodes. The constrain comes from internal structure contains a ConcurrentHashMap which uses indexed by key. The internal expression of graph is based on adjacent list. If we consider symmetric property of adjacent list expression, we can save half of the memory. But this trick will down grade time efficiency. We still store the complete adjacent list.

Author:
Zhi Gan

Constructor Summary
UndirectedGraph()
           
 
Method Summary
 boolean addEdge(Edge<E> edge)
          Add an edge to this graph.
 boolean addEdge(E start, E end, double weight)
          add one edge to graph.
 boolean addEdge(Node<E> start, Node<E> end, double weight)
          add one edge to graph with weight.
 Graph<E> clone()
          Clone this graph.
 boolean removeEdge(Edge<E> edge)
          remove all the edges which start from start and end to end.
 boolean removeEdge(E start, E end)
          remove all the edges which start from start and end to end.
 boolean removeEdge(Node<E> start, Node<E> end)
          remove all the edges which start from start and end to end.
 boolean removeNode(Node<E> node)
          remove the node from the graph.
 
Methods inherited from class org.amino.ds.graph.AbstractGraph
add, addAll, addAllNodes, addNode, addNode, clear, contains, containsAll, containsEdge, containsNode, dumpGraph, freeMultiOwnerShip, getAllNodes, getEdges, getEdges, getLinkedEdges, getLinkedNodes, getMultiOwnerShip, getNodes, isEmpty, iterator, remove, removeAll, retainAll, simpleContentionManager, simpleContentionManager, size, toArray, toArray
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

UndirectedGraph

public UndirectedGraph()
Method Detail

addEdge

public boolean addEdge(E start,
                       E end,
                       double weight)
add one edge to graph.

Parameters:
start - value in start node. A new node will be added to graph is this value is not in graph yet.
end - value in end node. A new node will be added to graph is this value is not in graph yet.
weight - weight of this edge
Returns:
true if the operation is successful

addEdge

public boolean addEdge(Node<E> start,
                       Node<E> end,
                       double weight)
add one edge to graph with weight.

Parameters:
start - start node. A new node will be added to graph is this value is not in graph yet.
end - end node. A new node will be added to graph is this value is not in graph yet.
weight - weight of this edge
Returns:
true if the operation is successful

addEdge

public boolean addEdge(Edge<E> edge)
Add an edge to this graph.

Parameters:
edge - adding edge
Returns:
true if succeed

removeEdge

public boolean removeEdge(Edge<E> edge)
remove all the edges which start from start and end to end.

Parameters:
edge - edge removed
Returns:
true if the operation is successful

removeEdge

public boolean removeEdge(Node<E> start,
                          Node<E> end)
remove all the edges which start from start and end to end.

Parameters:
start - start node
end - end node
Returns:
true if the operation is successful

removeEdge

public boolean removeEdge(E start,
                          E end)
remove all the edges which start from start and end to end.

Parameters:
start - start value
end - end value
Returns:
true if the operation is successful

removeNode

public boolean removeNode(Node<E> node)
remove the node from the graph.

Specified by:
removeNode in interface Graph<E>
Overrides:
removeNode in class AbstractGraph<E>
Parameters:
node - node removed
Returns:
true if the operation is successful

clone

public Graph<E> clone()
Clone this graph.

Specified by:
clone in interface Graph<E>
Specified by:
clone in class AbstractGraph<E>
Returns:
a graph


Copyright © 2008. All Rights Reserved.