1
1
use core:: hash:: { BuildHasher , Hash } ;
2
2
3
- use super :: { Equivalent , IndexMap } ;
3
+ use super :: { Bucket , Entries , Equivalent , IndexMap } ;
4
4
5
5
pub struct PrivateMarker { }
6
6
@@ -21,13 +21,22 @@ pub trait MutableKeys {
21
21
type Value ;
22
22
23
23
/// Return item index, mutable reference to key and value
24
+ ///
25
+ /// Computes in **O(1)** time (average).
24
26
fn get_full_mut2 < Q : ?Sized > (
25
27
& mut self ,
26
28
key : & Q ,
27
29
) -> Option < ( usize , & mut Self :: Key , & mut Self :: Value ) >
28
30
where
29
31
Q : Hash + Equivalent < Self :: Key > ;
30
32
33
+ /// Return mutable reference to key and value at an index.
34
+ ///
35
+ /// Valid indices are *0 <= index < self.len()*
36
+ ///
37
+ /// Computes in **O(1)** time.
38
+ fn get_index_mut2 ( & mut self , index : usize ) -> Option < ( & mut Self :: Key , & mut Self :: Value ) > ;
39
+
31
40
/// Scan through each key-value pair in the map and keep those where the
32
41
/// closure `keep` returns `true`.
33
42
///
@@ -39,6 +48,7 @@ pub trait MutableKeys {
39
48
where
40
49
F : FnMut ( & mut Self :: Key , & mut Self :: Value ) -> bool ;
41
50
51
+ #[ doc( hidden) ]
42
52
/// This method is not useful in itself – it is there to “seal” the trait
43
53
/// for external implementation, so that we can add methods without
44
54
/// causing breaking changes.
@@ -55,11 +65,21 @@ where
55
65
{
56
66
type Key = K ;
57
67
type Value = V ;
68
+
58
69
fn get_full_mut2 < Q : ?Sized > ( & mut self , key : & Q ) -> Option < ( usize , & mut K , & mut V ) >
59
70
where
60
71
Q : Hash + Equivalent < K > ,
61
72
{
62
- self . get_full_mut2_impl ( key)
73
+ if let Some ( i) = self . get_index_of ( key) {
74
+ let entry = & mut self . as_entries_mut ( ) [ i] ;
75
+ Some ( ( i, & mut entry. key , & mut entry. value ) )
76
+ } else {
77
+ None
78
+ }
79
+ }
80
+
81
+ fn get_index_mut2 ( & mut self , index : usize ) -> Option < ( & mut K , & mut V ) > {
82
+ self . as_entries_mut ( ) . get_mut ( index) . map ( Bucket :: muts)
63
83
}
64
84
65
85
fn retain2 < F > ( & mut self , keep : F )
0 commit comments