route_node

class route_node #(type T =  int)

Implements a node of a route.

Parameter

Toptional The type of data collected in a route_node.  The default is int.
Summary
route_nodeImplements a node of a route.
Types
route_node_typeThe shorthand of the route node type specialized with type T.
Properties
idThe globally unique ID of this node.
elemThe element stored at this route node.
from_nodesThe nodes this node is connected from.
to_nodesThe nodes this node is connected to.
relativesThe route nodes this route node is related to.
Functions
newCreates a new route node.
addvirtual Creates a route node of the given element and adds it as a new to_nodes.
connectvirtual Connects the given route node (and its connections) as a new to_nodes.
disconnectvirtual Removes the specified route node (and its connections) from this node.
get_num_of_to_nodesvirtual Returns the number of to_nodes.
has_to_nodesvirtual Returns if this route node has at least one to_nodes.
get_indexvirtual Returns the index of the to_nodes this node is connected to, from the view point of the specified “from node”.

Types

route_node_type

typedef route_node#(T) route_node_type

The shorthand of the route node type specialized with type T.

Properties

id

int id

The globally unique ID of this node.

elem

T elem

The element stored at this route node.

from_nodes

route_node_type from_nodes[$]

The nodes this node is connected from.

+---------------+    +-----------+
| from_nodes[0] |--->|           |
+---------------+    |           |
+---------------+    |           |
| from_nodes[1] |--->| this node |
+---------------+    |           |
+---------------+    |           |
| from_nodes[2] |--->|           |
+---------------+    +-----------+

to_nodes

route_node_type to_nodes[$]

The nodes this node is connected to.

+-----------+    +-------------+
|           |--->| to_nodes[0] |
|           |    +-------------+
|           |    +-------------+
| this node |--->| to_nodes[1] |
|           |    +-------------+
|           |    +-------------+
|           |--->| to_nodes[2] |
+-----------+    +-------------+

relatives

route_node_type relatives[$]

The route nodes this route node is related to.  Usage of this property is up to the user.

Functions

new

function new(elem)

Creates a new route node.

Argument

elemData element stored at the route node.

Example

int i = 123;
route_node#(int) rn = new( i );

add

virtual function route_node_type add(e)

virtual Creates a route node of the given element and adds it as a new to_nodes.

Argument

eAn element to be added.

Returns

Newly added route node.

Example

route_node#(int) rn;
route_node#(int) rn_123 = new( 123 );

rn = rn_123.add( 234 );
// (123) ---- (234) <~~ rn

rn = rn_123.add( 345 );
// (123) -+-- (234)
//        |
//        +-- (345) <~~ rn

rn = rn_123.add( 456 ).add( 567 ); // chain
// (123) -+-- (234)
//        |
//        +-- (345)
//        |
//        +-- (456) ---- (567) <~~ rn

connect

virtual function route_node_type connect(route_node_type rn)

virtual Connects the given route node (and its connections) as a new to_nodes.

Argument

rnA route node to be connected.

Returns

A route node to be connected (rn).

Example

route_node#(int) rn_123;
route_node#(int) rn_234;
route_node#(int) rn_345;
route_node#(int) rn_456;
route_node#(int) rn;

rn_123 = new( 123 );
rn_234 = rn_123.add( 234 );
// (123) --- (234)
//             \__ rn_234

rn_345 = new( 345 );
rn_456 = rn_345.add( 456 );
// (345) ---- (456)
//   \__ rn_345

rn = rn_234.connect( rn_345 );
// (123) ---- (234) --- (345) ---- (456)
//                        \__ rn

disconnect

virtual function route_node_type disconnect(int index =  0)

virtual Removes the specified route node (and its connections) from this node.

Argument

indexoptional The index of the to_nodes.  The default is 0.  If the specified node does not exist, this function does nothing.

Returns

This route node.

Example

route_node#(int) rn;
route_node#(int) rn_123 = new( 123 );

