Set
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
orset
).
Declarations
Set can be declared by following syntax:
set<data_type> identifier
- Assume defined enum type before
Initialization Assignment
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 ({}
).
- Assume defined enum type before
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 =
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.
- Same element will appear only once.
Note
Operator that modify contents can only be used within exec
block or native function
.
Equality operator ==
Evaluetes to true if both sizes are equal and have exactly same elements.
- Equalize size and all elements.
- Equalize size and all elements in different order.
- Inequalize size.
- Different data_type are incomparable.
Warning
Different data_type of two sets should NOT be compared.
Inequality operator !=
Evaluetes to true whether both sizes are not equal or do not have exactly same elements.
- Equalize size, and all elements.
- Equalize size, and all elements in different order.
- Inequalize size.
- Different data_type are incomparable.
Warning
Different data_type of two sets should NOT be compared.
Set membership operator in
Evaluetes to true if element on LHS of in
is exists in the set.
- Different data_type between LHS of
in
and the set's element on RHS ofin
.
Warning
Data_type of element on LHS of in
should be SAME as the set's element on RHS of in
.
foreach
statement
Iterates over the set's elements.
Look at Procedural/foreach
for more information.
Warning
For set
-type, index variable of foreach
statament should NOT be used to specify set
elements.
function int size()
Returns the number of elements in the set.
function void clear()
Removes all elements from the set.
Note
Method that modify contents can only be used within exec
block or native function
.
function void delete(data_type element)
Removes the elements from the set.
- The element is not exist in the set.
- 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)
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element of insert()
.
Adds the element to the set.
- 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()
Returns all elements to a list
-type.
Created: 2023-10-19