1- use core:: borrow:: Borrow ;
2- use core:: cmp:: Ordering ;
1+ use core:: cmp:: { Comparable , Ordering } ;
32use core:: ops:: { Bound , RangeBounds } ;
43
54use SearchBound :: * ;
@@ -46,16 +45,15 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
4645 ///
4746 /// The result is meaningful only if the tree is ordered by key, like the tree
4847 /// in a `BTreeMap` is.
49- pub ( super ) fn search_tree < Q : ? Sized > (
48+ pub ( super ) fn search_tree < Q : Clone > (
5049 mut self ,
51- key : & Q ,
50+ key : Q ,
5251 ) -> SearchResult < BorrowType , K , V , marker:: LeafOrInternal , marker:: Leaf >
5352 where
54- Q : Ord ,
55- K : Borrow < Q > ,
53+ K : Comparable < Q > ,
5654 {
5755 loop {
58- self = match self . search_node ( key) {
56+ self = match self . search_node ( key. clone ( ) ) {
5957 Found ( handle) => return Found ( handle) ,
6058 GoDown ( handle) => match handle. force ( ) {
6159 Leaf ( leaf) => return GoDown ( leaf) ,
@@ -95,7 +93,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
9593 >
9694 where
9795 Q : Ord ,
98- K : Borrow < Q > ,
96+ K : Comparable < & Q > ,
9997 R : RangeBounds < Q > ,
10098 {
10199 // Determine if map or set is being searched
@@ -156,27 +154,25 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
156154 /// the matching child node, if `self` is an internal node.
157155 ///
158156 /// The result is meaningful only if the tree is ordered by key.
159- pub ( super ) fn find_lower_bound_edge < ' r , Q > (
157+ pub ( super ) fn find_lower_bound_edge < Q : Clone > (
160158 self ,
161- bound : SearchBound < & ' r Q > ,
162- ) -> ( Handle < Self , marker:: Edge > , SearchBound < & ' r Q > )
159+ bound : SearchBound < Q > ,
160+ ) -> ( Handle < Self , marker:: Edge > , SearchBound < Q > )
163161 where
164- Q : ?Sized + Ord ,
165- K : Borrow < Q > ,
162+ K : Comparable < Q > ,
166163 {
167164 let ( edge_idx, bound) = self . find_lower_bound_index ( bound) ;
168165 let edge = unsafe { Handle :: new_edge ( self , edge_idx) } ;
169166 ( edge, bound)
170167 }
171168
172169 /// Clone of `find_lower_bound_edge` for the upper bound.
173- pub ( super ) fn find_upper_bound_edge < ' r , Q > (
170+ pub ( super ) fn find_upper_bound_edge < Q : Clone > (
174171 self ,
175- bound : SearchBound < & ' r Q > ,
176- ) -> ( Handle < Self , marker:: Edge > , SearchBound < & ' r Q > )
172+ bound : SearchBound < Q > ,
173+ ) -> ( Handle < Self , marker:: Edge > , SearchBound < Q > )
177174 where
178- Q : ?Sized + Ord ,
179- K : Borrow < Q > ,
175+ K : Comparable < Q > ,
180176 {
181177 let ( edge_idx, bound) = unsafe { self . find_upper_bound_index ( bound, 0 ) } ;
182178 let edge = unsafe { Handle :: new_edge ( self , edge_idx) } ;
@@ -192,13 +188,9 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
192188 ///
193189 /// The result is meaningful only if the tree is ordered by key, like the tree
194190 /// in a `BTreeMap` is.
195- pub ( super ) fn search_node < Q : ?Sized > (
196- self ,
197- key : & Q ,
198- ) -> SearchResult < BorrowType , K , V , Type , Type >
191+ pub ( super ) fn search_node < Q : Clone > ( self , key : Q ) -> SearchResult < BorrowType , K , V , Type , Type >
199192 where
200- Q : Ord ,
201- K : Borrow < Q > ,
193+ K : Comparable < Q > ,
202194 {
203195 match unsafe { self . find_key_index ( key, 0 ) } {
204196 IndexResult :: KV ( idx) => Found ( unsafe { Handle :: new_kv ( self , idx) } ) ,
@@ -214,19 +206,18 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
214206 ///
215207 /// # Safety
216208 /// `start_index` must be a valid edge index for the node.
217- unsafe fn find_key_index < Q : ? Sized > ( & self , key : & Q , start_index : usize ) -> IndexResult
209+ unsafe fn find_key_index < Q : Clone > ( & self , key : Q , start_index : usize ) -> IndexResult
218210 where
219- Q : Ord ,
220- K : Borrow < Q > ,
211+ K : Comparable < Q > ,
221212 {
222213 let node = self . reborrow ( ) ;
223214 let keys = node. keys ( ) ;
224215 debug_assert ! ( start_index <= keys. len( ) ) ;
225216 for ( offset, k) in unsafe { keys. get_unchecked ( start_index..) } . iter ( ) . enumerate ( ) {
226- match key . cmp ( k . borrow ( ) ) {
227- Ordering :: Greater => { }
217+ match k . compare ( key . clone ( ) ) {
218+ Ordering :: Less => { }
228219 Ordering :: Equal => return IndexResult :: KV ( start_index + offset) ,
229- Ordering :: Less => return IndexResult :: Edge ( start_index + offset) ,
220+ Ordering :: Greater => return IndexResult :: Edge ( start_index + offset) ,
230221 }
231222 }
232223 IndexResult :: Edge ( keys. len ( ) )
@@ -237,22 +228,18 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
237228 /// the matching child node, if `self` is an internal node.
238229 ///
239230 /// The result is meaningful only if the tree is ordered by key.
240- fn find_lower_bound_index < ' r , Q > (
241- & self ,
242- bound : SearchBound < & ' r Q > ,
243- ) -> ( usize , SearchBound < & ' r Q > )
231+ fn find_lower_bound_index < Q : Clone > ( & self , bound : SearchBound < Q > ) -> ( usize , SearchBound < Q > )
244232 where
245- Q : ?Sized + Ord ,
246- K : Borrow < Q > ,
233+ K : Comparable < Q > ,
247234 {
248235 match bound {
249- Included ( key) => match unsafe { self . find_key_index ( key, 0 ) } {
236+ Included ( key) => match unsafe { self . find_key_index ( key. clone ( ) , 0 ) } {
250237 IndexResult :: KV ( idx) => ( idx, AllExcluded ) ,
251- IndexResult :: Edge ( idx) => ( idx, bound ) ,
238+ IndexResult :: Edge ( idx) => ( idx, Included ( key ) ) ,
252239 } ,
253- Excluded ( key) => match unsafe { self . find_key_index ( key, 0 ) } {
240+ Excluded ( key) => match unsafe { self . find_key_index ( key. clone ( ) , 0 ) } {
254241 IndexResult :: KV ( idx) => ( idx + 1 , AllIncluded ) ,
255- IndexResult :: Edge ( idx) => ( idx, bound ) ,
242+ IndexResult :: Edge ( idx) => ( idx, Excluded ( key ) ) ,
256243 } ,
257244 AllIncluded => ( 0 , AllIncluded ) ,
258245 AllExcluded => ( self . len ( ) , AllExcluded ) ,
@@ -264,23 +251,22 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
264251 ///
265252 /// # Safety
266253 /// `start_index` must be a valid edge index for the node.
267- unsafe fn find_upper_bound_index < ' r , Q > (
254+ unsafe fn find_upper_bound_index < Q : Clone > (
268255 & self ,
269- bound : SearchBound < & ' r Q > ,
256+ bound : SearchBound < Q > ,
270257 start_index : usize ,
271- ) -> ( usize , SearchBound < & ' r Q > )
258+ ) -> ( usize , SearchBound < Q > )
272259 where
273- Q : ?Sized + Ord ,
274- K : Borrow < Q > ,
260+ K : Comparable < Q > ,
275261 {
276262 match bound {
277- Included ( key) => match unsafe { self . find_key_index ( key, start_index) } {
263+ Included ( key) => match unsafe { self . find_key_index ( key. clone ( ) , start_index) } {
278264 IndexResult :: KV ( idx) => ( idx + 1 , AllExcluded ) ,
279- IndexResult :: Edge ( idx) => ( idx, bound ) ,
265+ IndexResult :: Edge ( idx) => ( idx, Included ( key ) ) ,
280266 } ,
281- Excluded ( key) => match unsafe { self . find_key_index ( key, start_index) } {
267+ Excluded ( key) => match unsafe { self . find_key_index ( key. clone ( ) , start_index) } {
282268 IndexResult :: KV ( idx) => ( idx, AllIncluded ) ,
283- IndexResult :: Edge ( idx) => ( idx, bound ) ,
269+ IndexResult :: Edge ( idx) => ( idx, Excluded ( key ) ) ,
284270 } ,
285271 AllIncluded => ( self . len ( ) , AllIncluded ) ,
286272 AllExcluded => ( start_index, AllExcluded ) ,
0 commit comments