-
Notifications
You must be signed in to change notification settings - Fork 294
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
Raw entry hasher #54
Raw entry hasher #54
Conversation
src/map.rs
Outdated
S: BuildHasher, | ||
H: Fn(&K) -> u64, | ||
{ | ||
self.table.reserve(1, |x| hasher(&x.0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't actually need to call reserve
here, it is done internally by insert
. I realize now that the reserve
call was unnecessary in the first place.
bors r+ |
54: Raw entry hasher r=Amanieu a=sujayakar This PR allows the user to create a `HashMap` where `K` doesn't implement `Hash`, so long as they are okay with only using the raw entry API. The first step is to move around some methods that didn't actually depend on `K: Hash`. Then, the only non-plumbing change was to defer the `.reserve(1)` call on `raw_entry_mut` to right before insertion. Then, we expose a new method `RawVacantEntryMut::insert_with_hasher` that takes in the custom hashing function and passes it in to `reserve` before inserting. @Amanieu do these API changes merit a version bump? I think we're only allowing these methods to be used on _more_ types, but let me know. Closes #44 Co-authored-by: Sujay Jayakar <[email protected]>
Thanks! A major version bump isn't needed since we are only relaxing trait bounds, not tightening them. |
Build succeeded
|
@Amanieu, do you think the recent build failures are related to this diff? It looks like some Travis misconfiguration, but I'm not sure. |
Oh, that's something else. It should be fixed now. |
This PR allows the user to create a
HashMap
whereK
doesn't implementHash
, so long as they are okay with only using the raw entry API.The first step is to move around some methods that didn't actually depend on
K: Hash
. Then, the only non-plumbing change was to defer the.reserve(1)
call onraw_entry_mut
to right before insertion. Then, we expose a new methodRawVacantEntryMut::insert_with_hasher
that takes in the custom hashing function and passes it in toreserve
before inserting.@Amanieu do these API changes merit a version bump? I think we're only allowing these methods to be used on more types, but let me know.
Closes #44