Home

Awesome

Map(s).gml

Maintained by: YellowAfterlife

Quick links: Documentation

This repository contains several hashtable implementations for GameMaker Studio 2.3+:

I hope this to be of use for anyone doing larger-scale work with structs.

Small example:

var h = new HashMap();

h.set("hi", "hello!");
h.set(4, "four");
trace(h.get("hi")); // "hello!"
trace(h); // Map({ "hi": "hello!", 4: "four" })
trace("toObject", h.toObject());
trace("keys", h.keys());
trace("values", h.values());

h.set(5, "?");
h.remove(5);
// h.get(5) => undefined
// h.exists(5) => false

var it = h.iterator();
while (it.next()) {
	trace("iter", it.key, "=>", it.value);
}

for (var i = 0; i < 200; i++) h.set(i, "$" + string(i));
// h.size() => 201

License: MIT

Feature comparison

Criteriads_map_*variable_*LightMapStructMapHashMap
Memory managementexplicitGCGCGCGC
Key typesjust about anythingstringstringstringstring, number, undefined
Key-value pair removal

(... is there anything else of interest?)

Compiling

  1. Set up haxe, install sfhx and sfgml via haxelib git
  2. Do haxe build.hxml

Performance

In general, ds_map_* <=> structs > LightMap > StructMap > HashMap.

Structs can out-perform ds_map by utilizing obj.field syntax for known-to-exist fields.

HashMap generally pays for being written in GML (and having more logic to it), but still can perform well for its areas of use.

StructMap/LightMap have comparable performance to variable_struct_* functions as they have minimal amount of logic on top.