Hash_Table module

table_find_pointer

procedure · 1 overloadSource

A pointer to the value stored for key, or null when there is none, so the value can be changed in place.

The pointer is valid until the table grows or the entry is removed. Looking up in a table that never held anything is fine and finds nothing.

ExampleOpen in playground ↗
counts: Table(string, int);
table_add(*counts, "a", 1);
pointer := table_find_pointer(*counts, "a");
pointer.* += 1;
assert(table_find_pointer(*counts, "a").* == 2);
assert(table_find_pointer(*counts, "b") == null);
deinit(*counts);
table_find_pointer :: (table: *Table, key: table.Key_Type) -> *table.Value_Type

A pointer to the value stored for key, or null when there is none, so the value can be changed in place.

The pointer is valid until the table grows or the entry is removed. Looking up in a table that never held anything is fine and finds nothing.

Parameters

table: *Table
key: table.Key_Type

Returns

*table.Value_Type
ExampleOpen in playground ↗
counts: Table(string, int);
table_add(*counts, "a", 1);
pointer := table_find_pointer(*counts, "a");
pointer.* += 1;
assert(table_find_pointer(*counts, "a").* == 2);
assert(table_find_pointer(*counts, "b") == null);
deinit(*counts);

See also