From 1fa0be2bc038e0575a601ba0273cd83d91d064f2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 21 Jan 2016 10:28:39 -0800 Subject: std: Stabilize custom hasher support in HashMap This commit implements the stabilization of the custom hasher support intended for 1.7 but left out due to some last-minute questions that needed some decisions. A summary of the actions done in this PR are: Stable * `std::hash::BuildHasher` * `BuildHasher::Hasher` * `BuildHasher::build_hasher` * `std::hash::BuildHasherDefault` * `HashMap::with_hasher` * `HashMap::with_capacity_and_hasher` * `HashSet::with_hasher` * `HashSet::with_capacity_and_hasher` * `std::collections::hash_map::RandomState` * `RandomState::new` Deprecated * `std::collections::hash_state` * `std::collections::hash_state::HashState` - this trait was also moved into `std::hash` with a reexport here to ensure that we can have a blanket impl to prevent immediate breakage on nightly. Note that this is unstable in both location. * `HashMap::with_hash_state` - renamed * `HashMap::with_capacity_and_hash_state` - renamed * `HashSet::with_hash_state` - renamed * `HashSet::with_capacity_and_hash_state` - renamed Closes #27713 --- src/libserialize/collection_impls.rs | 15 +++++++-------- src/libserialize/lib.rs | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/libserialize') diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index e21307cc752..804e1af19ab 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -10,8 +10,7 @@ //! Implementations of serialization for structures found in libcollections -use std::hash::Hash; -use std::collections::hash_state::HashState; +use std::hash::{Hash, BuildHasher}; use std::mem; use {Decodable, Encodable, Decoder, Encoder}; @@ -159,7 +158,7 @@ impl< impl Encodable for HashMap where K: Encodable + Hash + Eq, V: Encodable, - S: HashState, + S: BuildHasher, { fn encode(&self, e: &mut E) -> Result<(), E::Error> { e.emit_map(self.len(), |e| { @@ -177,12 +176,12 @@ impl Encodable for HashMap impl Decodable for HashMap where K: Decodable + Hash + Eq, V: Decodable, - S: HashState + Default, + S: BuildHasher + Default, { fn decode(d: &mut D) -> Result, D::Error> { d.read_map(|d, len| { let state = Default::default(); - let mut map = HashMap::with_capacity_and_hash_state(len, state); + let mut map = HashMap::with_capacity_and_hasher(len, state); for i in 0..len { let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d))); let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d))); @@ -195,7 +194,7 @@ impl Decodable for HashMap impl Encodable for HashSet where T: Encodable + Hash + Eq, - S: HashState, + S: BuildHasher, { fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { @@ -211,12 +210,12 @@ impl Encodable for HashSet impl Decodable for HashSet where T: Decodable + Hash + Eq, - S: HashState + Default, + S: BuildHasher + Default, { fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let state = Default::default(); - let mut set = HashSet::with_capacity_and_hash_state(len, state); + let mut set = HashSet::with_capacity_and_hasher(len, state); for i in 0..len { set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d)))); } diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 910600d91e4..8bb596c8bb2 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -29,7 +29,6 @@ Core encoding and decoding interfaces. #![feature(box_syntax)] #![feature(collections)] #![feature(enumset)] -#![feature(hashmap_hasher)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(str_char)] -- cgit 1.4.1-3-g733a5