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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/unique_impl.rs
@@ -1,6 +1,5 @@

use std::collections::HashMap;
use std::collections::hash_map::{Entry};
use std::collections::hash_map::Entry;
use std::hash::Hash;
use std::fmt;
use std::iter::FusedIterator;
Expand All @@ -12,7 +11,9 @@ use std::iter::FusedIterator;
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct UniqueBy<I: Iterator, V, F> {
iter: I,
// Use a hashmap for the entry API
// Use a Hashmap for the Entry API in order to prevent hashing twice.
// This can maybe be replaced with a HashSet once `get_or_insert_with`
// or a proper Entry API for Hashset is stable and meets this msrv
used: HashMap<V, ()>,
f: F,
}
Expand Down