@@ -834,13 +834,13 @@ where
834
834
K : Hash + Eq ,
835
835
S : BuildHasher ,
836
836
{
837
- fn probe_action < ' a , Sz , A > ( & ' a mut self , key : K , action : A ) -> A :: Output
837
+ fn insert_phase_1 < ' a , Sz , A > ( & ' a mut self , key : K , action : A ) -> A :: Output
838
838
where
839
839
Sz : Size ,
840
840
A : ProbeAction < ' a , Sz , K , V > ,
841
841
{
842
842
let hash = hash_elem_using ( & self . hash_builder , & key) ;
843
- self . core . probe_action :: < Sz , A > ( hash, key, action)
843
+ self . core . insert_phase_1 :: < Sz , A > ( hash, key, action)
844
844
}
845
845
846
846
/// Remove all key-value pairs in the map, while preserving its capacity.
@@ -904,7 +904,7 @@ where
904
904
/// or if you need to get the index of the corresponding key-value pair.
905
905
pub fn insert_full ( & mut self , key : K , value : V ) -> ( usize , Option < V > ) {
906
906
self . reserve_one ( ) ;
907
- dispatch_32_vs_64 ! ( self . probe_action :: <_>( key, InsertValue ( value) ) )
907
+ dispatch_32_vs_64 ! ( self . insert_phase_1 :: <_>( key, InsertValue ( value) ) )
908
908
}
909
909
910
910
/// Get the given key’s corresponding entry in the map for insertion and/or
@@ -913,7 +913,7 @@ where
913
913
/// Computes in **O(1)** time (amortized average).
914
914
pub fn entry ( & mut self , key : K ) -> Entry < K , V > {
915
915
self . reserve_one ( ) ;
916
- dispatch_32_vs_64 ! ( self . probe_action :: <_>( key, MakeEntry ) )
916
+ dispatch_32_vs_64 ! ( self . insert_phase_1 :: <_>( key, MakeEntry ) )
917
917
}
918
918
919
919
/// Return an iterator over the key-value pairs of the map, in their order
@@ -1406,7 +1406,7 @@ impl<K, V> OrderMapCore<K, V> {
1406
1406
Some ( self . swap_remove_found ( probe, found) )
1407
1407
}
1408
1408
1409
- fn probe_action < ' a , Sz , A > ( & ' a mut self , hash : HashValue , key : K , action : A ) -> A :: Output
1409
+ fn insert_phase_1 < ' a , Sz , A > ( & ' a mut self , hash : HashValue , key : K , action : A ) -> A :: Output
1410
1410
where
1411
1411
Sz : Size ,
1412
1412
K : Eq ,
@@ -1696,21 +1696,24 @@ impl<K, V> OrderMapCore<K, V> {
1696
1696
1697
1697
trait ProbeAction < ' a , Sz : Size , K , V > : Sized {
1698
1698
type Output ;
1699
+ // handle an occupied spot in the map
1699
1700
fn hit ( self , entry : OccupiedEntry < ' a , K , V > ) -> Self :: Output ;
1701
+ // handle an empty spot in the map
1700
1702
fn empty ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output ;
1701
- fn steal ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output {
1702
- self . empty ( entry)
1703
- }
1703
+ // robin hood: handle a that you should steal because it's better for you
1704
+ fn steal ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output ;
1704
1705
}
1705
1706
1706
1707
struct InsertValue < V > ( V ) ;
1707
1708
1708
1709
impl < ' a , Sz : Size , K , V > ProbeAction < ' a , Sz , K , V > for InsertValue < V > {
1709
1710
type Output = ( usize , Option < V > ) ;
1711
+
1710
1712
fn hit ( self , entry : OccupiedEntry < ' a , K , V > ) -> Self :: Output {
1711
1713
let old = replace ( & mut entry. map . entries [ entry. index ] . value , self . 0 ) ;
1712
1714
( entry. index , Some ( old) )
1713
1715
}
1716
+
1714
1717
fn empty ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output {
1715
1718
let pos = & mut entry. map . indices [ entry. probe ] ;
1716
1719
let index = entry. map . entries . len ( ) ;
@@ -1722,15 +1725,10 @@ impl<'a, Sz: Size, K, V> ProbeAction<'a, Sz, K, V> for InsertValue<V> {
1722
1725
} ) ;
1723
1726
( index, None )
1724
1727
}
1728
+
1725
1729
fn steal ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output {
1726
1730
let index = entry. map . entries . len ( ) ;
1727
- let old_pos = Pos :: with_hash :: < Sz > ( index, entry. hash ) ;
1728
- entry. map . entries . push ( Bucket {
1729
- hash : entry. hash ,
1730
- key : entry. key ,
1731
- value : self . 0 ,
1732
- } ) ;
1733
- entry. map . insert_phase_2 :: < Sz > ( entry. probe , old_pos) ;
1731
+ entry. insert_impl :: < Sz > ( self . 0 ) ;
1734
1732
( index, None )
1735
1733
}
1736
1734
}
@@ -1745,6 +1743,9 @@ impl<'a, Sz: Size, K: 'a, V: 'a> ProbeAction<'a, Sz, K, V> for MakeEntry {
1745
1743
fn empty ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output {
1746
1744
Entry :: Vacant ( entry)
1747
1745
}
1746
+ fn steal ( self , entry : VacantEntry < ' a , K , V > ) -> Self :: Output {
1747
+ Entry :: Vacant ( entry)
1748
+ }
1748
1749
}
1749
1750
1750
1751
/// Find, in the indices, an entry that already exists at a known position
0 commit comments