1
- use core:: borrow:: Borrow ;
2
- use core:: cmp:: Ordering ;
1
+ use core:: cmp:: { Comparable , Ordering } ;
3
2
use core:: error:: Error ;
4
3
use core:: fmt:: { self , Debug } ;
5
4
use core:: hash:: { Hash , Hasher } ;
@@ -332,8 +331,7 @@ impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
332
331
333
332
pub ( super ) fn get_or_insert_with < Q : ?Sized , F > ( & mut self , q : & Q , f : F ) -> & K
334
333
where
335
- K : Borrow < Q > + Ord ,
336
- Q : Ord ,
334
+ K : Comparable < Q > + Ord ,
337
335
F : FnOnce ( & Q ) -> K ,
338
336
{
339
337
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
@@ -343,7 +341,7 @@ impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
343
341
Found ( handle) => handle. into_kv_mut ( ) . 0 ,
344
342
GoDown ( handle) => {
345
343
let key = f ( q) ;
346
- assert ! ( * key. borrow ( ) == * q , "new value is not equal" ) ;
344
+ assert ! ( key. equivalent ( q ) , "new value is not equal" ) ;
347
345
VacantEntry {
348
346
key,
349
347
handle : Some ( handle) ,
@@ -710,8 +708,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
710
708
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
711
709
pub fn get < Q : ?Sized > ( & self , key : & Q ) -> Option < & V >
712
710
where
713
- K : Borrow < Q > + Ord ,
714
- Q : Ord ,
711
+ K : Comparable < Q > + Ord ,
715
712
{
716
713
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
717
714
match root_node. search_tree ( key) {
@@ -776,8 +773,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
776
773
#[ stable( feature = "map_get_key_value" , since = "1.40.0" ) ]
777
774
pub fn get_key_value < Q : ?Sized > ( & self , k : & Q ) -> Option < ( & K , & V ) >
778
775
where
779
- K : Borrow < Q > + Ord ,
780
- Q : Ord ,
776
+ K : Comparable < Q > + Ord ,
781
777
{
782
778
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
783
779
match root_node. search_tree ( k) {
@@ -972,8 +968,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
972
968
#[ cfg_attr( not( test) , rustc_diagnostic_item = "btreemap_contains_key" ) ]
973
969
pub fn contains_key < Q : ?Sized > ( & self , key : & Q ) -> bool
974
970
where
975
- K : Borrow < Q > + Ord ,
976
- Q : Ord ,
971
+ K : Comparable < Q > + Ord ,
977
972
{
978
973
self . get ( key) . is_some ( )
979
974
}
@@ -999,8 +994,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
999
994
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1000
995
pub fn get_mut < Q : ?Sized > ( & mut self , key : & Q ) -> Option < & mut V >
1001
996
where
1002
- K : Borrow < Q > + Ord ,
1003
- Q : Ord ,
997
+ K : Comparable < Q > + Ord ,
1004
998
{
1005
999
let root_node = self . root . as_mut ( ) ?. borrow_mut ( ) ;
1006
1000
match root_node. search_tree ( key) {
@@ -1101,8 +1095,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1101
1095
#[ rustc_confusables( "delete" , "take" ) ]
1102
1096
pub fn remove < Q : ?Sized > ( & mut self , key : & Q ) -> Option < V >
1103
1097
where
1104
- K : Borrow < Q > + Ord ,
1105
- Q : Ord ,
1098
+ K : Comparable < Q > + Ord ,
1106
1099
{
1107
1100
self . remove_entry ( key) . map ( |( _, v) | v)
1108
1101
}
@@ -1126,8 +1119,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1126
1119
#[ stable( feature = "btreemap_remove_entry" , since = "1.45.0" ) ]
1127
1120
pub fn remove_entry < Q : ?Sized > ( & mut self , key : & Q ) -> Option < ( K , V ) >
1128
1121
where
1129
- K : Borrow < Q > + Ord ,
1130
- Q : Ord ,
1122
+ K : Comparable < Q > + Ord ,
1131
1123
{
1132
1124
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
1133
1125
let root_node = map. root . as_mut ( ) ?. borrow_mut ( ) ;
@@ -1260,7 +1252,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1260
1252
pub fn range < T : ?Sized , R > ( & self , range : R ) -> Range < ' _ , K , V >
1261
1253
where
1262
1254
T : Ord ,
1263
- K : Borrow < T > + Ord ,
1255
+ K : Comparable < T > ,
1264
1256
R : RangeBounds < T > ,
1265
1257
{
1266
1258
if let Some ( root) = & self . root {
@@ -1300,7 +1292,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1300
1292
pub fn range_mut < T : ?Sized , R > ( & mut self , range : R ) -> RangeMut < ' _ , K , V >
1301
1293
where
1302
1294
T : Ord ,
1303
- K : Borrow < T > + Ord ,
1295
+ K : Comparable < T > ,
1304
1296
R : RangeBounds < T > ,
1305
1297
{
1306
1298
if let Some ( root) = & mut self . root {
@@ -1388,9 +1380,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
1388
1380
/// assert_eq!(b[&41], "e");
1389
1381
/// ```
1390
1382
#[ stable( feature = "btree_split_off" , since = "1.11.0" ) ]
1391
- pub fn split_off < Q : ?Sized + Ord > ( & mut self , key : & Q ) -> Self
1383
+ pub fn split_off < Q : ?Sized > ( & mut self , key : & Q ) -> Self
1392
1384
where
1393
- K : Borrow < Q > + Ord ,
1385
+ K : Comparable < Q > + Ord ,
1394
1386
A : Clone ,
1395
1387
{
1396
1388
if self . is_empty ( ) {
@@ -2440,8 +2432,7 @@ impl<K: Debug, V: Debug, A: Allocator + Clone> Debug for BTreeMap<K, V, A> {
2440
2432
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2441
2433
impl < K , Q : ?Sized , V , A : Allocator + Clone > Index < & Q > for BTreeMap < K , V , A >
2442
2434
where
2443
- K : Borrow < Q > + Ord ,
2444
- Q : Ord ,
2435
+ K : Comparable < Q > + Ord ,
2445
2436
{
2446
2437
type Output = V ;
2447
2438
@@ -2694,8 +2685,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
2694
2685
#[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2695
2686
pub fn lower_bound < Q : ?Sized > ( & self , bound : Bound < & Q > ) -> Cursor < ' _ , K , V >
2696
2687
where
2697
- K : Borrow < Q > + Ord ,
2698
- Q : Ord ,
2688
+ K : Comparable < Q > + Ord ,
2699
2689
{
2700
2690
let root_node = match self . root . as_ref ( ) {
2701
2691
None => return Cursor { current : None , root : None } ,
@@ -2747,8 +2737,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
2747
2737
#[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2748
2738
pub fn lower_bound_mut < Q : ?Sized > ( & mut self , bound : Bound < & Q > ) -> CursorMut < ' _ , K , V , A >
2749
2739
where
2750
- K : Borrow < Q > + Ord ,
2751
- Q : Ord ,
2740
+ K : Comparable < Q > + Ord ,
2752
2741
{
2753
2742
let ( root, dormant_root) = DormantMutRef :: new ( & mut self . root ) ;
2754
2743
let root_node = match root. as_mut ( ) {
@@ -2817,8 +2806,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
2817
2806
#[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2818
2807
pub fn upper_bound < Q : ?Sized > ( & self , bound : Bound < & Q > ) -> Cursor < ' _ , K , V >
2819
2808
where
2820
- K : Borrow < Q > + Ord ,
2821
- Q : Ord ,
2809
+ K : Comparable < Q > + Ord ,
2822
2810
{
2823
2811
let root_node = match self . root . as_ref ( ) {
2824
2812
None => return Cursor { current : None , root : None } ,
@@ -2870,8 +2858,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
2870
2858
#[ unstable( feature = "btree_cursors" , issue = "107540" ) ]
2871
2859
pub fn upper_bound_mut < Q : ?Sized > ( & mut self , bound : Bound < & Q > ) -> CursorMut < ' _ , K , V , A >
2872
2860
where
2873
- K : Borrow < Q > + Ord ,
2874
- Q : Ord ,
2861
+ K : Comparable < Q > + Ord ,
2875
2862
{
2876
2863
let ( root, dormant_root) = DormantMutRef :: new ( & mut self . root ) ;
2877
2864
let root_node = match root. as_mut ( ) {
0 commit comments