pass a real rehash hasher to MapHashTable reserve / shrink#235
Merged
sunshowers merged 2 commits intomainfrom Apr 23, 2026
Merged
Conversation
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, MapHashTable::reserve, try_reserve, shrink_to_fit, and shrink_to all
delegated to hashbrown::HashTable with
|_| 0as the rehash hasher.When the capacity change triggers a reallocation, hashbrown's rehash
pipeline (resize_inner / reserve_rehash_inner) calls the supplied hasher
for every surviving entry and uses the result to pick its new bucket.
Returning 0 for every key crowds all entries into bucket 0 of the new
table; subsequent lookups probe from
hash(key) mod capacityand miss,so the map silently appears empty to
get/find_indexwhile iterationstill returns every item.
Also,
reserveandtry_reserveare reachable through the public API ofIdHashMap / BiHashMap / TriHashMap, including via
Extend, whichpre-reserves
size_hint / 2before inserting.The fix is to take a real hasher at the MapHashTable layer and plumb
|ix| state.hash_one(items[*ix].keyN())through every caller.Also add coverage for these methods to our proptests.