@@ -542,7 +542,6 @@ where
542542 /// Computes in **O(n)** time (average).
543543 pub fn insert_sorted_by < F > ( & mut self , key : K , value : V , mut cmp : F ) -> ( usize , Option < V > )
544544 where
545- K : Ord ,
546545 F : FnMut ( & K , & V , & K , & V ) -> Ordering ,
547546 {
548547 let ( Ok ( i) | Err ( i) ) = self . binary_search_by ( |k, v| cmp ( k, v, & key, & value) ) ;
@@ -864,7 +863,7 @@ where
864863 self . get_index_of ( key) . is_some ( )
865864 }
866865
867- /// Return a reference to the value stored for `key`, if it is present,
866+ /// Return a reference to the stored value for `key`, if it is present,
868867 /// else `None`.
869868 ///
870869 /// Computes in **O(1)** time (average).
@@ -880,7 +879,7 @@ where
880879 }
881880 }
882881
883- /// Return references to the key-value pair stored for `key`,
882+ /// Return references to the stored key-value pair for the lookup `key`,
884883 /// if it is present, else `None`.
885884 ///
886885 /// Computes in **O(1)** time (average).
@@ -896,7 +895,10 @@ where
896895 }
897896 }
898897
899- /// Return item index, key and value
898+ /// Return the index with references to the stored key-value pair for the
899+ /// lookup `key`, if it is present, else `None`.
900+ ///
901+ /// Computes in **O(1)** time (average).
900902 pub fn get_full < Q > ( & self , key : & Q ) -> Option < ( usize , & K , & V ) >
901903 where
902904 Q : ?Sized + Hash + Equivalent < K > ,
@@ -909,7 +911,7 @@ where
909911 }
910912 }
911913
912- /// Return item index, if it exists in the map
914+ /// Return the item index for `key` , if it is present, else `None`.
913915 ///
914916 /// Computes in **O(1)** time (average).
915917 pub fn get_index_of < Q > ( & self , key : & Q ) -> Option < usize >
@@ -926,6 +928,10 @@ where
926928 }
927929 }
928930
931+ /// Return a mutable reference to the stored value for `key`,
932+ /// if it is present, else `None`.
933+ ///
934+ /// Computes in **O(1)** time (average).
929935 pub fn get_mut < Q > ( & mut self , key : & Q ) -> Option < & mut V >
930936 where
931937 Q : ?Sized + Hash + Equivalent < K > ,
@@ -938,6 +944,26 @@ where
938944 }
939945 }
940946
947+ /// Return a reference and mutable references to the stored key-value pair
948+ /// for the lookup `key`, if it is present, else `None`.
949+ ///
950+ /// Computes in **O(1)** time (average).
951+ pub fn get_key_value_mut < Q > ( & mut self , key : & Q ) -> Option < ( & K , & mut V ) >
952+ where
953+ Q : ?Sized + Hash + Equivalent < K > ,
954+ {
955+ if let Some ( i) = self . get_index_of ( key) {
956+ let entry = & mut self . as_entries_mut ( ) [ i] ;
957+ Some ( ( & entry. key , & mut entry. value ) )
958+ } else {
959+ None
960+ }
961+ }
962+
963+ /// Return the index with a reference and mutable reference to the stored
964+ /// key-value pair for the lookup `key`, if it is present, else `None`.
965+ ///
966+ /// Computes in **O(1)** time (average).
941967 pub fn get_full_mut < Q > ( & mut self , key : & Q ) -> Option < ( usize , & K , & mut V ) >
942968 where
943969 Q : ?Sized + Hash + Equivalent < K > ,
0 commit comments