-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std: Stabilize custom hasher support in HashMap #31081
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r? @aturon cc @rust-lang/libs nominating for a beta-backport |
Everything here seems reasonable and as was discussed. 👍 |
pub fn with_hash_state(hash_state: S) -> HashMap<K, V, S> { | ||
HashMap::with_hasher(hash_state) | ||
} | ||
|
||
/// Creates an empty HashMap with space for at least `capacity` |
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.
Should we give the same warning about DoS here?
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.
Ooops, github just had it collapsed, nevermind.
LGTM -- though I did leave one question about the actual API. I suspect I'm just failing to remember one of the design constraints here. |
eaff046
to
ad2f9af
Compare
@aturon I've updated with removing the old and misleading |
ad2f9af
to
306bd59
Compare
This looks good to go, right? |
@alexcrichton corrected the wrong docs problem :) I still find the docs super misleading, but we can fix in post if you prefer. That's my only complaint. |
I'm fine changing the docs, but I'm not really quite sure what to change them to? Do you have something in mind @aturon ? |
@@ -190,6 +191,79 @@ pub trait Hasher { | |||
} | |||
} | |||
|
|||
/// A trait representing an object which maintains state to create new instances |
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.
Suggestion: nix this sentence.
@alexcrichton Left some minimal suggestions. With that r=me. |
This commit implements the stabilization of the custom hasher support intended for 1.7 but left out due to some last-minute questions that needed some decisions. A summary of the actions done in this PR are: Stable * `std::hash::BuildHasher` * `BuildHasher::Hasher` * `BuildHasher::build_hasher` * `std::hash::BuildHasherDefault` * `HashMap::with_hasher` * `HashMap::with_capacity_and_hasher` * `HashSet::with_hasher` * `HashSet::with_capacity_and_hasher` * `std::collections::hash_map::RandomState` * `RandomState::new` Deprecated * `std::collections::hash_state` * `std::collections::hash_state::HashState` - this trait was also moved into `std::hash` with a reexport here to ensure that we can have a blanket impl to prevent immediate breakage on nightly. Note that this is unstable in both location. * `HashMap::with_hash_state` - renamed * `HashMap::with_capacity_and_hash_state` - renamed * `HashSet::with_hash_state` - renamed * `HashSet::with_capacity_and_hash_state` - renamed Closes rust-lang#27713
306bd59
to
1fa0be2
Compare
This commit implements the stabilization of the custom hasher support intended for 1.7 but left out due to some last-minute questions that needed some decisions. A summary of the actions done in this PR are: Stable * `std::hash::BuildHasher` * `BuildHasher::Hasher` * `BuildHasher::build_hasher` * `std::hash::BuildHasherDefault` * `HashMap::with_hasher` * `HashMap::with_capacity_and_hasher` * `HashSet::with_hasher` * `HashSet::with_capacity_and_hasher` * `std::collections::hash_map::RandomState` * `RandomState::new` Deprecated * `std::collections::hash_state` * `std::collections::hash_state::HashState` - this trait was also moved into `std::hash` with a reexport here to ensure that we can have a blanket impl to prevent immediate breakage on nightly. Note that this is unstable in both location. * `HashMap::with_hash_state` - renamed * `HashMap::with_capacity_and_hash_state` - renamed * `HashSet::with_hash_state` - renamed * `HashSet::with_capacity_and_hash_state` - renamed Closes #27713
Marking as accepted for beta as libs talked about this awhile ago |
This commit implements the stabilization of the custom hasher support intended
for 1.7 but left out due to some last-minute questions that needed some
decisions. A summary of the actions done in this PR are:
Stable
std::hash::BuildHasher
BuildHasher::Hasher
BuildHasher::build_hasher
std::hash::BuildHasherDefault
HashMap::with_hasher
HashMap::with_capacity_and_hasher
HashSet::with_hasher
HashSet::with_capacity_and_hasher
std::collections::hash_map::RandomState
RandomState::new
Deprecated
std::collections::hash_state
std::collections::hash_state::HashState
- this trait was also moved intostd::hash
with a reexport here to ensure that we can have a blanket impl toprevent immediate breakage on nightly. Note that this is unstable in both
location.
HashMap::with_hash_state
- renamedHashMap::with_capacity_and_hash_state
- renamedHashSet::with_hash_state
- renamedHashSet::with_capacity_and_hash_state
- renamedCloses #27713