Map
Properties
- Unordered.
- Non-randomizable.
- Key, element and data_type can be any scalar or aggregate of scalars.
- Each key must be unique.
- Can be nested by any collection types (e.g.,
array
,list
,map
orset
).
Declarations
Map can be declared by following syntax:
map<data_type, data_type> identifier
- Assume defined enum type before
Initialization Assignment
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as key or element in initialization assignment.
Map can be assigned at declaration; otherwise, it will be initialized to empty aggregate literal ({}
).
- Assume defined enum type before
Map Operators
Operator | Description |
---|---|
[] |
Used to access a specific element of a map by given key. |
= |
Create a copy of the map -type expression on the RHS and assigns it to the map on the LHS. |
== |
Evaluates to true if both sizes are equal and all elements with corresponding keys are equal. |
!= |
Evaluates to true whether both sizes are not equal or if any element with corresponding key is not equal. |
foreach |
Iterates over the map's elements. |
Map Methods
Method | Description |
---|---|
int size() |
Returns the number of elements in the map. |
clear() |
Removes all *element"s from the map. |
<data_type> delete(key) |
Moves out the element by the specified key, which must exists in the map. |
insert(key, element) |
Adds the element with the specified key. |
set<data_type> keys() |
Returns all keys to a set -type. |
list<data_type> values() |
Returns all elements to a list -type. |
Index operator []
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as key or element for index operator []
.
Used to access a specific element of a map by given key.
- The key
"3"
not exist. - The data_type of index and key are not the same.
Warning
When used to reference an element in the map, the key should be exists.
Note
When used at LHS for assignment, the key will be added if not exists.
Note
Operator that modify contents can only be used within exec
block or native function
.
Assignment operator =
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as key or element for assignment operator =
.
Creates a copy of the map
-type expression on the RHS and assigns it to the map on the LHS.
Last element will be used if there have multiple elements with same key in the expression.
- The
data_type
s are not same as declaration of the map.
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 keys are equal.
- Equalize size and all elements with corresponding keys.
- Inequalize any element with corresponding key.
- Inequalize any element with corresponding key.
- Equalize size and all elements with corresponding keys.
- Inequalize size.
- Different data_type of key or element are incomparable.
Warning
Different data_type of key or element of two maps should NOT be compared.
Inequality operator !=
Evaluates to true whether both sizes are not equal or if any element with corresponding key is not equal.
- Equalize size and all elements with corresponding keys.
- Inequalize any element with corresponding key.
- Inequalize any element with corresponding key.
- Equalize size and all elements with corresponding keys.
- Inequalize size.
- Different data_type of key or element are incomparable.
Warning
Different data_type of key or element of two maps should NOT be compared.
foreach
statement
Iterates over the map's elements.
Look at Procedural/foreach
for more information.
function int size()
Returns the number of elements in the map.
function void clear()
Removes all elements from the map.
Note
Method that modify contents can only be used within exec
block or native function
.
function <data_type> delete(data_type key)
Moves out the element by the specified key, which must exists in the map.
- The key
"3"
is not exist.
Warning
The key should be exists in the map.
Note
Method that modify contents can only be used within exec
block or native function
.
function void insert(data_type key, data_type element)
PSSGen: Not support bool
, enum
, float32
, float64
, chandle
, and struct
as key or element of insert()
.
Adds the element with the specified key. The element will be replaced if the key already exists.
- The data_type of element is not same.
- The data_type of key is not same.
Waring
The data_type of key or element should be same as the map's declaration.
Note
Method that modify contents can only be used within exec
block or native function
.
function set<data_type> keys()
Returns all keys to a set
-type.
function list<data_type> values()
Returns all elements to a list
-type.
Created: 2023-10-17