1pub mod sixty_four {
2 use crate::XxHash64;
3 use core::hash::BuildHasher;
4 use rand::{self, Rng};
5
6 #[derive(Clone)]
7 /// Constructs a randomized seed and reuses it for multiple hasher instances.
8 pub struct RandomXxHashBuilder64(u64);
9
10 impl RandomXxHashBuilder64 {
11 fn new() -> RandomXxHashBuilder64 {
12 RandomXxHashBuilder64(rand::thread_rng().gen())
13 }
14 }
15
16 impl Default for RandomXxHashBuilder64 {
17 fn default() -> RandomXxHashBuilder64 {
18 RandomXxHashBuilder64::new()
19 }
20 }
21
22 impl BuildHasher for RandomXxHashBuilder64 {
23 type Hasher = XxHash64;
24
25 fn build_hasher(&self) -> XxHash64 {
26 XxHash64::with_seed(self.0)
27 }
28 }
29}
30
31pub mod thirty_two {
32 use crate::XxHash32;
33 use core::hash::BuildHasher;
34 use rand::{self, Rng};
35
36 #[derive(Clone)]
37 /// Constructs a randomized seed and reuses it for multiple hasher instances. See the usage warning on `XxHash32`.
38 pub struct RandomXxHashBuilder32(u32);
39
40 impl RandomXxHashBuilder32 {
41 fn new() -> RandomXxHashBuilder32 {
42 RandomXxHashBuilder32(rand::thread_rng().gen())
43 }
44 }
45
46 impl Default for RandomXxHashBuilder32 {
47 fn default() -> RandomXxHashBuilder32 {
48 RandomXxHashBuilder32::new()
49 }
50 }
51
52 impl BuildHasher for RandomXxHashBuilder32 {
53 type Hasher = XxHash32;
54
55 fn build_hasher(&self) -> XxHash32 {
56 XxHash32::with_seed(self.0)
57 }
58 }
59}
60
61pub mod xxh3 {
62 use crate::xxh3::{Hash128, Hash64};
63 use core::hash::BuildHasher;
64 use rand::{self, Rng};
65
66 #[derive(Clone)]
67 /// Constructs a randomized seed and reuses it for multiple hasher instances.
68 pub struct RandomHashBuilder64(u64);
69
70 impl RandomHashBuilder64 {
71 fn new() -> RandomHashBuilder64 {
72 RandomHashBuilder64(rand::thread_rng().gen())
73 }
74 }
75
76 impl Default for RandomHashBuilder64 {
77 fn default() -> RandomHashBuilder64 {
78 RandomHashBuilder64::new()
79 }
80 }
81
82 impl BuildHasher for RandomHashBuilder64 {
83 type Hasher = Hash64;
84
85 fn build_hasher(&self) -> Hash64 {
86 Hash64::with_seed(self.0)
87 }
88 }
89
90 #[derive(Clone)]
91 /// Constructs a randomized seed and reuses it for multiple hasher instances.
92 pub struct RandomHashBuilder128(u64);
93
94 impl RandomHashBuilder128 {
95 fn new() -> RandomHashBuilder128 {
96 RandomHashBuilder128(rand::thread_rng().gen())
97 }
98 }
99
100 impl Default for RandomHashBuilder128 {
101 fn default() -> RandomHashBuilder128 {
102 RandomHashBuilder128::new()
103 }
104 }
105
106 impl BuildHasher for RandomHashBuilder128 {
107 type Hasher = Hash128;
108
109 fn build_hasher(&self) -> Hash128 {
110 Hash128::with_seed(self.0)
111 }
112 }
113}
114