File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
src/libstd/collections/hash Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change 1
- // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -139,13 +139,11 @@ impl SafeHash {
139
139
/// This function wraps up `hash_keyed` to be the only way outside this
140
140
/// module to generate a SafeHash.
141
141
pub fn make_hash < Sized ? T : Hash < S > , S , H : Hasher < S > > ( hasher : & H , t : & T ) -> SafeHash {
142
- match hasher. hash ( t) {
143
- // This constant is exceedingly likely to hash to the same
144
- // bucket, but it won't be counted as empty! Just so we can maintain
145
- // our precious uniform distribution of initial indexes.
146
- EMPTY_BUCKET => SafeHash { hash : 0x8000_0000_0000_0000 } ,
147
- h => SafeHash { hash : h } ,
148
- }
142
+ // We need to avoid 0u64 in order to prevent collisions with
143
+ // EMPTY_HASH. We can maintain our precious uniform distribution
144
+ // of initial indexes by unconditionally setting the MSB,
145
+ // effectively reducing 64-bits hashes to 63 bits.
146
+ SafeHash { hash : 0x8000_0000_0000_0000 | hasher. hash ( t) }
149
147
}
150
148
151
149
// `replace` casts a `*u64` to a `*SafeHash`. Since we statically
You can’t perform that action at this time.
0 commit comments