class set #( type T = int ) extends set_base#( T )
Implements the set_base using an associative array.
| T | optional The type of data collected in a set. The default is int. |
| set | Implements the set_base using an associative array. |
| Functions | |
| new | Creates a new set. |
| add | virtual Adds the given element to this set if it is not already present. |
| clear | virtual Removes all of the elements from this set. |
| clone | virtual Returns a shallow copy of this set. |
| contains | virtual Returns 1 if this set contains the specified element. |
| is_empty | virtual Returns 1 if this set contains no elements. |
| get_iterator | virtual Returns an iterator over the elements in this set. |
| remove | virtual Removes the given element from this set if it is present. |
| size | virtual Returns the number of elements in this set. |
function new( collection#(T) c = null, comparator#(T) cmp = null, formatter#(T) fmtr = null )
Creates a new set.
| c | optional A collection whose elements are to be added to this set. |
| 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. |
set#(int) int_set = new();
virtual function bit add( T e )
virtual Adds the given element to this set if it is not already present.
| e | An element to be added to this set. |
If this set did not contain the given element, returns 1. Otherwise, returns 0.
set#(int) int_set = new(); assert( int_set.add( 123 ) == 1 ); assert( int_set.add( 123 ) == 0 ); // 123 is already in the set
virtual function bit contains( T e )
virtual Returns 1 if this set contains the specified element.
| e | An element to be checked. |
If this set contains e, returns 1. Otherwise, returns 0.
set#(int) int_set = new(); void'( int_set.add( 123 ) ); assert( int_set.contains( 123 ) == 1 ); assert( int_set.contains( 456 ) == 0 );
virtual function iterator#( T ) get_iterator()
virtual Returns an iterator over the elements in this set.
An iterator.
set#(int) int_set = new();
iterator#(int) it;
string s;
void'( int_set.add( 123 ) );
void'( int_set.add( 456 ) );
it = int_set.get_iterator();
while ( it.has_next() ) s = { s, $sformatf( "%0d ", it.next() ) };
assert( s == "123 456 " );
virtual function bit remove( T e )
virtual Removes the given element from this set if it is present.
| e | An element to remove. |
If e is removed, returns 1. Otherwise, returns 0.
set#(int) int_set = new(); void'( int_set.add( 123 ) ); assert( int_set.remove( 123 ) == 1 ); assert( int_set.remove( 123 ) == 0 ); // already removed
Implements the set_base using an associative array.
class set #( type T = int ) extends set_base#( T )
virtual Defines the core functionality of a set.
virtual class set_base #( type T = int ) extends collection#( T )
Creates a new set.
function new( collection#(T) c = null, comparator#(T) cmp = null, formatter#(T) fmtr = null )
virtual Adds the given element to this set if it is not already present.
virtual function bit add( T e )
virtual Removes all of the elements from this set.
virtual function void clear()
virtual Returns a shallow copy of this set.
virtual function collection#( T ) clone()
virtual Returns 1 if this set contains the specified element.
virtual function bit contains( T e )
virtual Returns 1 if this set contains no elements.
virtual function bit is_empty()
virtual Returns an iterator over the elements in this set.
virtual function iterator#( T ) get_iterator()
virtual Removes the given element from this set if it is present.
virtual function bit remove( T e )
virtual Returns the number of elements in this set.
virtual function int size()
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 )