1
- use core:: borrow:: Borrow ;
2
1
use core:: cmp:: Ordering ;
3
2
use core:: ops:: { Bound , RangeBounds } ;
4
3
5
4
use SearchBound :: * ;
6
5
use SearchResult :: * ;
7
6
7
+ use super :: cmp:: Comparable ;
8
8
use super :: node:: ForceResult :: * ;
9
9
use super :: node:: { Handle , NodeRef , marker} ;
10
10
@@ -51,8 +51,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
51
51
key : & Q ,
52
52
) -> SearchResult < BorrowType , K , V , marker:: LeafOrInternal , marker:: Leaf >
53
53
where
54
- Q : Ord ,
55
- K : Borrow < Q > ,
54
+ K : Comparable < Q > ,
56
55
{
57
56
loop {
58
57
self = match self . search_node ( key) {
@@ -95,7 +94,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
95
94
>
96
95
where
97
96
Q : Ord ,
98
- K : Borrow < Q > ,
97
+ K : Comparable < Q > ,
99
98
R : RangeBounds < Q > ,
100
99
{
101
100
// Determine if map or set is being searched
@@ -161,8 +160,8 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
161
160
bound : SearchBound < & ' r Q > ,
162
161
) -> ( Handle < Self , marker:: Edge > , SearchBound < & ' r Q > )
163
162
where
164
- Q : ?Sized + Ord ,
165
- K : Borrow < Q > ,
163
+ Q : ?Sized ,
164
+ K : Comparable < Q > ,
166
165
{
167
166
let ( edge_idx, bound) = self . find_lower_bound_index ( bound) ;
168
167
let edge = unsafe { Handle :: new_edge ( self , edge_idx) } ;
@@ -175,8 +174,8 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
175
174
bound : SearchBound < & ' r Q > ,
176
175
) -> ( Handle < Self , marker:: Edge > , SearchBound < & ' r Q > )
177
176
where
178
- Q : ?Sized + Ord ,
179
- K : Borrow < Q > ,
177
+ Q : ?Sized ,
178
+ K : Comparable < Q > ,
180
179
{
181
180
let ( edge_idx, bound) = unsafe { self . find_upper_bound_index ( bound, 0 ) } ;
182
181
let edge = unsafe { Handle :: new_edge ( self , edge_idx) } ;
@@ -197,8 +196,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
197
196
key : & Q ,
198
197
) -> SearchResult < BorrowType , K , V , Type , Type >
199
198
where
200
- Q : Ord ,
201
- K : Borrow < Q > ,
199
+ K : Comparable < Q > ,
202
200
{
203
201
match unsafe { self . find_key_index ( key, 0 ) } {
204
202
IndexResult :: KV ( idx) => Found ( unsafe { Handle :: new_kv ( self , idx) } ) ,
@@ -216,17 +214,16 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
216
214
/// `start_index` must be a valid edge index for the node.
217
215
unsafe fn find_key_index < Q : ?Sized > ( & self , key : & Q , start_index : usize ) -> IndexResult
218
216
where
219
- Q : Ord ,
220
- K : Borrow < Q > ,
217
+ K : Comparable < Q > ,
221
218
{
222
219
let node = self . reborrow ( ) ;
223
220
let keys = node. keys ( ) ;
224
221
debug_assert ! ( start_index <= keys. len( ) ) ;
225
222
for ( offset, k) in unsafe { keys. get_unchecked ( start_index..) } . iter ( ) . enumerate ( ) {
226
- match key . cmp ( k . borrow ( ) ) {
227
- Ordering :: Greater => { }
223
+ match k . compare ( key ) {
224
+ Ordering :: Less => { }
228
225
Ordering :: Equal => return IndexResult :: KV ( start_index + offset) ,
229
- Ordering :: Less => return IndexResult :: Edge ( start_index + offset) ,
226
+ Ordering :: Greater => return IndexResult :: Edge ( start_index + offset) ,
230
227
}
231
228
}
232
229
IndexResult :: Edge ( keys. len ( ) )
@@ -242,8 +239,8 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
242
239
bound : SearchBound < & ' r Q > ,
243
240
) -> ( usize , SearchBound < & ' r Q > )
244
241
where
245
- Q : ?Sized + Ord ,
246
- K : Borrow < Q > ,
242
+ Q : ?Sized ,
243
+ K : Comparable < Q > ,
247
244
{
248
245
match bound {
249
246
Included ( key) => match unsafe { self . find_key_index ( key, 0 ) } {
@@ -270,8 +267,8 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
270
267
start_index : usize ,
271
268
) -> ( usize , SearchBound < & ' r Q > )
272
269
where
273
- Q : ?Sized + Ord ,
274
- K : Borrow < Q > ,
270
+ Q : ?Sized ,
271
+ K : Comparable < Q > ,
275
272
{
276
273
match bound {
277
274
Included ( key) => match unsafe { self . find_key_index ( key, start_index) } {
0 commit comments