Skip to content

Commit 7976c3c

Browse files
committed
unordered_map,unordered_set: Fix excess list size for very low capacities
1 parent 8f25f66 commit 7976c3c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/stdgpu/impl/unordered_base_detail.cuh

+4-3
Original file line numberDiff line numberDiff line change
@@ -1203,9 +1203,10 @@ unordered_base<Key, Value, KeyFromValue, Hash, KeyEqual, Allocator>::createDevic
12031203
index_t bucket_count = static_cast<index_t>(
12041204
bit_ceil(static_cast<std::size_t>(std::ceil(static_cast<float>(capacity) / default_max_load_factor()))));
12051205

1206-
// excess count is estimated by the expected collision count and conservatively lowered since entries falling into
1207-
// regular buckets are already included here
1208-
index_t excess_count = std::max<index_t>(1, expected_collisions(bucket_count, capacity) * 2 / 3);
1206+
// excess count is estimated by the expected collision count:
1207+
// - Conservatively lower the amount since entries falling into regular buckets are already included here
1208+
// - Increase amount by 1 since insertion expects a non-empty excess list also in case of no collision
1209+
index_t excess_count = std::max<index_t>(1, expected_collisions(bucket_count, capacity) * 2 / 3) + 1;
12091210

12101211
index_t total_count = bucket_count + excess_count;
12111212

0 commit comments

Comments
 (0)