From 5062aeed93d8694accb3282ab43e6d824d059e2e Mon Sep 17 00:00:00 2001 From: Patrick Stotko Date: Wed, 10 Apr 2024 09:11:37 +0200 Subject: [PATCH] unordered_map,unordered_set: Simplify excess list size computation --- src/stdgpu/impl/unordered_base_detail.cuh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/stdgpu/impl/unordered_base_detail.cuh b/src/stdgpu/impl/unordered_base_detail.cuh index 8b16d10e3..109e0720c 100644 --- a/src/stdgpu/impl/unordered_base_detail.cuh +++ b/src/stdgpu/impl/unordered_base_detail.cuh @@ -16,7 +16,6 @@ #ifndef STDGPU_UNORDERED_BASE_DETAIL_H #define STDGPU_UNORDERED_BASE_DETAIL_H -#include #include #include @@ -39,7 +38,7 @@ expected_collisions(const index_t bucket_count, const index_t capacity) long double k = static_cast(bucket_count); long double n = static_cast(capacity); // NOLINTNEXTLINE(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers) - index_t result = static_cast(n * (1.0L - std::pow(1.0L - (1.0L / k), n - 1.0L))); + index_t result = static_cast(std::ceil(n * (1.0L - std::pow(1.0L - (1.0L / k), n - 1.0L)))); STDGPU_ENSURES(result >= 0); @@ -1206,7 +1205,7 @@ unordered_base::createDevic // 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 excess_count = expected_collisions(bucket_count, capacity) * 2 / 3 + 1; index_t total_count = bucket_count + excess_count;