@@ -32,11 +32,13 @@ This crate has only single feature used exclusively for benchmarking.
32
32
C++ implementations.
33
33
*/
34
34
#![ no_std]
35
-
35
+ #![ allow( clippy:: many_single_char_names) ]
36
+ // This is a false positive: https://github.com/rust-lang/rust-clippy/issues/7580 :
37
+ #![ allow( clippy:: blocks_in_if_conditions) ]
36
38
use core:: num:: Wrapping ;
37
39
38
- type w64 = Wrapping < u64 > ;
39
- type w32 = Wrapping < u32 > ;
40
+ type W64 = Wrapping < u64 > ;
41
+ type W32 = Wrapping < u32 > ;
40
42
41
43
/** C++ CityHash-compatible uint128 type. Please note that From<u128>
42
44
* and Into<u128> are defined for this type.
@@ -52,7 +54,7 @@ impl U128 {
52
54
Self { lo, hi }
53
55
}
54
56
55
- const fn from_w64 ( lo : w64 , hi : w64 ) -> Self {
57
+ const fn from_w64 ( lo : W64 , hi : W64 ) -> Self {
56
58
Self { lo : lo. 0 , hi : hi. 0 }
57
59
}
58
60
}
@@ -72,55 +74,55 @@ impl From<U128> for u128 {
72
74
}
73
75
}
74
76
75
- const fn w64 ( v : u64 ) -> w64 {
77
+ const fn w64 ( v : u64 ) -> W64 {
76
78
Wrapping ( v)
77
79
}
78
80
79
- const fn w32 ( v : u32 ) -> w32 {
81
+ const fn w32 ( v : u32 ) -> W32 {
80
82
Wrapping ( v)
81
83
}
82
84
83
85
// Some primes between 2^63 and 2^64 for various uses.
84
- const K0 : w64 = w64 ( 0xc3a5c85c97cb3127u64 ) ;
85
- const K1 : w64 = w64 ( 0xb492b66fbe98f273u64 ) ;
86
- const K2 : w64 = w64 ( 0x9ae16a3b2f90404fu64 ) ;
87
- const K3 : w64 = w64 ( 0xc949d7c7509e6557u64 ) ;
86
+ const K0 : W64 = w64 ( 0xc3a5c85c97cb3127u64 ) ;
87
+ const K1 : W64 = w64 ( 0xb492b66fbe98f273u64 ) ;
88
+ const K2 : W64 = w64 ( 0x9ae16a3b2f90404fu64 ) ;
89
+ const K3 : W64 = w64 ( 0xc949d7c7509e6557u64 ) ;
88
90
89
91
#[ inline]
90
- unsafe fn fetch64 ( s : * const u8 ) -> w64 {
92
+ unsafe fn fetch64 ( s : * const u8 ) -> W64 {
91
93
w64 ( ( s as * const u64 ) . read_unaligned ( ) . to_le ( ) )
92
94
}
93
95
94
96
#[ inline]
95
- unsafe fn fetch32 ( s : * const u8 ) -> w32 {
97
+ unsafe fn fetch32 ( s : * const u8 ) -> W32 {
96
98
w32 ( ( s as * const u32 ) . read_unaligned ( ) . to_le ( ) )
97
99
}
98
100
99
101
#[ inline]
100
- fn rotate ( v : w64 , n : u32 ) -> w64 {
102
+ fn rotate ( v : W64 , n : u32 ) -> W64 {
101
103
debug_assert ! ( n > 0 ) ;
102
104
// Look, ma, I have real rotate!
103
105
// rotate_right for Wrapping is yet unstable, so we unwrap and wrap it back.
104
106
w64 ( v. 0 . rotate_right ( n) )
105
107
}
106
108
107
- fn hash_len16 ( u : w64 , v : w64 ) -> w64 {
109
+ fn hash_len16 ( u : W64 , v : W64 ) -> W64 {
108
110
hash128_to_64 ( u, v)
109
111
}
110
112
111
113
// Hash 128 input bits down to 64 bits of output.
112
114
// This is intended to be a reasonably good hash function.
113
115
#[ inline]
114
- fn hash128_to_64 ( l : w64 , h : w64 ) -> w64 {
115
- const K_MUL : w64 = w64 ( 0x9ddfea08eb382d69u64 ) ;
116
+ fn hash128_to_64 ( l : W64 , h : W64 ) -> W64 {
117
+ const K_MUL : W64 = w64 ( 0x9ddfea08eb382d69u64 ) ;
116
118
let mut a = ( h ^ l) * K_MUL ;
117
119
a ^= a >> 47 ;
118
120
let mut b = ( h ^ a) * K_MUL ;
119
121
b ^= b >> 47 ;
120
122
b * K_MUL
121
123
}
122
124
123
- unsafe fn hash_len0to16 ( data : & [ u8 ] ) -> w64 {
125
+ unsafe fn hash_len0to16 ( data : & [ u8 ] ) -> W64 {
124
126
let len = data. len ( ) ;
125
127
let s = data. as_ptr ( ) ;
126
128
@@ -148,7 +150,7 @@ unsafe fn hash_len0to16(data: &[u8]) -> w64 {
148
150
}
149
151
}
150
152
151
- unsafe fn hash_len17to32 ( data : & [ u8 ] ) -> w64 {
153
+ unsafe fn hash_len17to32 ( data : & [ u8 ] ) -> W64 {
152
154
let s = data. as_ptr ( ) ;
153
155
let len = data. len ( ) ;
154
156
@@ -162,7 +164,7 @@ unsafe fn hash_len17to32(data: &[u8]) -> w64 {
162
164
)
163
165
}
164
166
165
- unsafe fn hash_len33to64 ( data : & [ u8 ] ) -> w64 {
167
+ unsafe fn hash_len33to64 ( data : & [ u8 ] ) -> W64 {
166
168
let s = data. as_ptr ( ) ;
167
169
let len = data. len ( ) ;
168
170
@@ -189,7 +191,7 @@ unsafe fn hash_len33to64(data: &[u8]) -> w64 {
189
191
shift_mix ( vs + r * K0 ) * K2
190
192
}
191
193
192
- unsafe fn weak_hash_len32_with_seeds ( s : * const u8 , a : w64 , b : w64 ) -> ( w64 , w64 ) {
194
+ unsafe fn weak_hash_len32_with_seeds ( s : * const u8 , a : W64 , b : W64 ) -> ( W64 , W64 ) {
193
195
weak_hash_len32_with_seeds_ (
194
196
fetch64 ( s) ,
195
197
fetch64 ( s. add ( 8 ) ) ,
@@ -201,13 +203,13 @@ unsafe fn weak_hash_len32_with_seeds(s: *const u8, a: w64, b: w64) -> (w64, w64)
201
203
}
202
204
203
205
unsafe fn weak_hash_len32_with_seeds_ (
204
- w : w64 ,
205
- x : w64 ,
206
- y : w64 ,
207
- z : w64 ,
208
- mut a : w64 ,
209
- mut b : w64 ,
210
- ) -> ( w64 , w64 ) {
206
+ w : W64 ,
207
+ x : W64 ,
208
+ y : W64 ,
209
+ z : W64 ,
210
+ mut a : W64 ,
211
+ mut b : W64 ,
212
+ ) -> ( W64 , W64 ) {
211
213
a += w;
212
214
b = rotate ( b + a + z, 21 ) ;
213
215
let c = a;
@@ -216,7 +218,7 @@ unsafe fn weak_hash_len32_with_seeds_(
216
218
( a + z, b + c)
217
219
}
218
220
219
- fn shift_mix ( val : w64 ) -> w64 {
221
+ fn shift_mix ( val : W64 ) -> W64 {
220
222
val ^ ( val >> 47 )
221
223
}
222
224
@@ -244,8 +246,8 @@ pub fn cityhash64(data: &[u8]) -> u64 {
244
246
let mut y = fetch64 ( s. add ( len) . sub ( 16 ) ) ^ K1 ;
245
247
let mut z = fetch64 ( s. add ( len) . sub ( 56 ) ) ^ K0 ;
246
248
247
- let mut v: ( w64 , w64 ) = weak_hash_len32_with_seeds ( s. add ( len) . sub ( 64 ) , w64 ( len as u64 ) , y) ;
248
- let mut w: ( w64 , w64 ) =
249
+ let mut v: ( W64 , W64 ) = weak_hash_len32_with_seeds ( s. add ( len) . sub ( 64 ) , w64 ( len as u64 ) , y) ;
250
+ let mut w: ( W64 , W64 ) =
249
251
weak_hash_len32_with_seeds ( s. add ( len) . sub ( 32 ) , K1 * w64 ( len as u64 ) , K0 ) ;
250
252
251
253
z += shift_mix ( v. 1 ) * K1 ;
@@ -284,8 +286,8 @@ unsafe fn city_murmur(data: &[u8], seed: U128) -> U128 {
284
286
285
287
let mut a = w64 ( seed. lo ) ;
286
288
let mut b = w64 ( seed. hi ) ;
287
- let mut c: w64 ;
288
- let mut d: w64 ;
289
+ let mut c: W64 ;
290
+ let mut d: W64 ;
289
291
let mut l = ( len as isize ) - 16 ;
290
292
291
293
if l <= 0 {
0 commit comments