Skip to content

Set

v2.2.0

Properties

  • Unordered.
  • Non-randomizable.
  • Element can be any scalar or aggregate of scalars.
  • Each element must be unique.
  • Can be nested by any collection types (e.g., array, list, map or set).

Declarations

v2.2.0

Not support yet

PSSGen: Not support chandle as data_type.

Set can be declared by following syntax:

set<data_type> identifier

1
2
3
4
5
6
set<bit [4] > nibbleSet;    //  nibbleSet: {}
set<int     > intSet   ;    //  intSet   : {}
set<bool    > boolSet  ;    //  boolSet  : {}
set<string  > stringSet;    //  stringSet: {}
set<float32 > floatSet ;    //  floatSet : {}
set<eSTR2NUM> enumSet  ;    //  enumSet  : {} (1)
  1. Assume defined enum type before
    1
    2
    3
    enum eSTR2NUM {
        ZERO, ONE, TWO
    };
    

Initialization Assignment

v2.2.0

PSSGen: Support bit, int, and string as element in initialization assignment.

Not support yet

PSSGen: Not support bool, enum, float32, float64, chandle, and struct as element in initialization assignment.

Set can be assigned at declaration; otherwise, it will be initialized to empty aggregate literal ({}).

1
2
3
4
5
6
set<bit [4] > nibbleSet = {4'b0001, 4'b0010};
set<int     > intSet    = {      1, 2      };
set<bool    > boolSet   = {  false, true   };
set<string  > stringSet = {    "1", "2"    };
set<float32 > floatSet  = {    1.0, 2.0    };
set<eSTR2NUM> enumSet   = {    ONE, TWO    };   // (1)!

  1. Assume defined enum type before
    1
    2
    3
    enum eSTR2NUM {
        ZERO, ONE, TWO
    };
    

Set Operators

Operator Description
= Create a copy of the set-type expression on the RHS and assigns it to the set on the LHS.
== Evaluetes to true if both sizes are equal and have exactly same elements.
!= Evaluetes to true whether both sizes are not equal or do not have exactly same elements.
in Evaluetes to true if element on LHS of in is exists in the set.
foreach Iterates over the set's elements.

Set Methods

Method Description
int size() Returns the number of elements in the set.
clear() Removes all elements from the set.
delete(data_type element) Remove the elements from the set.
insert(data_type element) Adds the element to the set.
list<data_type> to_list() Returns all elements to a list-type.

Assignment operator =

v2.2.0

PSSGen: Support bit, int, and string as element for assignment operator =.

Not support yet

PSSGen: Not support bool, enum, float32, float64, chandle, and struct as element for assignment operator =.

Create a copy of the set-type expression on the RHS and assigns it to the set on the LHS. Same elements in the RHS will be merged automatically and appear only once in the set.

1
2
3
4
set<int> intSet;

intSet = {1, 2};    //  intSet: {}     -> {1, 2}
intSet = {3, 3, 4}; //  intSet: {1, 2} -> {3, 4} (1)

  1. Same element will appear only once.
Note

Operator that modify contents can only be used within exec block or native function.

Equality operator ==

v2.2.0

Evaluetes to true if both sizes are equal and have exactly same elements.

set<int   > set_0 = { 1 ,  2      };
set<int   > set_1 = { 2 ,  1      };
set<int   > set_2 = { 1 ,  2 ,  3 };
set<string> set_3 = {"1", "2"     };

bit bitVal_0, bitVal_1, bitVal_2, bitVal_3;
if (set_0 == set_0) bitVal_0 = 1;   //  bitVal_0: 0 -> 1 (1)
if (set_0 == set_1) bitVal_1 = 1;   //  bitVal_1: 0 -> 1 (2)
if (set_0 == set_2) bitVal_2 = 1;   //  bitVal_2: 0 -> 0 (3)
if (set_0 == set_3) bitVal_3 = 1;   //  ILLEGAL (4)

  1. Equalize size and all elements.
  2. Equalize size and all elements in different order.
  3. Inequalize size.
  4. Different data_type are incomparable.

Warning

Different data_type of two sets should NOT be compared.

Inequality operator !=

v2.2.0

