class route #( type T = int ) extends collection#( T )
Implements a route structure.
| T | optional The type of data collected in a route. The default is int. |
| route | Implements a route structure. |
| Types | |
| route_node_type | The shorthand of the route_node type specialized with type T. |
| route_type | The shorthand of the route type specialized with type T. |
| Properties | |
| start | The starting node of the route. |
| Functions | |
| new | Creates a new route. |
| add | virtual Creates a new route_node of the given element and adds it to the start. |
| add_to_node | virtual Creates a new route_node of the given element and adds it to the specified node. |
| connect | virtual Connects the given two route_nodes. |
| clear | virtual Removes all of the elements from this route. |
| clone | virtual Returns a shallow copy of this route. |
| is_empty | virtual Returns 1 if this route contains no elements. |
| get_iterator | virtual Returns an iterator over the elements in this route. |
| get_breadth_first_iterator | virtual Returns a route_breadth_first_iterator over the elements in this route. |
| get_last_node | virtual Returns the last route node in the breadth-first order. |
typedef route_node#( T ) route_node_type
The shorthand of the route_node type specialized with type T.
typedef route#( T ) route_type
The shorthand of the route type specialized with type T.
function new( collection#(T) c = null, comparator#(T) cmp = null, formatter#(T) fmtr = null )
Creates a new route.
| c | optional A collection whose elements are to be added to this route. |
| cmp | optional A strategy object used to compare the elements of type T. If not specified or null, comparator #(T) is used. The default is null. |
| fmtr | optional 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. |
route#(int) int_route = new();
virtual function bit add( T 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.
| e | An element to be added to the start. |
If this route changed as a result of the call, 1 is returned. Otherwise, 0 is returned.
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)
virtual function route_node_type add_to_node( T e, route_node_type node = null )
virtual Creates a new route_node of the given element and adds it to the specified node.
| e | An element to be added to the route. |
| node | optional 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. |
Newly added route_node.
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)
virtual function route_node_type connect( route_node_type from_node, route_node_type to_node )
virtual Connects the given two route_nodes.
| from_node | A route node connected from. |
| to_node | A route node connected to. |
A route node connected to (to_node).
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
virtual function collection#( T ) clone()
virtual Returns a shallow copy of this route. Only the start is copied. The connected routes are not cloned.
A copy of this route.
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 );
virtual function bit is_empty()
virtual Returns 1 if this route contains no elements.
If this route contains no elements, returns 1. Otherwise, returns 0.
route#(int) int_route = new(); assert( int_route.add( 123 ) ); assert( int_route.add( 234 ) ); assert( int_route.is_empty() == 0 );
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.
An iterator.
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 " );
virtual function iterator#( T ) get_breadth_first_iterator()
virtual Returns a route_breadth_first_iterator over the elements in this route.
An iterator.
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 " );
virtual function route_node_type get_last_node()
virtual Returns the last route node in the breadth-first order.
The last node. If the last route node does not exist, return null.
route#(int) int_route = new(); assert( int_route.add( 123 ) ); assert( int_route.add( 234 ) ); assert( int_route.get_last_node().elem == 234 );
Implements a route structure.
class route #( type T = int ) extends collection#( T )
The shorthand of the route_node type specialized with type T.
typedef route_node#( T ) route_node_type
Implements a node of a route.
class route_node #( type T = int )
The shorthand of the route type specialized with type T.
typedef route#( T ) route_type
The starting node of the route.
route_node_type start
Creates a new route.
function new( collection#(T) c = null, comparator#(T) cmp = null, formatter#(T) fmtr = null )
virtual Creates a new route_node of the given element and adds it to the start.
virtual function bit add( T e )
virtual Creates a new route_node of the given element and adds it to the specified node.
virtual function route_node_type add_to_node( T e, route_node_type node = null )
virtual Connects the given two route_nodes.
virtual function route_node_type connect( route_node_type from_node, route_node_type to_node )
virtual Removes all of the elements from this route.
virtual function void clear()
virtual Returns a shallow copy of this route.
virtual function collection#( T ) clone()
virtual Returns 1 if this route contains no elements.
virtual function bit is_empty()
virtual Returns an iterator over the elements in this route.
virtual function iterator#( T ) get_iterator()
virtual Returns a route_breadth_first_iterator over the elements in this route.
virtual function iterator#( T ) get_breadth_first_iterator()
Provides a breadth-first iterator to a route.
class route_breadth_first_iterator #( type T = int ) extends iterator#( T )
virtual Returns the last route node in the breadth-first order.
virtual function route_node_type get_last_node()
singleton Provides strategies to compare objects.
class comparator#( type T = int )
singleton Provides a strategy to convert an object of type T to a string using a hexadecimal format.
class hex_formatter #( type T = int ) extends formatter#( T )