Dictionaries are data structures that associate keys with values. You can perform specific operations on dictionaries.
>typeof(streamname) rec := dict[symbol]; if( not (isnull(rec)) { // use rec }
You can perform the following operations on dictionaries:
Create a new dictionary. Memory is allocated when the dictionary is created, even though it is empty.
Syntax: new dictionary(type_of_key, type_of_value)
For example, d := new dictionary(integer, string); creates a new, empty dictionary with integer keys and string values.
Assign a value to a key in the dictionary. The key and value must match the key type and value type of the dictionary. The function returns the updated dictionary.
Syntax: dictionary[key] := value
For example, counter[input] := 3 returns the dictionary counter with the value of input set to 3.
Get a value from the dictionary by key. The key must have the type of the keys of the dictionary. This operator returns a value of the type of the values held in the dictionary. Unless the key is not found in the dictionary, then it returns null.
Syntax: dictionary[key]
For example, counter[input] returns the value associated with the key input.
Remove a key, and its associated value, from the dictionary. 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.
Syntax: remove(dictionary, key)
For example, remove(counter, input) returns a 1 after removing the key input and its associated value, or it returns a 0 if the key input was not found.
Remove all key/value pairs from the dictionary. Each key/value pair is examined in turn; if not referenced anywhere else, it is removed and memory is deallocated. The function returns the cleared dictionary.
Syntax: clear(dictionary)
For example, clear(counter) returns an empty dictionary, counter, after removing all of the key/value pairs as long as none of them were referenced anywhere else.
Test a dictionary for emptiness. The function returns an integer: 1 if the dictionary is empty, 0 if not empty.
Syntax: empty(dictionary)
For example, empty(counter) returns a 1 if counter is empty, a 0 if it is not.
There is no command to copy a dictionary. Therefore, the only way to make a copy of a dictionary is manually, by iterating through the elements. You can also iterate through all the elements in the dictionary (up to the first null element) using a for loop.