@@ -23,7 +23,7 @@ use iter::{Iterator, ExactSizeIterator, IntoIterator, IteratorExt, FromIterator,
2323use marker:: Sized ;
2424use mem:: { self , swap, replace} ;
2525use num:: { Int , UnsignedInt } ;
26- use ops:: { Deref , DerefMut , Drop , FnMut , Index , IndexMut } ;
26+ use ops:: { Drop , FnMut , Index , IndexMut } ;
2727use option:: Option :: { self , Some , None } ;
2828use rand:: { self , Rng } ;
2929use result:: Result :: { self , Ok , Err } ;
@@ -33,7 +33,6 @@ use super::table::{
3333 Bucket ,
3434 EmptyBucket ,
3535 FullBucket ,
36- FullBucketImm ,
3736 FullBucketMut ,
3837 RawTable ,
3938 SafeHash ,
@@ -441,19 +440,19 @@ fn robin_hood<'a, K: 'a, V: 'a>(bucket: FullBucketMut<'a, K, V>,
441440
442441// Performs insertion with relaxed requirements.
443442// The caller should ensure that invariants of Robin Hood linear probing hold.
444- fn insert_hashed_ordered < M : Put , K , V > ( arg : M , hash : SafeHash , key : K , val : V ) -> M
443+ fn insert_hashed_ordered < M : Put , K , V > ( table : M , hash : SafeHash , key : K , val : V ) -> M
445444 where M : BorrowMut < RawTable < K , V > >
446445{
447446 let cap = table. borrow ( ) . capacity ( ) ;
448- let mut buckets = Bucket :: new ( table, h ) . unwrap ( ) ;
447+ let mut buckets = Bucket :: new ( table, hash ) . unwrap ( ) ;
449448 let ib = buckets. index ( ) ;
450449
451450 while buckets. index ( ) != ib + cap {
452451 // We don't need to compare hashes for value swap.
453452 // Not even DIBs for Robin Hood.
454453 buckets = match buckets. peek ( ) {
455454 Empty ( empty) => {
456- return empty. put ( h , k , v ) . into_table ( ) ;
455+ return empty. put ( hash , key , val ) . into_table ( ) ;
457456 }
458457 Full ( full) => full. into_bucket ( )
459458 } ;
@@ -474,19 +473,19 @@ impl<K, V, S> HashMap<K, V, S>
474473 /// If you already have the hash for the key lying around, use
475474 /// search_hashed.
476475 fn search < ' a , Q : ?Sized > ( & ' a self , q : & Q )
477- -> Option < InternalEntry < K , V , & ' a RawTable < K , V > > >
476+ -> ( InternalEntry < K , V , & ' a RawTable < K , V > > , SafeHash )
478477 where K : Borrow < Q > , Q : Eq + Hash
479478 {
480479 let hash = self . make_hash ( q) ;
481- search_hashed ( & self . table , hash, |k| q. eq ( k. borrow ( ) ) )
480+ ( search_hashed ( & self . table , hash, |k| q. eq ( k. borrow ( ) ) ) , hash )
482481 }
483482
484483 fn search_mut < ' a , Q : ?Sized > ( & ' a mut self , q : & Q )
485- -> Option < InternalEntry < K , V , & ' a mut RawTable < K , V > > >
484+ -> ( InternalEntry < K , V , & ' a mut RawTable < K , V > > , SafeHash )
486485 where K : Borrow < Q > , Q : Eq + Hash
487486 {
488487 let hash = self . make_hash ( q) ;
489- search_hashed ( & mut self . table , hash, |k| q. eq ( k. borrow ( ) ) )
488+ ( search_hashed ( & mut self . table , hash, |k| q. eq ( k. borrow ( ) ) ) , hash )
490489 }
491490}
492491
@@ -645,7 +644,7 @@ impl<K, V, S> HashMap<K, V, S>
645644 // Grow the table.
646645 let is_inplace = self . table . grow_inplace ( new_capacity) ;
647646
648- let mut destination = if is_inplace {
647+ let destination = if is_inplace {
649648 // Resizing in-place.
650649 None
651650 } else {
@@ -764,9 +763,9 @@ impl<K, V, S> HashMap<K, V, S>
764763
765764 // Shrink the table. Naive algorithm for resizing:
766765 while let Some ( ( h, k, v) ) = old_table. take_front ( ) {
767- match search_hashed ( & mut self . table , hash , |key| * key == k) {
766+ match search_hashed ( & mut self . table , h , |key| * key == k) {
768767 InternalEntry :: Vacant ( entry) => {
769- entry. insert ( hash , k, v) ;
768+ entry. insert ( h , k, v) ;
770769 }
771770 InternalEntry :: Occupied ( mut entry) => {
772771 entry. insert ( v) ;
@@ -779,24 +778,24 @@ impl<K, V, S> HashMap<K, V, S>
779778 }
780779 }
781780
782- /// Insert a pre-hashed key-value pair, without first checking
783- /// that there's enough room in the buckets. Returns a reference to the
784- /// newly insert value.
785- ///
786- /// If the key already exists, the hashtable will be returned untouched
787- /// and a reference to the existing element will be returned.
788- fn insert_hashed_nocheck ( & mut self , hash : SafeHash , k : K , v : V ) -> Option < V > {
789- match search_hashed ( & mut self . table , hash, |key| * key == k) {
790- InternalEntry :: Vacant ( entry) => {
791- entry. insert ( hash, k, v) ;
792- return None ;
793- }
794- InternalEntry :: Occupied ( mut entry) => {
795- return Some ( entry. insert ( v) ) ;
796- }
797- InternalEntry :: TableIsEmpty => unreachable ! ( )
798- }
799- }
781+ // // / Insert a pre-hashed key-value pair, without first checking
782+ // // / that there's enough room in the buckets. Returns a reference to the
783+ // // / newly insert value.
784+ // // /
785+ // // / If the key already exists, the hashtable will be returned untouched
786+ // // / and a reference to the existing element will be returned.
787+ // fn insert_hashed_nocheck(&mut self, hash: SafeHash, k: K, v: V) -> Option<V> {
788+ // match search_hashed(&mut self.table, hash, |key| *key == k) {
789+ // InternalEntry::Vacant(entry) => {
790+ // entry.insert(hash, k, v);
791+ // return None;
792+ // }
793+ // InternalEntry::Occupied(mut entry) => {
794+ // return Some(entry.insert(v));
795+ // }
796+ // InternalEntry::TableIsEmpty => unreachable!()
797+ // }
798+ // }
800799
801800 /// An iterator visiting all keys in arbitrary order.
802801 /// Iterator element type is `&'a K`.
@@ -935,13 +934,13 @@ impl<K, V, S> HashMap<K, V, S>
935934 self . reserve ( 1 ) ;
936935
937936 match self . search_mut ( & key) {
938- InternalEntry :: Occupied ( state) => Occupied ( state) ,
939- InternalEntry :: Vacant ( bucket) => Vacant ( VacantEntry {
940- elem : bucket,
941- hash : hash,
937+ ( InternalEntry :: Occupied ( state) , _) => Occupied ( state) ,
938+ ( InternalEntry :: Vacant ( bucket) , hash) => Vacant ( VacantEntry {
942939 key : key,
940+ hash : hash,
941+ elem : bucket,
943942 } ) ,
944- InternalEntry :: TableIsEmpty => unreachable ! ( )
943+ ( InternalEntry :: TableIsEmpty , _ ) => unreachable ! ( )
945944 }
946945 }
947946
@@ -1043,7 +1042,7 @@ impl<K, V, S> HashMap<K, V, S>
10431042 pub fn get < Q : ?Sized > ( & self , k : & Q ) -> Option < & V >
10441043 where K : Borrow < Q > , Q : Hash + Eq
10451044 {
1046- self . search ( k) . into_option ( ) . map ( |bucket| bucket. into_refs ( ) . 1 )
1045+ self . search ( k) . 0 . into_option ( ) . map ( |bucket| bucket. into_refs ( ) . 1 )
10471046 }
10481047
10491048 /// Returns true if the map contains a value for the specified key.
@@ -1066,7 +1065,7 @@ impl<K, V, S> HashMap<K, V, S>
10661065 pub fn contains_key < Q : ?Sized > ( & self , k : & Q ) -> bool
10671066 where K : Borrow < Q > , Q : Hash + Eq
10681067 {
1069- self . search ( k) . into_option ( ) . is_some ( )
1068+ self . search ( k) . 0 . into_option ( ) . is_some ( )
10701069 }
10711070
10721071 /// Returns a mutable reference to the value corresponding to the key.
@@ -1092,7 +1091,7 @@ impl<K, V, S> HashMap<K, V, S>
10921091 pub fn get_mut < Q : ?Sized > ( & mut self , k : & Q ) -> Option < & mut V >
10931092 where K : Borrow < Q > , Q : Hash + Eq
10941093 {
1095- self . search_mut ( k) . into_option ( ) . map ( |bucket| bucket. into_mut_refs ( ) . 1 )
1094+ self . search_mut ( k) . 0 . into_option ( ) . map ( |bucket| bucket. into_mut_refs ( ) . 1 )
10961095 }
10971096
10981097 /// Inserts a key-value pair from the map. If the key already had a value
@@ -1116,14 +1115,14 @@ impl<K, V, S> HashMap<K, V, S>
11161115 self . reserve ( 1 ) ;
11171116
11181117 match self . search_mut ( & key) {
1119- InternalEntry :: Vacant ( entry) => {
1118+ ( InternalEntry :: Occupied ( mut entry) , _) => {
1119+ return Some ( entry. insert ( value) ) ;
1120+ }
1121+ ( InternalEntry :: Vacant ( entry) , hash) => {
11201122 entry. insert ( hash, key, value) ;
11211123 return None ;
11221124 }
1123- InternalEntry :: Occupied ( mut entry) => {
1124- return Some ( entry. insert ( value) ) ;
1125- }
1126- InternalEntry :: TableIsEmpty => unreachable ! ( )
1125+ ( InternalEntry :: TableIsEmpty , _) => unreachable ! ( )
11271126 }
11281127 }
11291128
@@ -1152,7 +1151,7 @@ impl<K, V, S> HashMap<K, V, S>
11521151 return None
11531152 }
11541153
1155- self . search_mut ( k) . into_option ( ) . map ( |bucket| pop_internal ( bucket) . 1 )
1154+ self . search_mut ( k) . 0 . into_option ( ) . map ( |bucket| pop_internal ( bucket) . 1 )
11561155 }
11571156}
11581157
0 commit comments