Allow alternative hash functions in GraphMap#622
Merged
ABorgna merged 1 commit intopetgraph:masterfrom Apr 1, 2024
Merged
Conversation
3e81e1c to
8e40f11
Compare
cuviper
reviewed
May 11, 2024
| pub fn new() -> Self | ||
| where | ||
| S: Default, | ||
| { |
Contributor
There was a problem hiding this comment.
FYI: by leaving S open here, it means that type inference can't figure it out, and it won't use the default either. e.g. This used to work:
let mut graph = GraphMap::new();
// ... other code that insert stuff, inferring those types but *not* the hasherNow to allow inference I have to write:
let mut graph = GraphMap::<_, _, _>::new(); // now 4th param `S` is defaultedThat's why HashMap::new() and IndexMap::new() only use the default hasher, while default() is fully generic.
See also: https://faultlore.com/blah/defaults-affect-inference/
Contributor
There was a problem hiding this comment.
Don't get me wrong, this is a great feature overall! I would have just left new() on the old hasher for the reason above, but it would be a breaking change to go back on that now.
Contributor
Author
There was a problem hiding this comment.
Ack, thanks for the comment. I would have done it differently if I'd realized.
This was referenced Jun 25, 2025
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.
Hi there @bluss and @ABorgna!
Today,
GraphMapusesIndexMap's default choice of hash function. Like many Rustaceans, I have a use case that is bottlenecked by hashing, which could take advantage of a faster hash function.This change allows users of this crate to pick alternative hashers, as they might with an
IndexMapor aHashMap, but only if they want to. Existing code will still work, because eachimplhas been made more generic, sincestd::hash::RandomStatealready implementsBuildHasherandDefault.I took
dev-dependenciesonahashandfxhash, and extended a benchmark I'd previously contributed: