@@ -17,6 +17,9 @@ use ptr;
17
17
18
18
/// An implementation of SipHash 1-3.
19
19
///
20
+ /// This is currently the default hashing function used by standard library
21
+ /// (eg. `collections::HashMap` uses it by default).
22
+ ///
20
23
/// See: https://131002.net/siphash/
21
24
#[ unstable( feature = "sip_hash_13" , issue = "34767" ) ]
22
25
#[ rustc_deprecated( since = "1.13.0" , reason = "use `DefaultHasher` instead" ) ]
@@ -39,9 +42,6 @@ pub struct SipHasher24 {
39
42
///
40
43
/// See: https://131002.net/siphash/
41
44
///
42
- /// This is currently the default hashing function used by standard library
43
- /// (eg. `collections::HashMap` uses it by default).
44
- ///
45
45
/// SipHash is a general-purpose hashing function: it runs at a good
46
46
/// speed (competitive with Spooky and City) and permits strong _keyed_
47
47
/// hashing. This lets you key your hashtables from a strong RNG, such as
@@ -117,23 +117,18 @@ unsafe fn load_u64_le(buf: &[u8], i: usize) -> u64 {
117
117
data. to_le ( )
118
118
}
119
119
120
- macro_rules! rotl {
121
- ( $x: expr, $b: expr) =>
122
- ( ( $x << $b) | ( $x >> ( 64_i32 . wrapping_sub( $b) ) ) )
123
- }
124
-
125
120
macro_rules! compress {
126
121
( $state: expr) => ( {
127
122
compress!( $state. v0, $state. v1, $state. v2, $state. v3)
128
123
} ) ;
129
124
( $v0: expr, $v1: expr, $v2: expr, $v3: expr) =>
130
125
( {
131
- $v0 = $v0. wrapping_add( $v1) ; $v1 = rotl! ( $v1, 13 ) ; $v1 ^= $v0;
132
- $v0 = rotl! ( $v0, 32 ) ;
133
- $v2 = $v2. wrapping_add( $v3) ; $v3 = rotl! ( $v3, 16 ) ; $v3 ^= $v2;
134
- $v0 = $v0. wrapping_add( $v3) ; $v3 = rotl! ( $v3, 21 ) ; $v3 ^= $v0;
135
- $v2 = $v2. wrapping_add( $v1) ; $v1 = rotl! ( $v1, 17 ) ; $v1 ^= $v2;
136
- $v2 = rotl! ( $v2, 32 ) ;
126
+ $v0 = $v0. wrapping_add( $v1) ; $v1 = $v1. rotate_left ( 13 ) ; $v1 ^= $v0;
127
+ $v0 = $v0. rotate_left ( 32 ) ;
128
+ $v2 = $v2. wrapping_add( $v3) ; $v3 = $v3. rotate_left ( 16 ) ; $v3 ^= $v2;
129
+ $v0 = $v0. wrapping_add( $v3) ; $v3 = $v3. rotate_left ( 21 ) ; $v3 ^= $v0;
130
+ $v2 = $v2. wrapping_add( $v1) ; $v1 = $v1. rotate_left ( 17 ) ; $v1 ^= $v2;
131
+ $v2 = $v2. rotate_left ( 32 ) ;
137
132
} ) ;
138
133
}
139
134
0 commit comments