@@ -17,6 +17,9 @@ use ptr;
1717
1818/// An implementation of SipHash 1-3.
1919///
20+ /// This is currently the default hashing function used by standard library
21+ /// (eg. `collections::HashMap` uses it by default).
22+ ///
2023/// See: https://131002.net/siphash/
2124#[ unstable( feature = "sip_hash_13" , issue = "34767" ) ]
2225#[ rustc_deprecated( since = "1.13.0" , reason = "use `DefaultHasher` instead" ) ]
@@ -39,9 +42,6 @@ pub struct SipHasher24 {
3942///
4043/// See: https://131002.net/siphash/
4144///
42- /// This is currently the default hashing function used by standard library
43- /// (eg. `collections::HashMap` uses it by default).
44- ///
4545/// SipHash is a general-purpose hashing function: it runs at a good
4646/// speed (competitive with Spooky and City) and permits strong _keyed_
4747/// 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 {
117117 data. to_le ( )
118118}
119119
120- macro_rules! rotl {
121- ( $x: expr, $b: expr) =>
122- ( ( $x << $b) | ( $x >> ( 64_i32 . wrapping_sub( $b) ) ) )
123- }
124-
125120macro_rules! compress {
126121 ( $state: expr) => ( {
127122 compress!( $state. v0, $state. v1, $state. v2, $state. v3)
128123 } ) ;
129124 ( $v0: expr, $v1: expr, $v2: expr, $v3: expr) =>
130125 ( {
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 ) ;
137132 } ) ;
138133}
139134
0 commit comments