1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:27:35 +00:00

AK: HashMap::set() didn't save new values for existing keys.

This commit is contained in:
Andreas Kling 2019-03-25 04:23:17 +01:00
parent 1c67788933
commit 17b9fb7bfc

View file

@ -244,9 +244,11 @@ void HashTable<T, TraitsForT>::set(T&& value)
rehash(1); rehash(1);
auto& bucket = lookup(value); auto& bucket = lookup(value);
for (auto& e : bucket.chain) { for (auto& e : bucket.chain) {
if (e == value) if (e == value) {
e = move(value);
return; return;
} }
}
if (size() >= capacity()) { if (size() >= capacity()) {
rehash(size() + 1); rehash(size() + 1);
insert(move(value)); insert(move(value));
@ -263,9 +265,11 @@ void HashTable<T, TraitsForT>::set(const T& value)
rehash(1); rehash(1);
auto& bucket = lookup(value); auto& bucket = lookup(value);
for (auto& e : bucket.chain) { for (auto& e : bucket.chain) {
if (e == value) if (e == value) {
e = move(value);
return; return;
} }
}
if (size() >= capacity()) { if (size() >= capacity()) {
rehash(size() + 1); rehash(size() + 1);
insert(value); insert(value);