jclass
Class SyncSimpleGraph

java.lang.Object
  |
  +--jclass.SyncSimpleGraph

public class SyncSimpleGraph
extends java.lang.Object

Class that implements a simple graph providing primitives for node connection handling. The class is designed only for providing a PASIVE NODE solution, that is the nodes may not exist in reality all that we do here is to store and retrieve fast and syncronized connections between them, being able to also remove a node consistently from the 'mesh' by removing all the connections that imply that node. This class may be better called "connections container" because it simply just STORES the connection without bothering about nodes more than needed.
The graph allows also more connections between 2 nodes, with different or equal metrics. It really does not care whether one node is or not already connected to another. When a new connection request arrives in via .connect() then it just enters the data into the appropriate internal structs.

Written: Radu Sion
Version: 0.12 limited for overall testing
Source: SyncSimpleGraph.java

Visit Smart Software 

See Also:
SyncSimpleArray

Constructor Summary
SyncSimpleGraph(int maxnodes)
          Creating a new graph.
 
Method Summary
 void connect(int snode, int dnode, long metric, long rtime)
          Connects two (existing or not) nodes inside the graph.
 void disconnect(int snode, int dnode)
          Disables all connections between two nodes that match the given parameters.
 int getMaxNodes()
          Returns the maximum nodes number that can be handled by this graph This also means that there can be NO node with an id greater than this value, stored inside this graph.
 java.util.Vector inConnections(int node)
          Returns the incomming connections of a given node.
 int inConnectionsNumber(int node)
          Returns the number of incomming connections of a given node.
 java.util.Vector outConnections(int node)
          Returns the outgoing connections of a given node.
 int outConnectionsNumber(int node)
          Returns the number of outgoing connections of a given node.
void remove(int node)
          Removes a node from the graph by removing all the connections that contain that node integer number.
Devlp note: The respective slot is not deleted ! why should it be ?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncSimpleGraph

public SyncSimpleGraph(int maxnodes)
Creating a new graph. No parameter checkings are performed.
Parameters:
maxnodes - Maximum number of expected nodes inside the graph
Method Detail

getMaxNodes

public int getMaxNodes()
Returns the maximum nodes number that can be handled by this graph This also means that there can be NO node with an id greater than this value, stored inside this graph. Remember that the internal data representation is STATIC.

remove

public void remove(int node)
Removes a node from the graph by removing all the connections that contain that node integer number.
Devlp note: The respective slot is not deleted ! why should it be ?
Parameters:
node - Node to remove

connect

public void connect(int snode,
                    int dnode,
                    long metric,
                    long rtime)
Connects two (existing or not) nodes inside the graph. No parameter checkings are performed.
Parameters:
snode - Source Node of that connection
dnode - Destination Node of that connection
metric - Metric assigned to that connection

disconnect

public void disconnect(int snode,
                       int dnode)
Disables all connections between two nodes that match the given parameters. The order is important, that is only the connections with source node = snode and destination node = dnode will be taken into account.
Parameters:
snode - Source Node of the Connection to remove
dnode - Destination Node of the Connection to remove

outConnections

public java.util.Vector outConnections(int node)
Returns the outgoing connections of a given node.
Parameters:
node - Node to take into account
Returns:
Null in case of error, a Vector otherwise

outConnectionsNumber

public int outConnectionsNumber(int node)
Returns the number of outgoing connections of a given node.
Parameters:
node - Node to take into account
Returns:
Negative in case of error

inConnections

public java.util.Vector inConnections(int node)
Returns the incomming connections of a given node.
Parameters:
node - Node to take into account
Returns:
Null in case of error, a Vector otherwise

inConnectionsNumber

public int inConnectionsNumber(int node)
Returns the number of incomming connections of a given node.
Parameters:
node - Node to take into account
Returns:
Negative in case of error