rn = rn_123.add( 234 );
rn = rn_123.add( 456 ).add( 567 );
rn = rn_123.add( 345 );
// (123) -+-- (234)
//        |
//        +-- (456) ---- (567)
//        |
//        +-- (345)

rn = rn_123.disconnect( .index( 1 ) );
// (123) -+-- (234)
//        |
//        +-- (345)

get_num_of_to_nodes

virtual function int get_num_of_to_nodes()

virtual Returns the number of to_nodes.  This function does not count the number of connections recursively.

Returns

The number of to_nodes.

Example

route_node#(int) rn;
route_node#(int) rn_123 = new( 123 );

rn = rn_123.add( 234 );
rn = rn_123.add( 345 );
rn = rn_123.add( 456 ).add( 567 );
// (123) -+-- (234)
//        |
//        +-- (345)
//        |
//        +-- (456) ---- (567)

assert( rn_123.get_num_of_to_nodes() == 3 ); // not 4

has_to_nodes

virtual function bit has_to_nodes()

virtual Returns if this route node has at least one to_nodes.

Returns

If this tree node has at least one to_nodes, returns 1.  Otherwise, returns 0.

Example

route_node#(int) rn;
route_node#(int) rn_123 = new( 123 );

rn = rn_123.add( 234 );
rn = rn_123.add( 345 );
rn = rn_123.add( 456 ).add( 567 );
// (123) -+-- (234)
//        |
//        +-- (345)
//        |
//        +-- (456) ---- (567)

assert( rn_123.has_to_nodes() == 1 );

get_index

virtual function int get_index(int from_node_index)

virtual Returns the index of the to_nodes this node is connected to, from the view point of the specified “from node”.

Returns

The index of the to_nodes of the specified “from node”.  If the specified “from node” does not exist, returns -1.

Example

route_node#(int) from_node0 = new( 0 );
route_node#(int) from_node1 = new( 1 );
route_node#(int) to_node0   = new( 2 );
route_node#(int) to_node1   = new( 3 );
route_node#(int) this_node  = new( 4 );
route_node#(int) rn;

rn = from_node0.connect( this_node );
rn = from_node1.connect( to_node0  );
rn = from_node1.connect( to_node1  );
rn = from_node1.connect( this_node );

//  +---------------+                       +------+
//  | from_nodes[0] |------to_nodes[0]----->|      |
//  +---------------+                       |      |
//  +---------------+    +-------------+    |      |
//  | from_nodes[1] |--->| to_nodes[0] |    | this |
//  |               |    +-------------+    |      |
//  |               |    +-------------+    | node |
//  |               |--->| to_nodes[1] |    |      |
//  |               |    +-------------+    |      |
//  |               |------to_nodes[2]----->|      |
//  +---------------+                       +------+

assert( this_node.get_index( .from_node_index( 0 ) ) == 0 );
assert( this_node.get_index( .from_node_index( 1 ) ) == 2 );
class route_node #(type T =  int)
Implements a node of a route.
class route #(type T =  int) extends collection#( T )
Implements a route structure.
typedef route_node#(T) route_node_type
The shorthand of the route node type specialized with type T.
int id
The globally unique ID of this node.
T elem
The element stored at this route node.
route_node_type from_nodes[$]
The nodes this node is connected from.
route_node_type to_nodes[$]
The nodes this node is connected to.
route_node_type relatives[$]
The route nodes this route node is related to.
function new(elem)
Creates a new route node.
virtual function route_node_type add(e)
virtual Creates a route node of the given element and adds it as a new to_nodes.
virtual function route_node_type connect(route_node_type rn)
virtual Connects the given route node (and its connections) as a new to_nodes.
virtual function route_node_type disconnect(int index =  0)
virtual Removes the specified route node (and its connections) from this node.
virtual function int get_num_of_to_nodes()
virtual Returns the number of to_nodes.
virtual function bit has_to_nodes()
virtual Returns if this route node has at least one to_nodes.
virtual function int get_index(int from_node_index)
virtual Returns the index of the to_nodes this node is connected to, from the view point of the specified “from node”.