From b7a350e03804e2febf9e5803949f59aecefa96cb Mon Sep 17 00:00:00 2001 From: Patrick Stotko Date: Mon, 8 Apr 2024 13:31:08 +0200 Subject: [PATCH] unordered_map,unordered_set: Fix excess list size for very low capacities --- src/stdgpu/impl/unordered_base_detail.cuh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/stdgpu/impl/unordered_base_detail.cuh b/src/stdgpu/impl/unordered_base_detail.cuh index a772f246f..8b16d10e3 100644 --- a/src/stdgpu/impl/unordered_base_detail.cuh +++ b/src/stdgpu/impl/unordered_base_detail.cuh @@ -1203,9 +1203,10 @@ unordered_base::createDevic index_t bucket_count = static_cast( bit_ceil(static_cast(std::ceil(static_cast(capacity) / default_max_load_factor())))); - // excess count is estimated by the expected collision count and conservatively lowered since entries falling into - // regular buckets are already included here - index_t excess_count = std::max(1, expected_collisions(bucket_count, capacity) * 2 / 3); + // excess count is estimated by the expected collision count: + // - Conservatively lower the amount since entries falling into regular buckets are already included here + // - Increase amount by 1 since insertion expects a non-empty excess list also in case of no collision + index_t excess_count = std::max(1, expected_collisions(bucket_count, capacity) * 2 / 3 + 1); index_t total_count = bucket_count + excess_count;