11// SPDX-License-Identifier: MIT
2- use std:: mem as memory ;
2+ use std:: mem;
33
44
55#[ derive( Clone , Default ) ]
@@ -48,17 +48,17 @@ impl<K: Ord, V> AvlTree<K, V> {
4848
4949
5050 pub fn get ( & self , key : & K ) -> Option < & V > {
51- Some ( & self . root . as_ref ( ) ?. get ( & key) ?. value )
51+ Some ( & self . root . as_deref ( ) ?. get ( & key) ?. value )
5252 }
5353
5454
5555 pub fn get_mut ( & mut self , key : & K ) -> Option < & mut V > {
56- Some ( & mut self . root . as_mut ( ) ?. get_mut ( & key) ?. value )
56+ Some ( & mut self . root . as_deref_mut ( ) ?. get_mut ( & key) ?. value )
5757 }
5858
5959
6060 pub fn first_key_value ( & self ) -> Option < ( & K , & V ) > {
61- Some ( self . root . as_ref ( ) ?. minimum ( ) )
61+ Some ( self . root . as_deref ( ) ?. minimum ( ) )
6262 }
6363
6464
@@ -130,7 +130,7 @@ impl<K: Ord, V> AvlTree<K, V> {
130130 } else if key > node. key {
131131 current = node. right . as_deref_mut ( ) ;
132132 } else {
133- return Some ( memory :: replace ( & mut node. value , value) ) ;
133+ return Some ( mem :: replace ( & mut node. value , value) ) ;
134134 }
135135 }
136136 let new: Box < Node < K , V > > = Box :: new ( Node :: new ( key, value) ) ;
@@ -169,11 +169,11 @@ impl<K: Ord, V> AvlTree<K, V> {
169169 let removed: V ;
170170 if node. left . is_some ( ) && node. right . is_some ( ) {
171171 let successor: Node < K , V > = node. right . remove_minimum ( ) . unwrap ( ) ;
172- let _ = memory :: replace ( & mut node. key , successor. key ) ;
173- removed = memory :: replace ( & mut node. value , successor. value ) ;
172+ let _ = mem :: replace ( & mut node. key , successor. key ) ;
173+ removed = mem :: replace ( & mut node. value , successor. value ) ;
174174 path. push ( node) ;
175175 } else if let Some ( mut child) = node. left . take ( ) . or ( node. right . take ( ) ) {
176- memory :: swap ( node, & mut child) ; // `node` is `child` now.
176+ mem :: swap ( node, & mut child) ; // `node` is `child` now.
177177 removed = child. value ;
178178 } else if let Some ( parent) = path. last ( ) {
179179 let parent: & mut Node < K , V > = unsafe { & mut * * parent } ;
@@ -218,12 +218,12 @@ impl<K: Ord, V> Node<K, V> {
218218 }
219219
220220
221- fn get ( & self , with : & K ) -> Option < & Self > {
221+ fn get ( & self , key : & K ) -> Option < & Self > {
222222 let mut current: Option < & Node < K , V > > = Some ( self ) ;
223223 while let Some ( node) = current {
224- if * with < node. key {
224+ if * key < node. key {
225225 current = node. left . as_deref ( ) ;
226- } else if * with > node. key {
226+ } else if * key > node. key {
227227 current = node. right . as_deref ( ) ;
228228 } else {
229229 break ;
@@ -233,12 +233,12 @@ impl<K: Ord, V> Node<K, V> {
233233 }
234234
235235
236- fn get_mut ( & mut self , with : & K ) -> Option < & mut Self > {
236+ fn get_mut ( & mut self , key : & K ) -> Option < & mut Self > {
237237 let mut current: Option < & mut Node < K , V > > = Some ( self ) ;
238238 while let Some ( node) = current {
239- if * with < node. key {
239+ if * key < node. key {
240240 current = node. left . as_deref_mut ( ) ;
241- } else if * with > node. key {
241+ } else if * key > node. key {
242242 current = node. right . as_deref_mut ( ) ;
243243 } else {
244244 current = Some ( node) ;
@@ -341,7 +341,7 @@ impl<K: Ord, V> Node<K, V> {
341341 fn rotate_left ( & mut self ) {
342342 let mut t: Box < Node < K , V > > = self . right . take ( ) . unwrap ( ) ;
343343 self . right = t. left . take ( ) ;
344- memory :: swap ( self , & mut t) ; // `self` is `t` now.
344+ mem :: swap ( self , & mut t) ; // `self` is `t` now.
345345 t. update_height ( ) ;
346346 self . left = Some ( t) ;
347347 self . update_height ( ) ;
@@ -358,7 +358,7 @@ impl<K: Ord, V> Node<K, V> {
358358 fn rotate_right ( & mut self ) {
359359 let mut r: Box < Node < K , V > > = self . left . take ( ) . unwrap ( ) ;
360360 self . left = r. right . take ( ) ;
361- memory :: swap ( self , & mut r) ; // `self` is `r` now.
361+ mem :: swap ( self , & mut r) ; // `self` is `r` now.
362362 r. update_height ( ) ;
363363 self . right = Some ( r) ;
364364 self . update_height ( ) ;
@@ -409,7 +409,7 @@ impl<K: Ord, V> OptionNodeExt<K, V> for Option<Box<Node<K, V>>> {
409409 let node: & mut Node < K , V > = unsafe { & mut * path. pop ( ) ? } ;
410410 let min: Box < Node < K , V > > ;
411411 if let Some ( mut right) = node. right . take ( ) {
412- memory :: swap ( node, & mut right) ; // `node` is `right` now.
412+ mem :: swap ( node, & mut right) ; // `node` is `right` now.
413413 min = right;
414414 } else if let Some ( parent) = path. last ( ) {
415415 min = unsafe { & mut * * parent } . left . take ( ) . unwrap ( ) ;
@@ -431,7 +431,7 @@ impl<K: Ord, V> OptionNodeExt<K, V> for Option<Box<Node<K, V>>> {
431431 let node: & mut Node < K , V > = unsafe { & mut * path. pop ( ) ? } ;
432432 let max: Box < Node < K , V > > ;
433433 if let Some ( mut left) = node. left . take ( ) {
434- memory :: swap ( node, & mut left) ; // `node` is `left` now.
434+ mem :: swap ( node, & mut left) ; // `node` is `left` now.
435435 max = left;
436436 } else if let Some ( parent) = path. last ( ) {
437437 max = unsafe { & mut * * parent } . right . take ( ) . unwrap ( ) ;
0 commit comments