List
Properties
- Ordered by index.
- Randomizable when its data_type is randomizable (e.g., randomizable scalar or aggregate of randomizable scalar).
- Element and data_type can be any scalar or aggregate of scalar.
- Index must be non-negative integer.
- Can be nested by any collection types (e.g.,
array
,list
,map
orset
).
Declarations
List can be declared by following syntax:
list<data_type> identifier
-
Assume defined enum type before
-
Assume defined struct type before
Declare list by rand
keyword
Initialization Assignment
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element in initialization assignment.
List can be assigned at declaration; otherwise, it will be initialized to empty aggregate literal ({}
).
List Operators
Operator | Description |
---|---|
[] |
Used to access a specific element of a list by given index, which must be a non-negative integer. |
= |
Create a copy of the list -type expression on the RHS and assigns it to the list on the LHS. |
== |
Evaluates to true if both sizes are equal and all elements with corresponding indexes are equal. |
!= |
Evaluates to true whether both sizes are not equal or if any element with corresponding index is not equal. |
in |
Evaluates to true if element on the LHS of in is exists in the list. |
foreach |
Iterates over the list's elements. |
List Methods
Method | Description |
---|---|
int size() |
Returns the number of elements in the list. |
clear() |
Removes all elements from the list. |
<data_type> delete(int index) |
Moves out the element at the specified index, which must be a non-negative integer. |
insert(int index, data_type element) |
Adds the element to the specified index, and all elements at and beyond the index are moved by one. |
<data_type> pop_front() |
Moves out the first element from the list. Same as delete(0) . |
push_front(data_type element) |
Adds the element to the beginning of the list. Same as insert(0, element) . |
<data_type> pop_back() |
Moves out the last element from the list. Same as delete(size()-1) . |
push_back(data_type element) |
Adds the element to the end of the list. Same as insert(size()-1, element) . |
set<data_type> to_set() |
Returns all elements to a set -type. |
shuffle() v2.3.0 v2.1 |
Randomizes orders of elements. |
Index operator []
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element for index operator []
.
Used to access a specific element of a list by given index, which must be a non-negative integer.
- The index is out of bounds.
Warning
Index should smaller than size()
of the list.
Assignment operator =
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element for assignment operator =
.
Create a copy of the list
-type expression on the RHS and assigns it to the list on the LHS.
Note
Operator that modify contents can only be used within exec
block or native function
.
Equality operator ==
Evaluates to true if both sizes are equal and all elements with corresponding indexes are equal.
- Equalize size and all elements with corresponding indexes.
- Inequalize size.
- Different data_type are incomparable.
Warning
Different data_type of two lists should NOT be compared.
Inequality operator !=
Evaluates to true whether both sizes are not equal or if any element with corresponding index is not equal.
- Equalize size and all elements with corresponding indexes.
- Inequalize size.
- Different data_type are incomparable.
Warning
Different data_type of two lists should NOT be compared.
Set membership operator in
Evaluates to true if element on the LHS of in
is exists in the list.
- Different data_type between LHS of
in
and the list's element on RHS ofin
.
Warning
Data_type of element on LHS of in
should be SAME as the list's element on RHS of in
.
foreach
statement
Iterates over the list's elements.
Look at Procedural/foreach
for more information.
function int size()
Returns the number of elements in the list.
function void clear()
Removes all elements from the list.
Note
Method that modify contents can only be used within exec
block or native function
.
function <data_type> delete(index)
Moves out the element at the specified index, which must be a non-negative integer.
- The index is out of bounds.
Warning
The index must be smaller than size()
of the list.
Note
Method that modify contents can only be used within exec
block or native function
.
function void insert(index, element)
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element of insert()
.
Adds the element to the specified index, and all elements at and beyond the index are moved by one.
- The index is larger than
size()
of the list. - The data_type of elements are not the same.
Warning
The index should NOT larger than size()
of the list.
Note
Method that modify contents can only be used within exec
block or native function
.
function <data_type> pop_front()
Moves out the first element from the list. Same as delete(0)
.
Note
Method that modify contents can only be used within exec
block or native function
.
function void push_front(element)
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element of push_front()
.
Adds the element to the beginning of the list. Same as insert(0, element)
.
Note
Method that modify contents can only be used within exec
block or native function
.
function <data_type> pop_back()
Moves out the last element from the list. Same as delete(size()-1)
.
Note
Method that modify contents can be used within exec
block or native function
.
function void push_back(element)
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as element of push_back()
.
Adds the element to the end of the list. Same as insert(size()-1, element)
.
Note
Method that modify contents can only be used within exec
block or native function
.
function set<data_type> to_set()
Returns all elements to a set
-type.
function void shuffle()
Randomizes orders of elements.
Note
Method that modify contents can only be used within exec
block or native function
.
Usage: use shuffle()
to generate a unique random array
While unique
become larger, the random solver can't solved within a limit iteration. Using shuffle()
and repeat()
can generate unique element for each variable.
Created: 2023-10-13