std::Map class

The Map class implements a mapping from keys to values. Keys may be any objects that provide a hash value using the std::Hash function and support the == operator, while values may be arbitrary objects. At most a single object can be associated with a specific key. If several values are assigned to a key, the later assignments replace the earlier values.

class Map(...)
Construct a Map object. The constructor accepts an arbitrary number of Pair objects that define the initial (key, value) pairs to be added to the map. The left item of each pair is the key, and the right item is the value. Example:
var m = Map("one": 1, "three": 33)
m["one"]   -- Result: 1

Map methods

length()
Return the number of keys in a map.
hasKey(key)
Return a boolean indicating whether the map contains the specified key.
remove(key)
Remove a key and the corresponding value from the map. It is an error to remove a key that is not in the map.
keys()
Return an array of all the keys in the map. The keys are returned in an arbitrary order.
values()
Return an array of all the values in the map. The values are returned in an arbitrary order.
iterator()
Return an iterator object that returns all the (key, value) pairs in the map, in an arbitrary order. Each item in the iteration is an array [key, value].

Map operations

Map objects support the following operations:

map[key]
Return the value associated with a key, or raise an IndexError if the key is missing.
map[key] = value
Add a new association to the map or replace an existing association if the key already exists.
for key, value in map
Map contents can be iterated with a for loop. Each item in the iteration is an array [key, value]. The items are iterated in an arbitrary order.
Str(map)
Return a string representation of a map.