@@ -33,6 +33,8 @@ use std::num::NonZeroU64;
33
33
#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize , serde:: Serialize ) ) ]
34
34
pub struct Id ( NonZeroU64 ) ;
35
35
36
+ impl nohash_hasher:: IsEnabled for Id { }
37
+
36
38
impl Id {
37
39
/// A special [`Id`], in particular as a key to [`crate::Memory::data`]
38
40
/// for when there is no particular widget to attach the data.
@@ -112,77 +114,8 @@ fn id_size() {
112
114
113
115
// ----------------------------------------------------------------------------
114
116
115
- // Idea taken from the `nohash_hasher` crate.
116
- #[ derive( Default ) ]
117
- pub struct IdHasher ( u64 ) ;
118
-
119
- impl std:: hash:: Hasher for IdHasher {
120
- fn write ( & mut self , _: & [ u8 ] ) {
121
- unreachable ! ( "Invalid use of IdHasher" ) ;
122
- }
123
-
124
- fn write_u8 ( & mut self , _n : u8 ) {
125
- unreachable ! ( "Invalid use of IdHasher" ) ;
126
- }
127
-
128
- fn write_u16 ( & mut self , _n : u16 ) {
129
- unreachable ! ( "Invalid use of IdHasher" ) ;
130
- }
131
-
132
- fn write_u32 ( & mut self , _n : u32 ) {
133
- unreachable ! ( "Invalid use of IdHasher" ) ;
134
- }
135
-
136
- #[ inline( always) ]
137
- fn write_u64 ( & mut self , n : u64 ) {
138
- self . 0 = n;
139
- }
140
-
141
- fn write_usize ( & mut self , _n : usize ) {
142
- unreachable ! ( "Invalid use of IdHasher" ) ;
143
- }
144
-
145
- fn write_i8 ( & mut self , _n : i8 ) {
146
- unreachable ! ( "Invalid use of IdHasher" ) ;
147
- }
148
-
149
- fn write_i16 ( & mut self , _n : i16 ) {
150
- unreachable ! ( "Invalid use of IdHasher" ) ;
151
- }
152
-
153
- fn write_i32 ( & mut self , _n : i32 ) {
154
- unreachable ! ( "Invalid use of IdHasher" ) ;
155
- }
156
-
157
- fn write_i64 ( & mut self , _n : i64 ) {
158
- unreachable ! ( "Invalid use of IdHasher" ) ;
159
- }
160
-
161
- fn write_isize ( & mut self , _n : isize ) {
162
- unreachable ! ( "Invalid use of IdHasher" ) ;
163
- }
164
-
165
- #[ inline( always) ]
166
- fn finish ( & self ) -> u64 {
167
- self . 0
168
- }
169
- }
170
-
171
- #[ derive( Copy , Clone , Debug , Default ) ]
172
- #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize , serde:: Serialize ) ) ]
173
- pub struct BuildIdHasher { }
174
-
175
- impl std:: hash:: BuildHasher for BuildIdHasher {
176
- type Hasher = IdHasher ;
177
-
178
- #[ inline( always) ]
179
- fn build_hasher ( & self ) -> IdHasher {
180
- IdHasher :: default ( )
181
- }
182
- }
183
-
184
117
/// `IdSet` is a `HashSet<Id>` optimized by knowing that [`Id`] has good entropy, and doesn't need more hashing.
185
- pub type IdSet = std :: collections :: HashSet < Id , BuildIdHasher > ;
118
+ pub type IdSet = nohash_hasher :: IntSet < Id > ;
186
119
187
120
/// `IdMap<V>` is a `HashMap<Id, V>` optimized by knowing that [`Id`] has good entropy, and doesn't need more hashing.
188
- pub type IdMap < V > = std :: collections :: HashMap < Id , V , BuildIdHasher > ;
121
+ pub type IdMap < V > = nohash_hasher :: IntMap < Id , V > ;
0 commit comments