@@ -237,7 +237,6 @@ enum Inserted<V> {
237
237
RobinHood {
238
238
probe : usize ,
239
239
old_pos : Pos ,
240
- dist : usize ,
241
240
}
242
241
}
243
242
@@ -438,8 +437,6 @@ pub struct VacantEntry<'a, K: 'a, V: 'a, S: 'a = RandomState> {
438
437
probe : usize ,
439
438
#[ allow( dead_code) ]
440
439
index : usize ,
441
- dist : usize ,
442
- stealing_bucket : bool ,
443
440
}
444
441
445
442
impl < ' a , K , V , S > VacantEntry < ' a , K , V , S > {
@@ -458,11 +455,8 @@ impl<'a, K, V, S> VacantEntry<'a, K, V, S> {
458
455
{
459
456
let index = self . map . entries . len ( ) ;
460
457
self . map . entries . push ( Bucket { hash : self . hash , key : self . key , value : value } ) ;
461
- let old_pos = replace ( & mut self . map . indices [ self . probe ] ,
462
- Pos :: with_hash :: < Sz > ( index, self . hash ) ) ;
463
- if self . stealing_bucket {
464
- self . map . insert_phase_2 :: < Sz > ( self . probe , old_pos, self . dist ) ;
465
- }
458
+ let old_pos = Pos :: with_hash :: < Sz > ( index, self . hash ) ;
459
+ self . map . insert_phase_2 :: < Sz > ( self . probe , old_pos) ;
466
460
& mut { self . map } . entries [ index] . value
467
461
}
468
462
}
@@ -509,9 +503,7 @@ impl<K, V, S> OrderMap<K, V, S>
509
503
hash: hash,
510
504
key: key,
511
505
probe: probe,
512
- stealing_bucket: true ,
513
506
index: i,
514
- dist: their_dist,
515
507
} ) ;
516
508
} else if entry_hash == hash && self . entries[ i] . key == key {
517
509
return Entry :: Occupied ( OccupiedEntry {
@@ -529,9 +521,7 @@ impl<K, V, S> OrderMap<K, V, S>
529
521
hash: hash,
530
522
key: key,
531
523
probe: probe,
532
- stealing_bucket: false ,
533
524
index: 0 ,
534
- dist: 0 ,
535
525
} ) ;
536
526
}
537
527
dist += 1 ;
@@ -574,11 +564,9 @@ impl<K, V, S> OrderMap<K, V, S>
574
564
if their_dist < dist {
575
565
// robin hood: steal the spot if it's better for us
576
566
let index = self . entries. len( ) ;
577
- let old_pos = replace( pos, Pos :: with_hash:: <Sz >( index, hash) ) ;
578
567
insert_kind = Inserted :: RobinHood {
579
568
probe: probe,
580
- old_pos: old_pos,
581
- dist: their_dist,
569
+ old_pos: Pos :: with_hash:: <Sz >( index, hash) ,
582
570
} ;
583
571
break ;
584
572
} else if entry_hash == hash && self . entries[ i] . key == key {
@@ -688,17 +676,17 @@ impl<K, V, S> OrderMap<K, V, S>
688
676
match self . insert_phase_1 :: < u64 > ( key, value) {
689
677
Inserted :: Swapped { prev_value } => Some ( prev_value) ,
690
678
Inserted :: Done => None ,
691
- Inserted :: RobinHood { probe, old_pos, dist } => {
692
- self . insert_phase_2 :: < u64 > ( probe, old_pos, dist ) ;
679
+ Inserted :: RobinHood { probe, old_pos } => {
680
+ self . insert_phase_2 :: < u64 > ( probe, old_pos) ;
693
681
None
694
682
}
695
683
}
696
684
} else {
697
685
match self . insert_phase_1 :: < u32 > ( key, value) {
698
686
Inserted :: Swapped { prev_value } => Some ( prev_value) ,
699
687
Inserted :: Done => None ,
700
- Inserted :: RobinHood { probe, old_pos, dist } => {
701
- self . insert_phase_2 :: < u32 > ( probe, old_pos, dist ) ;
688
+ Inserted :: RobinHood { probe, old_pos } => {
689
+ self . insert_phase_2 :: < u32 > ( probe, old_pos) ;
702
690
None
703
691
}
704
692
}
@@ -902,26 +890,18 @@ impl<K, V, S> OrderMap<K, V, S> {
902
890
self . remove_found ( probe, found)
903
891
}
904
892
905
- /// phase 2 is post-insert where we swap `Pos` in the indices around to
906
- /// adjust after a bucket was stolen.
907
- fn insert_phase_2 < Sz > ( & mut self , mut probe : usize , mut old_pos : Pos , mut dist : usize )
893
+ /// phase 2 is post-insert where we forward-shift `Pos` in the indices.
894
+ fn insert_phase_2 < Sz > ( & mut self , mut probe : usize , mut old_pos : Pos )
908
895
where Sz : Size
909
896
{
910
897
probe_loop ! ( probe < self . indices. len( ) , {
911
898
let pos = & mut self . indices[ probe] ;
912
- if let Some ( ( i, hash_proxy) ) = pos. resolve:: <Sz >( ) {
913
- let entry_hash = hash_proxy. get_short_hash( & self . entries, i) ;
914
- // if existing element probed less than us, swap
915
- let their_dist = probe_distance( self . mask, entry_hash. into_hash( ) , probe) ;
916
- if their_dist < dist {
917
- swap( & mut old_pos, pos) ;
918
- dist = their_dist;
919
- }
920
- } else {
899
+ if pos. is_none( ) {
921
900
* pos = old_pos;
922
901
break ;
902
+ } else {
903
+ old_pos = replace( pos, old_pos) ;
923
904
}
924
- dist += 1 ;
925
905
} ) ;
926
906
}
927
907
0 commit comments