Hash_Map module

Map

structextensionsince 0.23.0Source

A hash map from Key to Value. Strings and anything Hash.get_hash handles work as keys out of the box; pass hash and equal for other types. The zero value is an empty map that allocates on the first insert; free it with deinit.

Example↗
Hash_Map :: #import "Extensions/Hash_Map";

map: Hash_Map.Map(string, int);
defer Hash_Map.deinit(*map);

Hash_Map.insert(*map, "one", 1);
assert(map.count == 1 && Hash_Map.get(*map, "one") == 1);

Fields

count: int
Entries in the map. Read only.
capacity: int
Slots in the map: zero before the first insert, then a power of two, at least GROUP_SIZE. Read only.
growth_left: int
Empty slots that may still be filled before the map has to be rebuilt.
allocator: Allocator
control: *u8
One byte per slot, followed in the same allocation by the entries.
entries: *Entry

See also