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

Explain why Hashmap is used instead of Hashset in unique_impl #623

Merged
merged 1 commit into from Jun 7, 2022

Conversation

hellow554
Copy link
Contributor

The Hashmap was chosen because of the Entry API, but one can work around
that easiliy.

entry.insert(());
return Some(elt);
if !self.iter.used.contains(&v) {
self.iter.used.insert(v.clone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this code is easy to write, but it seems like it also loses the point of why the entry API was used in the first place -- this needs to hash the element twice (once in contains, once in insert), whereas the original code only has to hash it once (in entry).

Given that the HashMap vs HashSet doesn't leak out of the implementation, it seems to me like it's worth a slightly more complex implementation when it can save some hashing work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, thanks for the review and your great knowledge.

I'll rework the PR to make the intention clear :)

@hellow554 hellow554 force-pushed the unique_hashmap branch 2 times, most recently from 3cf22b9 to 2c74555 Compare Jun 7, 2022
@hellow554 hellow554 changed the title Replace Hashmap<V, ()> by HashSet<V> Explain why Hashmap is used instead of Hashset in unique_impl Jun 7, 2022
@jswrenn jswrenn added this to the next milestone Jun 7, 2022
@jswrenn
Copy link
Member

jswrenn commented Jun 7, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 7, 2022

Build succeeded:

@bors bors bot merged commit 28cff76 into rust-itertools:master Jun 7, 2022
4 checks passed
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.

None yet

3 participants