Map
Abstract map implementation.
Map:__init(key_values)
Constructor.
Arguments:
key_values
(table[any:any]
): used to initialize the map. Optional.
Map:add(key, val)
Adds an entry to the map.
Arguments:
key
(any
): key to add.value
(any
): value to add.
Map:addMany(tab)
Adds many entries to the map.
Arguments:
tab
(table[any:any]
): a map of key value pairs to add. Optional.
Map:copy()
Returns:
- (
Map
) copy of this map
Map:contains(key)
Arguments:
key
(any
): key to check.
Returns:
- (
coolean
) whether the map contains the key
Map:get(key, returnNilIfMissing)
Retrieves the value for a key.
Arguments:
key
(any
): key to retrive.returnNilIfMissing
(boolean
): whether to tolerate missing keys. Optional.
Returns:
- (
any
) value corresponding to the key
By default, asserts error if key
is not found. If returnNilIfMissing
is true,
then a nil
will be returned if key
is not found.
Map:remove(key)
Removes a key value pair
Arguments:
key
(any
): key to remove.
Returns:
- (
any
) the removed value
Asserts error if key
is not in the map.
Map:keys()
Returns:
- (
table[any]
) a table of the keys in the map
Map:totable()
Returns:
- (
table[any:any]
) the map in table form
Map:equals(another)
Arguments:
another
(Map
): another map to compare to.
Returns:
- (
boolean
) whether this map equalsanother
.
Maps are considered equal if all keys and corresponding values match.
Map:size()
Returns:
- (
int
) number of key value pairs in the map