Skip to content

Derive Eq for RandomState #32068

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
/// A particular instance `RandomState` will create the same instances of
/// `Hasher`, but the hashers created by two different `RandomState`
/// instances are unlikely to produce the same result for the same values.
#[derive(Clone)]
#[derive(Clone, PartialEq, Eq)]
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
pub struct RandomState {
k0: u64,
Expand Down Expand Up @@ -1732,6 +1732,8 @@ mod test_map {

use super::HashMap;
use super::Entry::{Occupied, Vacant};
use super::RandomState;
use hash::{Hash, BuildHasher, Hasher};
use cell::RefCell;
use rand::{thread_rng, Rng};

Expand Down Expand Up @@ -2454,4 +2456,20 @@ mod test_map {
a.insert(item, 0);
assert!(a.capacity() > a.len());
}


#[test]
fn test_randomstate_eq() {
let a = RandomState::new();
let b = a.clone();
assert!(a == b);

let mut a_hasher = a.build_hasher();
let mut b_hasher = b.build_hasher();

1u32.hash(&mut a_hasher);
1u32.hash(&mut b_hasher);

assert_eq!(a_hasher.finish(), b_hasher.finish())
}
}