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:#️⃣:BuildHasher` * `BuildHasher::Hasher` * `BuildHasher::build_hasher` * `std:#️⃣: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
This commit is contained in:
@@ -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<K, V, S> Encodable for HashMap<K, V, S>
|
||||
where K: Encodable + Hash + Eq,
|
||||
V: Encodable,
|
||||
S: HashState,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn encode<E: Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
|
||||
e.emit_map(self.len(), |e| {
|
||||
@@ -177,12 +176,12 @@ impl<K, V, S> Encodable for HashMap<K, V, S>
|
||||
impl<K, V, S> Decodable for HashMap<K, V, S>
|
||||
where K: Decodable + Hash + Eq,
|
||||
V: Decodable,
|
||||
S: HashState + Default,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<HashMap<K, V, S>, 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<K, V, S> Decodable for HashMap<K, V, S>
|
||||
|
||||
impl<T, S> Encodable for HashSet<T, S>
|
||||
where T: Encodable + Hash + Eq,
|
||||
S: HashState,
|
||||
S: BuildHasher,
|
||||
{
|
||||
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
@@ -211,12 +210,12 @@ impl<T, S> Encodable for HashSet<T, S>
|
||||
|
||||
impl<T, S> Decodable for HashSet<T, S>
|
||||
where T: Decodable + Hash + Eq,
|
||||
S: HashState + Default,
|
||||
S: BuildHasher + Default,
|
||||
{
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<HashSet<T, S>, 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))));
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user