peersim.graph
Class BitMatrixGraph

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

public class BitMatrixGraph
extends java.lang.Object
implements Graph

This class implements a graph which uses a bitmatrix as inner representation of edges.


Constructor Summary
BitMatrixGraph(int n)
          Constructs a directed graph with the given number of nodes.
BitMatrixGraph(int n, boolean directed)
          Constructs an graph with the given number of nodes.
 
Method Summary
 boolean clearEdge(int i, int j)
          Removes given edge, returns true if it existed before.
 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 null always.
 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 null always
 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)
          Sets given edge, returns true if it did not exist before.
 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

BitMatrixGraph

public BitMatrixGraph(int n)
Constructs a directed graph with the given number of nodes. The graph has no edges initially. The graph is directed.

Parameters:
n - size of graph

BitMatrixGraph

public BitMatrixGraph(int n,
                      boolean directed)
Constructs an graph with the given number of nodes. The graph has no edges initially.

Parameters:
n - size of graph
directed - if true graph is directed
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)
Returns null always

Specified by:
getNode in interface Graph

getEdge

public java.lang.Object getEdge(int i,
                                int j)
Returns null always.

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)
Description copied from interface: Graph
Sets given edge, returns true if it did not exist before. If the graph is undirected, sets the edge (j,i) as well. Optional operation.

Specified by:
setEdge in interface Graph

clearEdge

public boolean clearEdge(int i,
                         int j)
Description copied from interface: Graph
Removes given edge, returns true if it existed before. If the graph is undirected, removes the edge (j,i) as well. Optional operation.

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