Modules

Hash_Map

moduleSource
macOSLinuxWindowswasm

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.

ExampleOpen in playground ↗
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#

insertsince 0.23.0
(map: *Map, key: map.Key, value: map.Value) -> (previous: map.Value, replaced: bool)

Stores the value under the key. Returns the value it replaced (zero if there was none) and whether there was one.

findsince 0.23.0
(map: *Map, key: map.Key) -> *map.Value

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.

getsince 0.23.0
(map: *Map, key: map.Key, default: map.Value = .{}) -> map.Value

A copy of the key's value, or default if it is missing.

entrysince 0.23.0
(map: *Map, key: map.Key) -> (value: *map.Value, added: bool)

A pointer to the key's value, adding a zero-initialized one if the key is missing. added says whether it was added.

deletesince 0.23.0
(map: *Map, key: map.Key) -> (value: map.Value, removed: bool)

Removes the key. Returns its value (zero if it was missing) and whether it was there.

containssince 0.23.0
(map: *Map, key: map.Key) -> bool
reservesince 0.23.0
(map: *Map, expected_count: s64)

Room for expected_count entries in total, so inserting up to that many never rebuilds the map.

clearsince 0.23.0
(map: *Map)

Removes every entry and keeps the memory.

deinitsince 0.23.0
(map: *Map)

Removes every entry and frees the memory.

for_expansionsince 0.23.0
(map: *$T/Map, body: Code, flags: For_Flags)

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.

Types#

Mapstructsince 0.23.0
:: struct

Constants#