Closed
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.