Dictionaries are data structures that associate keys with values. You can perform specific operations on dictionaries.
You can perform the following operations on dictionaries:
Syntax: new dictionary(type, type)
Type: A vector of the declared type is returned.
Example: d := new dictionary(integer, string);
Syntax: dictionary[key]
Type: The key must have the type of the keys of the dictionary. The function returns a value of the type of the values held in the dictionary.
Example: counter[input]
Syntax: dictionary[key] := value
Type: The key and value must match the key type and value type of the dictionary. The function returns the updated dictionary.
Example: counter[input] := 3
Syntax: remove(dictionary, key)
Type: The key must match the key type of the dictionary. The function returns an integer: 0 if the key was not present, and 1 otherwise.
Example: remove(counter, input)
Syntax: clear(dictionary)
The function returns the cleared dictionary.
Example: clear(counter)
Syntax: empty(dictionary)
The function returns an integer: 1 if the dictionary is empty, 0 if not empty.
Example: empty(counter)
You can also iterate through all the key/value pairs in the dictionary using a "for" loop.