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: Fix excess list size for very low capacities #414

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

stotko
Copy link
Owner

@stotko stotko commented Apr 8, 2024

The size of the internal excess list of unordered_map and unordered_set is determined by the expected amount of collisions, but at least 1. However, insertion as a precaution requires a non-empty excess list to proceed even if the inserted element will not produce a collision. In case of very small capacities, e.g. n = 4, this may result in insertion failures if a collision happens. Increase the excess count by 1 to account for this "reserved" element.

Closes #411

@stotko stotko force-pushed the small_excess_list_count branch from 7976c3c to baa4941 Compare April 8, 2024 12:06
Copy link

codecov bot commented Apr 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.33%. Comparing base (8f25f66) to head (baa4941).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #414   +/-   ##
=======================================
  Coverage   97.33%   97.33%           
=======================================
  Files          31       31           
  Lines        2512     2512           
=======================================
  Hits         2445     2445           
  Misses         67       67           

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

@stotko stotko merged commit b7a350e into master Apr 8, 2024
61 checks passed
@stotko stotko deleted the small_excess_list_count branch April 8, 2024 12:16
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.

Unexpected insertion when using unordered_map and capacity equals to 4
2 participants