Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unordered_map,unordered_set: Increase excess size #435

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

stotko
Copy link
Owner

@stotko stotko commented Oct 22, 2024

The excess size of unordered_map and unordered_set have been estimated based on the birthday paradox and then conservatively lowered as some amount of estimated collisions also includes entries sitting in a bucket instead of the excess list. This size adjustment has been performed to save memory. However, the underlying assumption of this estimate is a perfect uniform distribution of the hashes which is the best case scenario. With common hash functions, that distribution may be worse leading to a larger amount of required excess entries, especially at high load factors. Use the estimated number directly as it overestimates the excess list size by a factor close to 2 (about 90% collisions will typically be between exactly 2 entries). This has been tested to work better with high load factors up to 100%.

@stotko stotko added the bug label Oct 22, 2024
@stotko stotko added this to the 2.0.0 milestone Oct 22, 2024
Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.46%. Comparing base (1523669) to head (f89d6d5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
+ Coverage   97.34%   97.46%   +0.11%     
==========================================
  Files          32       32              
  Lines        2524     2602      +78     
==========================================
+ Hits         2457     2536      +79     
+ Misses         67       66       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stotko stotko merged commit 3a0b20e into master Oct 22, 2024
61 checks passed
@stotko stotko deleted the unordered_map_set_collisions branch October 22, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant