Hash_Table module

table_remove

procedure · 1 overloadSource

Removes one entry with this key; returns whether there was one and its value.

With duplicate keys it removes the first match only; see table_remove_multiple. The slot keeps a marker until it is reused or the table is rebuilt, so removing does not shrink the table or move other entries.

ExampleOpen in playground ↗
table: Table(int, string);
table_add(*table, 5, "five");
removed, value := table_remove(*table, 5);
assert(removed && value == "five" && table.count == 0);
removed, value = table_remove(*table, 5);
assert(!removed);
deinit(*table);
table_remove :: (
    table: *Table,
    key: table.Key_Type
) -> (success: bool, value: table.Value_Type)

Removes one entry with this key; returns whether there was one and its value.

With duplicate keys it removes the first match only; see table_remove_multiple. The slot keeps a marker until it is reused or the table is rebuilt, so removing does not shrink the table or move other entries.

Parameters

table: *Table
key: table.Key_Type

Returns

success: bool
value: table.Value_Type
ExampleOpen in playground ↗
table: Table(int, string);
table_add(*table, 5, "five");
removed, value := table_remove(*table, 5);
assert(removed && value == "five" && table.count == 0);
removed, value = table_remove(*table, 5);
assert(!removed);
deinit(*table);

See also