peersim.graph
Class SubGraphEdges

java.lang.Object
  extended by peersim.graph.SubGraphEdges
All Implemented Interfaces:
Graph

public class SubGraphEdges
extends java.lang.Object
implements Graph

This class is an adaptor for representing subgraphs of any graph. The subgraph is defined the following way. The subgraph always contains all the nodes of the original underlying graph. However, it is possible to remove edges by flagging nodes as removed, in which case the edges that have at least one end on those nodes are removed. If the underlying graph changes after initialization, this class follows the change.


Constructor Summary
SubGraphEdges(Graph g)
          Constructs an initially empty subgraph of g.
 
Method Summary
 boolean addNode(int i)
          Adds given node to subgraph.
 boolean clearEdge(int i, int j)
          not supported
 int degree(int i)
          Returns the degree of the given node.
 boolean directed()
          Returns true if the graph is directed otherwise false.
 java.lang.Object getEdge(int i, int j)
          If both i and j are within the node set of the subgraph and the original graph has an (i,j) edge, returns that edge.
 java.util.Collection<java.lang.Integer> getNeighbours(int i)
          Returns a collection view to all outgoing edges from i.
 java.lang.Object getNode(int i)
          Returns the node object associated with the index.
 boolean isEdge(int i, int j)
          Returns true if there is a directed edge between node i and node j.
 boolean removeNode(int i)
          Removes given node from subgraph.
 boolean setEdge(int i, int j)
          not supported
 int size()
          The number of nodes in the graph.
 int subGraphSize()
          This function returns the size of the subgraph, i.e. the number of nodes in the subgraph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubGraphEdges

public SubGraphEdges(Graph g)
Constructs an initially empty subgraph of g. That is, the subgraph will contain no nodes.

Method Detail

isEdge

public boolean isEdge(int i,
                      int j)
Description copied from interface: Graph
Returns true if there is a directed edge between node i and node j.

Specified by:
isEdge in interface Graph

getNeighbours

public java.util.Collection<java.lang.Integer> getNeighbours(int i)
Description copied from interface: Graph
Returns a collection view to all outgoing edges from i. The collection should ideally be unmodifiable. In any case, modifying the returned collection is not safe and may result in unspecified behavior.

Specified by:
getNeighbours in interface Graph

getNode

public java.lang.Object getNode(int i)
Description copied from interface: Graph
Returns the node object associated with the index. Optional operation.

Specified by:
getNode in interface Graph

getEdge

public java.lang.Object getEdge(int i,
                                int j)
If both i and j are within the node set of the subgraph and the original graph has an (i,j) edge, returns that edge.

Specified by:
getEdge in interface Graph

size

public int size()
Description copied from interface: Graph
The number of nodes in the graph.

Specified by:
size in interface Graph

directed

public boolean directed()
Description copied from interface: Graph
Returns true if the graph is directed otherwise false.

Specified by:
directed in interface Graph

setEdge

public boolean setEdge(int i,
                       int j)
not supported

Specified by:
setEdge in interface Graph

clearEdge

public boolean clearEdge(int i,
                         int j)
not supported

Specified by:
clearEdge in interface Graph

degree

public int degree(int i)
Description copied from interface: Graph
Returns the degree of the given node. If the graph is directed, returns out degree.

Specified by:
degree in interface Graph

subGraphSize

public int subGraphSize()
This function returns the size of the subgraph, i.e. the number of nodes in the subgraph.


removeNode

public boolean removeNode(int i)
Removes given node from subgraph.

Returns:
true if the node was already in the subgraph otherwise false.

addNode

public boolean addNode(int i)
Adds given node to subgraph.

Returns:
true if the node was already in the subgraph otherwise false.