@@ -94,24 +94,22 @@ impl<K, V, S> Entries for IndexMap<K, V, S> {
94
94
type Entry = Bucket < K , V > ;
95
95
96
96
fn into_entries ( self ) -> Vec < Self :: Entry > {
97
- self . core . entries
97
+ self . core . into_entries ( )
98
98
}
99
99
100
100
fn as_entries ( & self ) -> & [ Self :: Entry ] {
101
- & self . core . entries
101
+ self . core . as_entries ( )
102
102
}
103
103
104
104
fn as_entries_mut ( & mut self ) -> & mut [ Self :: Entry ] {
105
- & mut self . core . entries
105
+ self . core . as_entries_mut ( )
106
106
}
107
107
108
108
fn with_entries < F > ( & mut self , f : F )
109
109
where
110
110
F : FnOnce ( & mut [ Self :: Entry ] ) ,
111
111
{
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) ;
115
113
}
116
114
}
117
115
@@ -273,36 +271,36 @@ where
273
271
/// Return an iterator over the key-value pairs of the map, in their order
274
272
pub fn iter ( & self ) -> Iter < K , V > {
275
273
Iter {
276
- iter : self . core . entries . iter ( ) ,
274
+ iter : self . as_entries ( ) . iter ( ) ,
277
275
}
278
276
}
279
277
280
278
/// Return an iterator over the key-value pairs of the map, in their order
281
279
pub fn iter_mut ( & mut self ) -> IterMut < K , V > {
282
280
IterMut {
283
- iter : self . core . entries . iter_mut ( ) ,
281
+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
284
282
}
285
283
}
286
284
287
285
/// Return an iterator over the keys of the map, in their order
288
286
pub fn keys ( & self ) -> Keys < K , V > {
289
287
Keys {
290
- iter : self . core . entries . iter ( ) ,
288
+ iter : self . as_entries ( ) . iter ( ) ,
291
289
}
292
290
}
293
291
294
292
/// Return an iterator over the values of the map, in their order
295
293
pub fn values ( & self ) -> Values < K , V > {
296
294
Values {
297
- iter : self . core . entries . iter ( ) ,
295
+ iter : self . as_entries ( ) . iter ( ) ,
298
296
}
299
297
}
300
298
301
299
/// Return an iterator over mutable references to the the values of the map,
302
300
/// in their order
303
301
pub fn values_mut ( & mut self ) -> ValuesMut < K , V > {
304
302
ValuesMut {
305
- iter : self . core . entries . iter_mut ( ) ,
303
+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
306
304
}
307
305
}
308
306
@@ -333,7 +331,7 @@ where
333
331
Q : Hash + Equivalent < K > ,
334
332
{
335
333
if let Some ( found) = self . get_index_of ( key) {
336
- let entry = & self . core . entries [ found] ;
334
+ let entry = & self . as_entries ( ) [ found] ;
337
335
Some ( ( found, & entry. key , & entry. value ) )
338
336
} else {
339
337
None
@@ -374,7 +372,7 @@ where
374
372
Q : Hash + Equivalent < K > ,
375
373
{
376
374
if let Some ( ( _, found) ) = self . find ( key) {
377
- let entry = & mut self . core . entries [ found] ;
375
+ let entry = & mut self . as_entries_mut ( ) [ found] ;
378
376
Some ( ( found, & mut entry. key , & mut entry. value ) )
379
377
} else {
380
378
None
@@ -548,8 +546,7 @@ where
548
546
where
549
547
F : FnMut ( & K , & V , & K , & V ) -> Ordering ,
550
548
{
551
- self . core
552
- . entries
549
+ self . as_entries_mut ( )
553
550
. sort_by ( move |a, b| cmp ( & a. key , & a. value , & b. key , & b. value ) ) ;
554
551
self . into_iter ( )
555
552
}
@@ -564,10 +561,8 @@ where
564
561
/// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
565
562
/// Keeps the allocated memory for reuse.
566
563
pub fn drain ( & mut self , range : RangeFull ) -> Drain < K , V > {
567
- self . core . clear_indices ( ) ;
568
-
569
564
Drain {
570
- iter : self . core . entries . drain ( range) ,
565
+ iter : self . core . drain ( range) ,
571
566
}
572
567
}
573
568
}
@@ -586,7 +581,7 @@ impl<K, V, S> IndexMap<K, V, S> {
586
581
///
587
582
/// Computes in **O(1)** time.
588
583
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)
590
585
}
591
586
592
587
/// Get a key-value pair by index
@@ -595,7 +590,7 @@ impl<K, V, S> IndexMap<K, V, S> {
595
590
///
596
591
/// Computes in **O(1)** time.
597
592
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)
599
594
}
600
595
601
596
/// Remove the key-value pair by index
@@ -609,8 +604,7 @@ impl<K, V, S> IndexMap<K, V, S> {
609
604
/// Computes in **O(1)** time (average).
610
605
pub fn swap_remove_index ( & mut self , index : usize ) -> Option < ( K , V ) > {
611
606
let ( probe, found) = match self
612
- . core
613
- . entries
607
+ . as_entries ( )
614
608
. get ( index)
615
609
. map ( |e| self . core . find_existing_entry ( e) )
616
610
{
@@ -631,8 +625,7 @@ impl<K, V, S> IndexMap<K, V, S> {
631
625
/// Computes in **O(n)** time (average).
632
626
pub fn shift_remove_index ( & mut self , index : usize ) -> Option < ( K , V ) > {
633
627
let ( probe, found) = match self
634
- . core
635
- . entries
628
+ . as_entries ( )
636
629
. get ( index)
637
630
. map ( |e| self . core . find_existing_entry ( e) )
638
631
{
@@ -931,7 +924,7 @@ where
931
924
type IntoIter = IntoIter < K , V > ;
932
925
fn into_iter ( self ) -> Self :: IntoIter {
933
926
IntoIter {
934
- iter : self . core . entries . into_iter ( ) ,
927
+ iter : self . into_entries ( ) . into_iter ( ) ,
935
928
}
936
929
}
937
930
}
0 commit comments