Stores the value under the key. Returns the value it replaced (zero if there was none) and whether there was one.
since 0.23.0
#import "Extensions/Hash_Map";
An opt-in hash map that probes sixteen slots at a time. A jaic extension, not official Jai. See docs/extensions/hash-map.md.
Map :: #import "Extensions/Hash_Map";
ages: Map.Map(string, int);
defer Map.deinit(*ages);
Map.insert(*ages, "ada", 36);
age := Map.get(*ages, "ada");
for value, name: ages print("% is %\n", name, value);Show moreShow less
A key is stored once. Iteration order is whatever the layout gives, and changes whenever the map grows.
Procedures#
A pointer to the key's value, or null if it is missing. The pointer stays valid until the map is next rebuilt by an insert or entry.
A copy of the key's value, or default if it is missing.
A pointer to the key's value, adding a zero-initialized one if the key is missing. added
says whether it was added.
Removes the key. Returns its value (zero if it was missing) and whether it was there.
Room for expected_count entries in total, so inserting up to that many never rebuilds the map.
Removes every entry and keeps the memory.
Removes every entry and frees the memory.
for value, key: map {...}: it is the value (a pointer to it under for *), it_index the
key. remove it takes the current entry out. Anything else that changes the map inside the
loop, adding included, invalidates the loop.