-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
At least for HashMap
’s default hasher, a call to Hasher::finish()
will not reset the hasher’s internal state. Instead, additional write()
s will modify the hasher’s existing state as if finish()
had never been called:
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
fn main() {
let mut hasher = DefaultHasher::new();
0u8.hash(&mut hasher);
let h1 = hasher.finish();
0u8.hash(&mut hasher);
let h2 = hasher.finish();
println!("h1: {}\nh2: {}", h1, h2);
}
will produce
h1: 7541581120933061747
h2: 6165216591721696495
Is this intended behavior? If so, this should probably mentioned in the documentation as it is somewhat surprising given the name of the method. I am happy to create a PR but wanted to check first.
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.