This is a "cheat sheet" for Map.gml extension by YellowAfterlife.
The extension can be found on itch.io or GitHub

Click on sections to expand/collapse them.
Quick display controls: Categories · Sections · Everything ·

LightMap

A very simple wrapper around variable_struct_ functions.

copy()LightMap

Returns a shallow copy of this structure.


empty()bool

Returns whether this structure contains no key-value pairs.

size()int

Returns the number of key-value pairs in this structure.


exists(key)bool

Returns whether the given key exists in this structure.

get(key)?value

Retrieves a value for the specified key, or undefined if it did not exist.

set(key, val)

Adds a new key-value pair of replaces an existing one.

replace(key, val)replaced?

Attempts to replace a value by a new one.

Returns true if the value was replaced or false if the key did not exist in this structure.


keys()array<string>

Returns an array of keys in this structure.
Not ordered in a specific way, but consistent with values.

values()array

Returns an array of values in this structure.
Not ordered in a specific way, but consistent with keys.


toString()string

Returns a string representation of this structure.

StructMap

A wrapper around variable_struct_ functions that supports key-value pair "removal" (by storing a special value in "unused" pairs and accounting for these).

copy()StructMap

Returns a shallow copy of this structure. The copy will only contain the fields that have not been marked as "unused".

clear()

Marks all key-value pairs in this structure as "unused".


empty()bool

Returns whether this structure contains no used key-value pairs.

size()int

Returns the number of key-value pairs in this structure, excluding ones marked as unused.


exists(key)bool

Returns whether the given key exists in this structure.

get(key)?value

Retrieves a value for the specified key, or undefined if it did not exist.

set(key, val)

Adds a new key-value pair of replaces an existing one.

replace(key, val)replaced?

Attempts to replace a value by a new one.

Returns true if the value was replaced or false if the key did not exist in this structure.

remove(key)removed?

Attempts to remove a value from the structure, marking it as "unused".

Returns whether the value was present (and thus was removed).


keys(?copy)array<string>

Returns an array of keys in this structure.
Not ordered in a specific way, but consistent with values.

If the optional copy parameter is set to false (default is true), the function will return a cached array where possible - good if you don't intend to modify the array!

values()array

Returns an array of values in this structure.
Not ordered in a specific way, but consistent with keys.


toString()string

Returns a string representation of this structure, excluding unused key-value pairs.

HashMap
new HashMap(?initialSize)

Creates a new map with specified initial capacity.

Default is 256, but you may make it lower if you know the approximate number of keys (check whether the map expands using capacity).

copy()

Returns a shallow copy of this map.

clear()

Removes all key-value pairs from this map.


empty()bool

Returns whether this map contains no key-value pairs.

size()int

Returns the current number of key-value pairs in the map.

capacity()int

Returns the current map capacity - that is, how many entries do the internal arrays hold. A map is resized whenever size reaches half of capacity or if a key-value pair cannot be fit due to a sufficient number of collisions.


exists(key)

Returns whether a key-value exists for the given key.

get(key)

Returns a value for the given key, or, if there is no such key-value pair,

set(key, val)

Adds a new key-value pair to the map or updates the value of an existing one.

As per capacity, this may trigger a reallocation of the map.

replace(key, value)bool

Finds a key-value pair for the given key and replaces the value with a new one.

Returns true if the value was replaced, or false if the pair was not found.

remove(key)bool

Removes a key-value pair, returns whether successful (false if no pair with the given key existed).


iterator()

Creates and returns a new iterator for this map.

The iterator has a single method called next, which will pull out the next key-value pair and store it in its key/value fields, subsequently returning true, or will return false if it has reached the end of the map.

You would usually use it like so:

var map = new Map();
map.set("one", 1);
map.set(2, "two");
var it = map.iterator();
while (it.next()) {
    trace("iter", it.key, "=>", it.value);
}
// shorter: for (var it = map.iterator(); it.next();) {...}
keys()array

Returns an array containing all keys in the map.
Not ordered in a specific way, but consistent with values.

values()array

Returns an array containing all values in the map.
Not ordered in a specific way, but consistent with keys.


toString()string

Returns a string representation of this map, in a somewhat JSON-looking (but not valid JSON) format - Map({ key1: value1, key2: value2, ... })

toStruct()struct

Returns a new struct containing key-value pairs from this map.