Skip to content

Commit

Permalink
unordered_map,unordered_set: Fix excess list size for very low capaci…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
stotko committed Apr 8, 2024
1 parent 8f25f66 commit b7a350e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/stdgpu/impl/unordered_base_detail.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -1203,9 +1203,10 @@ unordered_base<Key, Value, KeyFromValue, Hash, KeyEqual, Allocator>::createDevic
index_t bucket_count = static_cast<index_t>(
bit_ceil(static_cast<std::size_t>(std::ceil(static_cast<float>(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<index_t>(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<index_t>(1, expected_collisions(bucket_count, capacity) * 2 / 3 + 1);

index_t total_count = bucket_count + excess_count;

Expand Down

0 comments on commit b7a350e

Please sign in to comment.