route

class route #(type T =  int) extends collection#( T )

Implements a route structure.

Parameter

Toptional The type of data collected in a route.  The default is int.
Summary
routeImplements a route structure.
Types
route_node_typeThe shorthand of the route_node type specialized with type T.
route_typeThe shorthand of the route type specialized with type T.
Properties
startThe starting node of the route.
Functions
newCreates a new route.
addvirtual Creates a new route_node of the given element and adds it to the start.
add_to_nodevirtual Creates a new route_node of the given element and adds it to the specified node.
connectvirtual Connects the given two route_nodes.
clearvirtual Removes all of the elements from this route.
clonevirtual Returns a shallow copy of this route.
is_emptyvirtual Returns 1 if this route contains no elements.
get_iteratorvirtual Returns an iterator over the elements in this route.
get_breadth_first_iteratorvirtual Returns a route_breadth_first_iterator over the elements in this route.
get_last_nodevirtual Returns the last route node in the breadth-first order.

Types

route_node_type

typedef route_node#(T) route_node_type

The shorthand of the route_node type specialized with type T.

route_type

typedef route#(T) route_type

The shorthand of the route type specialized with type T.

Properties

start

route_node_type start

The starting node of the route.

Functions

new

function new(collection#(T) c =  null,
comparator#(T) cmp =  null,
formatter#(T) fmtr =  null)

Creates a new route.

Argument

coptional A collection whose elements are to be added to this route.
cmpoptional A strategy object used to compare the elements of type T.  If not specified or null, comparator #(T) is used.  The default is null.
fmtroptional A strategy object that provides a function to convert the element of type T to a string.  If not specified or null, hex_formatter #(T) is used.  The default is null.

Example

route#(int) int_route = new();

add

virtual function bit add(e)

virtual Creates a new route_node of the given element and adds it to the start.  If the start is empty, make the newly created route_node as the starting node.

Argument

eAn element to be added to the start.

Returns

If this route changed as a result of the call, 1 is returned.  Otherwise, 0 is returned.

Example

route#(int) int_route = new();

assert( int_route.add( 123 ) );
// (123)
//   \__ starting node

assert( int_route.add( 234 ) );
// (123) ---- (234)

assert( int_route.add( 345 ) );
// (123) -+-- (234)
//        |
//        +-- (345)

add_to_node

virtual function route_node_type add_to_node(e,  
route_node_type node =  null)

virtual Creates a new route_node of the given element and adds it to the specified node.

Argument

eAn element to be added to the route.
nodeoptional The node the newly created route_node is connected to.  If the node is null, add the node to the start.  If the start is empty, make the newly created route_node as the starting node.  Default is null.

Returns

Newly added route_node.

Example

route#(int)      int_route = new();
route_node#(int) rn_123;
route_node#(int) rn_234;
route_node#(int) rn_345;

rn_123 = int_route.add_to_node( 123 );
// (123)
//   \__ starting node

rn_234 = int_route.add_to_node( 234, .node( rn_123 ) );
// (123) ---- (234)

rn_345 = int_route.add_to_node( 345, .node( rn_234 ) );
// (123) ---- (234) ---- (345)

connect

virtual function route_node_type connect(route_node_type from_node,
route_node_type to_node)

virtual Connects the given two route_nodes.

Argument

from_nodeA route node connected from.
to_nodeA route node connected to.

Returns

A route node connected to (to_node).

Example

route#(int)      int_route = new();
route_node#(int) rn;
route_node#(int) rn_123;
route_node#(int) rn_234;
route_node#(int) rn_345;
route_node#(int) rn_456;

rn_123 = int_route.add_to_node( 123 );
rn_234 = int_route.add_to_node( 234, .node( rn_123 ) );
// (123) ---- (234)
//              \__ rn_234

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

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

clear

virtual function void clear()

virtual Removes all of the elements from this route.

Returns

None.

Example

route#(int) int_route = new();

assert( int_route.add( 123 ) );
assert( int_route.add( 234 ) );
assert( int_route.size() == 2 );
int_route.clear();
assert( int_route.size() == 0 );

clone

virtual function collection#(T) clone()

virtual Returns a shallow copy of this route.  Only the start is copied.  The connected routes are not cloned.

Returns

A copy of this route.

Example

route#(int) int_route = new();
collection#(int) cloned;

assert( int_route.add( 123 ) );
assert( int_route.add( 234 ) );
cloned = int_route.clone();
assert( cloned.size() == 2 );

is_empty

virtual function bit is_empty()

virtual Returns 1 if this route contains no elements.

Returns

If this route contains no elements, returns 1.  Otherwise, returns 0.

Example

route#(int) int_route = new();

assert( int_route.add( 123 ) );
assert( int_route.add( 234 ) );
assert( int_route.is_empty() == 0 );

get_iterator

virtual function iterator#(T) get_iterator()

virtual Returns an iterator over the elements in this route.  This function is equivalent to get_breadth_first_iterator.

Returns

An iterator.

Example

route#(int)      int_route = new();
route_node#(int) rn_123;
route_node#(int) rn_234;
route_node#(int) rn_345;
route_node#(int) rn_456;
iterator#(int)  it;
string s;

rn_123 = int_route.add_to_node( 123 );
rn_234 = int_route.add_to_node( 234, .node( rn_123 ) );
rn_345 = int_route.add_to_node( 345, .node( rn_123 ) );
rn_456 = int_route.add_to_node( 456, .node( rn_234 ) );
// (123) -+-- (234) ---- (456)
//        |
//        +-- (345)

it = int_route.get_iterator();
while ( it.has_next() ) s = { s, $sformatf( "%0d ", it.next() ) };
assert( s == "123 234 345 456 " );

get_breadth_first_iterator

virtual function iterator#(T) get_breadth_first_iterator()

virtual Returns a route_breadth_first_iterator over the elements in this route.

Returns

An iterator.

Example

route#(int)      int_route = new();
route_node#(int) rn_123;
route_node#(int) rn_234;
route_node#(int) rn_345;
route_node#(int) rn_456;
iterator#(int)  it;
string s;

rn_123 = int_route.add_to_node( 123 );
rn_234 = int_route.add_to_node( 234, .node( rn_123 ) );
rn_345 = int_route.add_to_node( 345, .node( rn_123 ) );
rn_456 = int_route.add_to_node( 456, .node( rn_234 ) );
// (123) -+-- (234) ---- (456)
//        |
//        +-- (345)

it = int_route.get_breadth_first_iterator();
while ( it.has_next() ) s = { s, $sformatf( "%0d ", it.next() ) };
assert( s == "123 234 345 456 " );

get_last_node

virtual function route_node_type get_last_node()

virtual Returns the last route node in the breadth-first order.

Returns

The last node.  If the last route node does not exist, return null.

Example

route#(int) int_route = new();
assert( int_route.add( 123 ) );
assert( int_route.add( 234 ) );

assert( int_route.get_last_node().elem == 234 );
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.
class route_node #(type T =  int)
Implements a node of a route.
typedef route#(T) route_type
The shorthand of the route type specialized with type T.
route_node_type start
The starting node of the route.
function new(collection#(T) c =  null,
comparator#(T) cmp =  null,
formatter#(T) fmtr =  null)
Creates a new route.
virtual function bit add(e)
virtual Creates a new route_node of the given element and adds it to the start.
virtual function route_node_type add_to_node(e,  
route_node_type node =  null)
virtual Creates a new route_node of the given element and adds it to the specified node.
virtual function route_node_type connect(route_node_type from_node,
route_node_type to_node)
virtual Connects the given two route_nodes.
virtual function void clear()
virtual Removes all of the elements from this route.
virtual function collection#(T) clone()
virtual Returns a shallow copy of this route.
virtual function bit is_empty()
virtual Returns 1 if this route contains no elements.
virtual function iterator#(T) get_iterator()
virtual Returns an iterator over the elements in this route.
virtual function iterator#(T) get_breadth_first_iterator()
virtual Returns a route_breadth_first_iterator over the elements in this route.
class route_breadth_first_iterator #(type T =  int) extends iterator#( T )
Provides a breadth-first iterator to a route.
virtual function route_node_type get_last_node()
virtual Returns the last route node in the breadth-first order.
class comparator#(type T =  int)
singleton Provides strategies to compare objects.
class hex_formatter #(type T =  int) extends formatter#( T )
singleton Provides a strategy to convert an object of type T to a string using a hexadecimal format.