peersim.graph
Class PrefixSubGraph

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

public class PrefixSubGraph
extends java.lang.Object
implements Graph

This class is an adaptor for representing special subgraphs of any graph. It can represent the subgraphs spanned by the nodes 0,...,i where i is less than or equal to n-1, the last node of the original graph. The underlying graph is stored by reference. This means that if the graph changes, then these changes will be reflected by this class as well. Besides, the size of the prefix can be changed at will at any time using setSize(int).


Constructor Summary
PrefixSubGraph(Graph g)
          Constructs an initially max size subgraph of g.
 
Method Summary
 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)
          Returns the edge in the original graph if both i and j are smaller than size().
 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 setEdge(int i, int j)
          not supported
 int setSize(int i)
          Sets the size of the subgraph.
 int size()
          The number of nodes in the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrefixSubGraph

public PrefixSubGraph(Graph g)
Constructs an initially max size subgraph of g. That is, the subgraph will contain all 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)
Returns the edge in the original graph if both i and j are smaller than size().

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

setSize

public int setSize(int i)
Sets the size of the subgraph. If i is negative, it is changed to 0 and if it is larger than the underlying graph size, it is changed to the underlying graph size (set at construction time).

Returns:
old size.