File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -134,15 +134,22 @@ fn h1(hash: u64) -> usize {
134
134
hash as usize
135
135
}
136
136
137
+ // Constant for h2 function that grabing the top 7 bits of the hash.
138
+ const MIN_HASH_LEN : usize = if mem:: size_of :: < usize > ( ) < mem:: size_of :: < u64 > ( ) {
139
+ mem:: size_of :: < usize > ( )
140
+ } else {
141
+ mem:: size_of :: < u64 > ( )
142
+ } ;
143
+
137
144
/// Secondary hash function, saved in the low 7 bits of the control byte.
138
145
#[ inline]
139
146
#[ allow( clippy:: cast_possible_truncation) ]
140
147
fn h2 ( hash : u64 ) -> u8 {
141
148
// Grab the top 7 bits of the hash. While the hash is normally a full 64-bit
142
149
// value, some hash functions (such as FxHash) produce a usize result
143
150
// instead, which means that the top 32 bits are 0 on 32-bit platforms.
144
- let hash_len = usize :: min ( mem :: size_of :: < usize > ( ) , mem :: size_of :: < u64 > ( ) ) ;
145
- let top7 = hash >> ( hash_len * 8 - 7 ) ;
151
+ // So we use MIN_HASH_LEN constant to handle this.
152
+ let top7 = hash >> ( MIN_HASH_LEN * 8 - 7 ) ;
146
153
( top7 & 0x7f ) as u8 // truncation
147
154
}
148
155
You can’t perform that action at this time.
0 commit comments