Hash_Table module

Walk_Table

procedure · 1 overloadSource

Low-level macro that visits the slots a lookup of key would probe, in order, up to the first never-used slot.

It reads the caller's variables table and key, and defines hash (the key's hash), index (the slot) and table_while_loop (the hash stored in that slot) for code. A removed entry shows as REMOVED_HASH. Use continue table_while_loop and break table_while_loop to control the walk. It exists to build lookups with custom matching, such as finding all entries that agree with key in some other way; prefer table_find and friends otherwise.

ExampleOpen in playground ↗
table: Table(int, string);
table_add(*table, 7, "seven");

key := 7;
matches := 0;
Walk_Table(#code {
    if table_while_loop == hash && table.entries[index].key == key matches += 1;
});
assert(matches == 1);
deinit(*table);
Walk_Table :: (code: Code)

Low-level macro that visits the slots a lookup of key would probe, in order, up to the first never-used slot.

It reads the caller's variables table and key, and defines hash (the key's hash), index (the slot) and table_while_loop (the hash stored in that slot) for code. A removed entry shows as REMOVED_HASH. Use continue table_while_loop and break table_while_loop to control the walk. It exists to build lookups with custom matching, such as finding all entries that agree with key in some other way; prefer table_find and friends otherwise.

Parameters

code: Code
ExampleOpen in playground ↗
table: Table(int, string);
table_add(*table, 7, "seven");

key := 7;
matches := 0;
Walk_Table(#code {
    if table_while_loop == hash && table.entries[index].key == key matches += 1;
});
assert(matches == 1);
deinit(*table);

See also