peersim.graph
Interface Graph

All Known Implementing Classes:
BitMatrixGraph, ConstUndirGraph, FastUndirGraph, NeighbourListGraph, OverlayGraph, PrefixSubGraph, SubGraphEdges, UndirectedGraph

public interface Graph

A general graph interface. It follows the following model: the graph has n nodes which are indexed from 0 to n-1. The parameters of operators refer to indices only. Implementations might return objects that represent the nodes or edges, although this is not required. Undirected graphs are modelled by the interface as directed graphs in which every edge (i,j) has a corresponding reverse edge (j,i).


Method Summary
abstract  boolean clearEdge(int i, int j)
          Removes given edge, returns true if it existed before.
abstract  int degree(int i)
          Returns the degree of the given node.
abstract  boolean directed()
          Returns true if the graph is directed otherwise false.
abstract  java.lang.Object getEdge(int i, int j)
          Returns the edge object associated with the index.
abstract  java.util.Collection<java.lang.Integer> getNeighbours(int i)
          Returns a collection view to all outgoing edges from i.
abstract  java.lang.Object getNode(int i)
          Returns the node object associated with the index.
abstract  boolean isEdge(int i, int j)
          Returns true if there is a directed edge between node i and node j.
abstract  boolean setEdge(int i, int j)
          Sets given edge, returns true if it did not exist before.
abstract  int size()
          The number of nodes in the graph.
 

Method Detail

isEdge

boolean isEdge(int i,
               int j)
Returns true if there is a directed edge between node i and node j.


getNeighbours

java.util.Collection<java.lang.Integer> getNeighbours(int i)
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.


getNode

java.lang.Object getNode(int i)
Returns the node object associated with the index. Optional operation.


getEdge

java.lang.Object getEdge(int i,
                         int j)
Returns the edge object associated with the index. Optional operation.


size

int size()
The number of nodes in the graph.


directed

boolean directed()
Returns true if the graph is directed otherwise false.


setEdge

boolean setEdge(int i,
                int j)
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.


clearEdge

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


degree

int degree(int i)
Returns the degree of the given node. If the graph is directed, returns out degree.