Evaluetes to true whether both sizes are not equal or do not have exactly same elements.

set<int   > set_0 = { 1 ,  2      };
set<int   > set_1 = { 2 ,  1      };
set<int   > set_2 = { 1 ,  2 ,  3 };
set<string> set_3 = {"1", "2"     };

bit bitVal_0, bitVal_1, bitVal_2, bitVal_3;
if (set_0 != set_0) bitVal_0 = 1;   //  bitVal_0: 0 -> 0 (1)
if (set_0 != set_1) bitVal_1 = 1;   //  bitVal_1: 0 -> 0 (2)
if (set_0 != set_2) bitVal_2 = 1;   //  bitVal_2: 0 -> 1 (3)
if (set_0 != set_3) bitVal_3 = 1;   //  bitVal_3: 0 -> 1 (4)

  1. Equalize size, and all elements.
  2. Equalize size, and all elements in different order.
  3. Inequalize size.
  4. Different data_type are incomparable.

Warning

Different data_type of two sets should NOT be compared.

Set membership operator in

v2.2.0

Not support yet

PSSGen: Not support float32, float64, and chandle as element.

Evaluetes to true if element on LHS of in is exists in the set.

1
2
3
4
5
6
set<int> intSet = {1, 2};

bit bitVal_0, bitVal_1, bitVal_2;
if ( 1  in intSet) bitVal_0 = 1;    //  bitVal_0: 0 -> 1
if ( 3  in intSet) bitVal_1 = 1;    //  bitVal_1: 0 -> 0
if ("1" in intSet) bitVal_2 = 1;    //  ILLEGAL (1)

  1. Different data_type between LHS of in and the set's element on RHS of in.

Warning

Data_type of element on LHS of in should be SAME as the set's element on RHS of in.

foreach statement

v2.2.0

Iterates over the set's elements.

Look at Procedural/foreach for more information.

1
2
3
4
5
6
set<int> intSet = {3, 4};
int intVal = 0;

foreach (i : intSet) {
    intVal = i;     //  intVal: 0 -> 3 -> 4 or 0 -> 4 -> 3
}

Warning

For set-type, index variable of foreach statament should NOT be used to specify set elements.

foreach (intSet[i]) {}  //  ILLEGAL


function int size()

v2.2.0

Returns the number of elements in the set.

1
2
3
set<int> intSet = {1, 2};

int intVal = intSet.size(); //  intVal: 0 -> 2

function void clear()

v2.2.0

Removes all elements from the set.

1
2
3
set<int> intSet = {1, 2};

intSet.clear(); // intSet: {1, 2} -> {}

Note

Method that modify contents can only be used within exec block or native function.

function void delete(data_type element)

v2.2.0

Removes the elements from the set.

1
2
3
4
5
set<int> intSet = {1, 2};

intSet.delete( 2 ); //  intSet: {1, 2} -> {1}
intSet.delete( 3 ); //  ILLEGAL (1)
intSet.delete("1"); //  ILLEGAL (2)

  1. The element is not exist in the set.
  2. Data-type of the element is not same as the set.

Warning

The element need to deleted should exists in the set.

Note

Different to list-type or map-type, delete(data_type element) of set-type will not return the element.

Note

Method that modify contents can only be used within exec block or native function.

function void insert(data_type element)

v2.2.0

PSSGen: Support bit, int, and string as element of insert().

Not support yet

PSSGen: Not support bool, enum, float32, float64, chandle, and struct as element of insert().

Adds the element to the set.

1
2
3
4
5
set<int> intSet = {1, 2};

intSet.insert( 3 ); //  intSet: {1, 2}    -> {1, 2, 3}
intSet.insert( 2 ); //  intSet: {1, 2, 3} -> {1, 2, 3}
intSet.insert("4"); //  ILLEGAL (1)

  1. Data-type of the element is not same as the set.
Note

Method that modify contents can only be used within exec block or native function.

function list<data_type> to_list()

v2.2.0

Returns all elements to a list-type.

1
2
3
set<int> intSet = {1, 2};

list<int> intList = intSet.to_list();   //  intList: {} -> {1, 2}


Last update: 2023-10-25
Created: 2023-10-19