@@ -94,24 +94,22 @@ impl<K, V, S> Entries for IndexMap<K, V, S> {
9494 type Entry = Bucket < K , V > ;
9595
9696 fn into_entries ( self ) -> Vec < Self :: Entry > {
97- self . core . entries
97+ self . core . into_entries ( )
9898 }
9999
100100 fn as_entries ( & self ) -> & [ Self :: Entry ] {
101- & self . core . entries
101+ self . core . as_entries ( )
102102 }
103103
104104 fn as_entries_mut ( & mut self ) -> & mut [ Self :: Entry ] {
105- & mut self . core . entries
105+ self . core . as_entries_mut ( )
106106 }
107107
108108 fn with_entries < F > ( & mut self , f : F )
109109 where
110110 F : FnOnce ( & mut [ Self :: Entry ] ) ,
111111 {
112- let side_index = self . core . save_hash_index ( ) ;
113- f ( & mut self . core . entries ) ;
114- self . core . restore_hash_index ( side_index) ;
112+ self . core . with_entries ( f) ;
115113 }
116114}
117115
@@ -273,36 +271,36 @@ where
273271 /// Return an iterator over the key-value pairs of the map, in their order
274272 pub fn iter ( & self ) -> Iter < K , V > {
275273 Iter {
276- iter : self . core . entries . iter ( ) ,
274+ iter : self . as_entries ( ) . iter ( ) ,
277275 }
278276 }
279277
280278 /// Return an iterator over the key-value pairs of the map, in their order
281279 pub fn iter_mut ( & mut self ) -> IterMut < K , V > {
282280 IterMut {
283- iter : self . core . entries . iter_mut ( ) ,
281+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
284282 }
285283 }
286284
287285 /// Return an iterator over the keys of the map, in their order
288286 pub fn keys ( & self ) -> Keys < K , V > {
289287 Keys {
290- iter : self . core . entries . iter ( ) ,
288+ iter : self . as_entries ( ) . iter ( ) ,
291289 }
292290 }
293291
294292 /// Return an iterator over the values of the map, in their order
295293 pub fn values ( & self ) -> Values < K , V > {
296294 Values {
297- iter : self . core . entries . iter ( ) ,
295+ iter : self . as_entries ( ) . iter ( ) ,
298296 }
299297 }
300298
301299 /// Return an iterator over mutable references to the the values of the map,
302300 /// in their order
303301 pub fn values_mut ( & mut self ) -> ValuesMut < K , V > {
304302 ValuesMut {
305- iter : self . core . entries . iter_mut ( ) ,
303+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
306304 }
307305 }
308306
@@ -333,7 +331,7 @@ where
333331 Q : Hash + Equivalent < K > ,
334332 {
335333 if let Some ( found) = self . get_index_of ( key) {
336- let entry = & self . core . entries [ found] ;
334+ let entry = & self . as_entries ( ) [ found] ;
337335 Some ( ( found, & entry. key , & entry. value ) )
338336 } else {
339337 None
@@ -374,7 +372,7 @@ where
374372 Q : Hash + Equivalent < K > ,
375373 {
376374 if let Some ( ( _, found) ) = self . find ( key) {
377- let entry = & mut self . core . entries [ found] ;
375+ let entry = & mut self . as_entries_mut ( ) [ found] ;
378376 Some ( ( found, & mut entry. key , & mut entry. value ) )
379377 } else {
380378 None
@@ -548,8 +546,7 @@ where
548546 where
549547 F : FnMut ( & K , & V , & K , & V ) -> Ordering ,
550548 {
551- self . core
552- . entries
549+ self . as_entries_mut ( )
553550 . sort_by ( move |a, b| cmp ( & a. key , & a. value , & b. key , & b. value ) ) ;
554551 self . into_iter ( )
555552 }
@@ -564,10 +561,8 @@ where
564561 /// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
565562 /// Keeps the allocated memory for reuse.
566563 pub fn drain ( & mut self , range : RangeFull ) -> Drain < K , V > {
567- self . core . clear_indices ( ) ;
568-
569564 Drain {
570- iter : self . core . entries . drain ( range) ,
565+ iter : self . core . drain ( range) ,
571566 }
572567 }
573568}
@@ -586,7 +581,7 @@ impl<K, V, S> IndexMap<K, V, S> {
586581 ///
587582 /// Computes in **O(1)** time.
588583 pub fn get_index ( & self , index : usize ) -> Option < ( & K , & V ) > {
589- self . core . entries . get ( index) . map ( Bucket :: refs)
584+ self . as_entries ( ) . get ( index) . map ( Bucket :: refs)
590585 }
591586
592587 /// Get a key-value pair by index
@@ -595,7 +590,7 @@ impl<K, V, S> IndexMap<K, V, S> {
595590 ///
596591 /// Computes in **O(1)** time.
597592 pub fn get_index_mut ( & mut self , index : usize ) -> Option < ( & mut K , & mut V ) > {
598- self . core . entries . get_mut ( index) . map ( Bucket :: muts)
593+ self . as_entries_mut ( ) . get_mut ( index) . map ( Bucket :: muts)
599594 }
600595
601596 /// Remove the key-value pair by index
@@ -609,8 +604,7 @@ impl<K, V, S> IndexMap<K, V, S> {
609604 /// Computes in **O(1)** time (average).
610605 pub fn swap_remove_index ( & mut self , index : usize ) -> Option < ( K , V ) > {
611606 let ( probe, found) = match self
612- . core
613- . entries
607+ . as_entries ( )
614608 . get ( index)
615609 . map ( |e| self . core . find_existing_entry ( e) )
616610 {
@@ -631,8 +625,7 @@ impl<K, V, S> IndexMap<K, V, S> {
631625 /// Computes in **O(n)** time (average).
632626 pub fn shift_remove_index ( & mut self , index : usize ) -> Option < ( K , V ) > {
633627 let ( probe, found) = match self
634- . core
635- . entries
628+ . as_entries ( )
636629 . get ( index)
637630 . map ( |e| self . core . find_existing_entry ( e) )
638631 {
@@ -931,7 +924,7 @@ where
931924 type IntoIter = IntoIter < K , V > ;
932925 fn into_iter ( self ) -> Self :: IntoIter {
933926 IntoIter {
934- iter : self . core . entries . into_iter ( ) ,
927+ iter : self . into_entries ( ) . into_iter ( ) ,
935928 }
936929 }
937930}
0 commit comments