fix: Guard against uninitialized hashmap in key removal

Removing non-present keys is a supported operation on HashMaps,
and most other operations are well-defined on uninitialized
HashMaps.

Currently, removing any key on an uninitialized HashMap will
result in an 'Array index out of bounds' error.

This change guards against such a case.
This commit is contained in:
Owen Shepherd
2024-08-16 22:32:10 +01:00
committed by Christoffer Lerno
parent 74b8da1e15
commit 4edaf603c9

View File

@@ -369,6 +369,7 @@ fn void HashMap.free_internal(&map, void* ptr) @inline @private
fn bool HashMap.remove_entry_for_key(&map, Key key) @private
{
if (!map.count) return false;
uint hash = rehash(key.hash());
uint i = index_for(hash, map.table.len);
Entry* prev = map.table[i];
@@ -421,4 +422,4 @@ struct Entry
Key key;
Value value;
Entry* next;
}
}