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

Raw entry hasher #54

Merged
merged 4 commits into from
Mar 17, 2019
Merged

Raw entry hasher #54

merged 4 commits into from
Mar 17, 2019

Conversation

sujayakar
Copy link

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

src/map.rs Outdated
S: BuildHasher,
H: Fn(&K) -> u64,
{
self.table.reserve(1, |x| hasher(&x.0));
Copy link
Member

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.

@Amanieu
Copy link
Member

Amanieu commented Mar 17, 2019

bors r+

bors bot added a commit that referenced this pull request Mar 17, 2019
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]>
@Amanieu
Copy link
Member

Amanieu commented Mar 17, 2019

Thanks! A major version bump isn't needed since we are only relaxing trait bounds, not tightening them.

@bors
Copy link
Contributor

bors bot commented Mar 17, 2019

Build succeeded

  • continuous-integration/travis-ci/push

@bors bors bot merged commit b3717fd into rust-lang:master Mar 17, 2019
@sujayakar sujayakar deleted the raw-entry-hasher branch March 17, 2019 22:44
@sujayakar
Copy link
Author

@Amanieu, do you think the recent build failures are related to this diff? It looks like some Travis misconfiguration, but I'm not sure.

@Amanieu
Copy link
Member

Amanieu commented Mar 21, 2019

Oh, that's something else. It should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants