@@ -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
@@ -282,36 +280,36 @@ where
282
280
/// Return an iterator over the key-value pairs of the map, in their order
283
281
pub fn iter ( & self ) -> Iter < K , V > {
284
282
Iter {
285
- iter : self . core . entries . iter ( ) ,
283
+ iter : self . as_entries ( ) . iter ( ) ,
286
284
}
287
285
}
288
286
289
287
/// Return an iterator over the key-value pairs of the map, in their order
290
288
pub fn iter_mut ( & mut self ) -> IterMut < K , V > {
291
289
IterMut {
292
- iter : self . core . entries . iter_mut ( ) ,
290
+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
293
291
}
294
292
}
295
293
296
294
/// Return an iterator over the keys of the map, in their order
297
295
pub fn keys ( & self ) -> Keys < K , V > {
298
296
Keys {
299
- iter : self . core . entries . iter ( ) ,
297
+ iter : self . as_entries ( ) . iter ( ) ,
300
298
}
301
299
}
302
300
303
301
/// Return an iterator over the values of the map, in their order
304
302
pub fn values ( & self ) -> Values < K , V > {
305
303
Values {
306
- iter : self . core . entries . iter ( ) ,
304
+ iter : self . as_entries ( ) . iter ( ) ,
307
305
}
308
306
}
309
307
310
308
/// Return an iterator over mutable references to the the values of the map,
311
309
/// in their order
312
310
pub fn values_mut ( & mut self ) -> ValuesMut < K , V > {
313
311
ValuesMut {
314
- iter : self . core . entries . iter_mut ( ) ,
312
+ iter : self . as_entries_mut ( ) . iter_mut ( ) ,
315
313
}
316
314
}
317
315
@@ -342,7 +340,7 @@ where
342
340
Q : Hash + Equivalent < K > ,
343
341
{
344
342
if let Some ( found) = self . get_index_of ( key) {
345
- let entry = & self . core . entries [ found] ;
343
+ let entry = & self . as_entries ( ) [ found] ;
346
344
Some ( ( found, & entry. key , & entry. value ) )
347
345
} else {
348
346
None
@@ -383,7 +381,7 @@ where
383
381
Q : Hash + Equivalent < K > ,
384
382
{
385
383
if let Some ( ( _, found) ) = self . find ( key) {
386
- let entry = & mut self . core . entries [ found] ;
384
+ let entry = & mut self . as_entries_mut ( ) [ found] ;
387
385
Some ( ( found, & mut entry. key , & mut entry. value ) )
388
386
} else {
389
387
None
@@ -557,19 +555,16 @@ where
557
555
where
558
556
F : FnMut ( & K , & V , & K , & V ) -> Ordering ,
559
557
{
560
- self . core
561
- . entries
558
+ self . as_entries_mut ( )
562
559
. sort_by ( move |a, b| cmp ( & a. key , & a. value , & b. key , & b. value ) ) ;
563
560
self . into_iter ( )
564
561
}
565
562
566
563
/// Clears the `IndexMap`, returning all key-value pairs as a drain iterator.
567
564
/// Keeps the allocated memory for reuse.
568
565
pub fn drain ( & mut self , range : RangeFull ) -> Drain < K , V > {
569
- self . core . clear_indices ( ) ;
570
-
571
566
Drain {
572
- iter : self . core . entries . drain ( range) ,
567
+ iter : self . core . drain ( range) ,
573
568
}
574
569
}
575
570
}
@@ -588,7 +583,7 @@ impl<K, V, S> IndexMap<K, V, S> {
588
583
///
589
584
/// Computes in **O(1)** time.
590
585
pub fn get_index ( & self , index : usize ) -> Option < ( & K , & V ) > {
591
- self . core . entries . get ( index) . map ( Bucket :: refs)
586
+ self . as_entries ( ) . get ( index) . map ( Bucket :: refs)
592
587
}
593
588
594
589
/// Get a key-value pair by index
@@ -597,7 +592,7 @@ impl<K, V, S> IndexMap<K, V, S> {
597
592
///
598
593
/// Computes in **O(1)** time.
599
594
pub fn get_index_mut ( & mut self , index : usize ) -> Option < ( & mut K , & mut V ) > {
600
- self . core . entries . get_mut ( index) . map ( Bucket :: muts)
595
+ self . as_entries_mut ( ) . get_mut ( index) . map ( Bucket :: muts)
601
596
}
602
597
603
598
/// Remove the key-value pair by index
@@ -611,8 +606,7 @@ impl<K, V, S> IndexMap<K, V, S> {
611
606
/// Computes in **O(1)** time (average).
612
607
pub fn swap_remove_index ( & mut self , index : usize ) -> Option < ( K , V ) > {
613
608
let ( probe, found) = match self
614
- . core
615
- . entries
609
+ . as_entries ( )
616
610
. get ( index)
617
611
. map ( |e| self . core . find_existing_entry ( e) )
618
612
{
@@ -633,8 +627,7 @@ impl<K, V, S> IndexMap<K, V, S> {
633
627
/// Computes in **O(n)** time (average).
634
628
pub fn shift_remove_index ( & mut self , index : usize ) -> Option < ( K , V ) > {
635
629
let ( probe, found) = match self
636
- . core
637
- . entries
630
+ . as_entries ( )
638
631
. get ( index)
639
632
. map ( |e| self . core . find_existing_entry ( e) )
640
633
{
@@ -933,7 +926,7 @@ where
933
926
type IntoIter = IntoIter < K , V > ;
934
927
fn into_iter ( self ) -> Self :: IntoIter {
935
928
IntoIter {
936
- iter : self . core . entries . into_iter ( ) ,
929
+ iter : self . into_entries ( ) . into_iter ( ) ,
937
930
}
938
931
}
939
932
}
0 commit comments