diff options
| author | bors <bors@rust-lang.org> | 2016-07-01 15:53:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-01 15:53:07 -0700 |
| commit | 01411937ff6b2a2dfad03d060d636941b0034591 (patch) | |
| tree | d2823f782d60f21ba04e03fc7364c73acdb5891b /src/libstd | |
| parent | 5661be01b61bbd22afbd95fde88591bc50947b42 (diff) | |
| parent | db1b1919baba8be48d997d9f70a6a5df7e31612a (diff) | |
| download | rust-01411937ff6b2a2dfad03d060d636941b0034591.tar.gz rust-01411937ff6b2a2dfad03d060d636941b0034591.zip | |
Auto merge of #33940 - seanmonstar:siphash-1-3, r=alexcrichton
hashmap: use siphash-1-3 as default hasher Also exposes `SipHash13` and `SipHash24` in `core::hash::sip`, for those that want to differentiate. For motivation, see this quote from the original issue: > we proposed SipHash-2-4 as a (strong) PRF/MAC, and so far no attack whatsoever has been found, although many competent people tried to break it. However, fewer rounds may be sufficient and I would be very surprised if SipHash-1-3 introduced weaknesses for hash tables. This keeps a type alias of `SipHasher` to `SipHash24`, and since the internal default hasher of HashMap is specified as "not specified", changing it should not be a breaking change. Closes #29754
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 28 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 1 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 536f168e401..60d7e01d988 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -14,7 +14,7 @@ use self::VacantEntryState::*; use borrow::Borrow; use cmp::max; use fmt::{self, Debug}; -use hash::{Hash, SipHasher, BuildHasher}; +use hash::{Hash, Hasher, BuildHasher, SipHasher13}; use iter::FromIterator; use mem::{self, replace}; use ops::{Deref, Index}; @@ -1711,10 +1711,30 @@ impl RandomState { #[stable(feature = "hashmap_build_hasher", since = "1.7.0")] impl BuildHasher for RandomState { - type Hasher = SipHasher; + type Hasher = DefaultHasher; #[inline] - fn build_hasher(&self) -> SipHasher { - SipHasher::new_with_keys(self.k0, self.k1) + fn build_hasher(&self) -> DefaultHasher { + DefaultHasher(SipHasher13::new_with_keys(self.k0, self.k1)) + } +} + +/// The default `Hasher` used by `RandomState`. +/// +/// The internal algorithm is not specified, and so it and its hashes should +/// not be relied upon over releases. +#[unstable(feature = "hashmap_default_hasher", issue = "0")] +pub struct DefaultHasher(SipHasher13); + +#[unstable(feature = "hashmap_default_hasher", issue = "0")] +impl Hasher for DefaultHasher { + #[inline] + fn write(&mut self, msg: &[u8]) { + self.0.write(msg) + } + + #[inline] + fn finish(&self) -> u64 { + self.0.finish() } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 135ea8a5e7c..a396c7be09a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -255,6 +255,7 @@ #![feature(reflect_marker)] #![feature(rustc_attrs)] #![feature(shared)] +#![feature(sip_hash_13)] #![feature(slice_bytes)] #![feature(slice_concat_ext)] #![feature(slice_patterns)] |
