From bacc0db77809f79dc673b4dbf35356ff85f31990 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 23 Dec 2023 16:31:42 +0200 Subject: [PATCH] BAN: Fix unstable hash map rebucket --- BAN/include/BAN/HashMap.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/BAN/include/BAN/HashMap.h b/BAN/include/BAN/HashMap.h index 061a73e972..b2f5050b03 100644 --- a/BAN/include/BAN/HashMap.h +++ b/BAN/include/BAN/HashMap.h @@ -223,20 +223,15 @@ namespace BAN if (new_buckets.resize(new_bucket_count).is_error()) return Error::from_errno(ENOMEM); - if constexpr(STABLE) + for (auto& bucket : m_buckets) { - // NOTE: We have to copy the old entries to the new entries and not move - // since we might run out of memory half way through. - for (auto& bucket : m_buckets) + for (Entry& entry : bucket) { - for (Entry& entry : bucket) - { - size_type bucket_index = HASH()(entry.key) % new_buckets.size(); - if constexpr(STABLE) - TRY(new_buckets[bucket_index].push_back(entry)); - else - TRY(new_buckets[bucket_index].push_back(BAN::move(entry))); - } + size_type bucket_index = HASH()(entry.key) % new_buckets.size(); + if constexpr(STABLE) + TRY(new_buckets[bucket_index].push_back(entry)); + else + TRY(new_buckets[bucket_index].push_back(BAN::move(entry))); } }