Skip to content

Commit 6745258

Browse files
authored
Merge pull request #52 from DaniPopes/random-state-clone
Derive Clone for FxRandomState and FxSeededState
2 parents eb049a8 + 23fcdff commit 6745258

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/random_state.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub type FxHashSetRand<V> = HashSet<V, FxRandomState>;
1313
/// A particular instance `FxRandomState` will create the same instances of
1414
/// [`Hasher`], but the hashers created by two different `FxRandomState`
1515
/// instances are unlikely to produce the same result for the same values.
16+
#[derive(Clone)]
1617
pub struct FxRandomState {
1718
seed: usize,
1819
}
@@ -62,6 +63,14 @@ mod tests {
6263

6364
use crate::FxHashMapRand;
6465

66+
#[test]
67+
fn cloned_random_states_are_equal() {
68+
let a = FxHashMapRand::<&str, u32>::default();
69+
let b = a.clone();
70+
71+
assert_eq!(a.hasher().seed, b.hasher().seed);
72+
}
73+
6574
#[test]
6675
fn random_states_are_different() {
6776
let a = FxHashMapRand::<&str, u32>::default();

src/seeded_state.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub type FxHashSetSeed<V> = std::collections::HashSet<V, FxSeededState>;
1818
/// map.insert(15, 610);
1919
/// assert_eq!(map[&15], 610);
2020
/// ```
21+
#[derive(Clone)]
2122
pub struct FxSeededState {
2223
seed: usize,
2324
}
@@ -43,6 +44,18 @@ mod tests {
4344

4445
use crate::FxSeededState;
4546

47+
#[test]
48+
fn cloned_seeded_states_are_equal() {
49+
let seed = 2;
50+
let a = FxSeededState::with_seed(seed);
51+
let b = a.clone();
52+
53+
assert_eq!(a.seed, b.seed);
54+
assert_eq!(a.seed, seed);
55+
56+
assert_eq!(a.build_hasher().hash, b.build_hasher().hash);
57+
}
58+
4659
#[test]
4760
fn same_seed_produces_same_hasher() {
4861
let seed = 1;

0 commit comments

Comments
 (0)