@@ -460,7 +460,7 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for RangeMut<'_, K, V> {
460
460
}
461
461
}
462
462
463
- impl < K : Ord , V > BTreeMap < K , V > {
463
+ impl < K , V > BTreeMap < K , V > {
464
464
/// Makes a new, empty `BTreeMap`.
465
465
///
466
466
/// Does not allocate anything on its own.
@@ -479,7 +479,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
479
479
/// ```
480
480
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
481
481
#[ rustc_const_unstable( feature = "const_btree_new" , issue = "71835" ) ]
482
- pub const fn new ( ) -> BTreeMap < K , V > {
482
+ pub const fn new ( ) -> BTreeMap < K , V >
483
+ where
484
+ K : Ord ,
485
+ {
483
486
BTreeMap { root : None , length : 0 }
484
487
}
485
488
@@ -498,7 +501,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
498
501
/// assert!(a.is_empty());
499
502
/// ```
500
503
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
501
- pub fn clear ( & mut self ) {
504
+ pub fn clear ( & mut self )
505
+ where
506
+ K : Ord ,
507
+ {
502
508
* self = BTreeMap :: new ( ) ;
503
509
}
504
510
@@ -522,7 +528,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
522
528
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
523
529
pub fn get < Q : ?Sized > ( & self , key : & Q ) -> Option < & V >
524
530
where
525
- K : Borrow < Q > ,
531
+ K : Borrow < Q > + Ord ,
526
532
Q : Ord ,
527
533
{
528
534
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
@@ -550,7 +556,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
550
556
#[ stable( feature = "map_get_key_value" , since = "1.40.0" ) ]
551
557
pub fn get_key_value < Q : ?Sized > ( & self , k : & Q ) -> Option < ( & K , & V ) >
552
558
where
553
- K : Borrow < Q > ,
559
+ K : Borrow < Q > + Ord ,
554
560
Q : Ord ,
555
561
{
556
562
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
@@ -578,7 +584,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
578
584
/// assert_eq!(map.first_key_value(), Some((&1, &"b")));
579
585
/// ```
580
586
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
581
- pub fn first_key_value ( & self ) -> Option < ( & K , & V ) > {
587
+ pub fn first_key_value ( & self ) -> Option < ( & K , & V ) >
588
+ where
589
+ K : Ord ,
590
+ {
582
591
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
583
592
root_node. first_leaf_edge ( ) . right_kv ( ) . ok ( ) . map ( Handle :: into_kv)
584
593
}
@@ -604,7 +613,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
604
613
/// assert_eq!(*map.get(&2).unwrap(), "b");
605
614
/// ```
606
615
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
607
- pub fn first_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > > {
616
+ pub fn first_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > >
617
+ where
618
+ K : Ord ,
619
+ {
608
620
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
609
621
let root_node = map. root . as_mut ( ) ?. borrow_mut ( ) ;
610
622
let kv = root_node. first_leaf_edge ( ) . right_kv ( ) . ok ( ) ?;
@@ -631,7 +643,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
631
643
/// assert!(map.is_empty());
632
644
/// ```
633
645
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
634
- pub fn pop_first ( & mut self ) -> Option < ( K , V ) > {
646
+ pub fn pop_first ( & mut self ) -> Option < ( K , V ) >
647
+ where
648
+ K : Ord ,
649
+ {
635
650
self . first_entry ( ) . map ( |entry| entry. remove_entry ( ) )
636
651
}
637
652
@@ -652,7 +667,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
652
667
/// assert_eq!(map.last_key_value(), Some((&2, &"a")));
653
668
/// ```
654
669
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
655
- pub fn last_key_value ( & self ) -> Option < ( & K , & V ) > {
670
+ pub fn last_key_value ( & self ) -> Option < ( & K , & V ) >
671
+ where
672
+ K : Ord ,
673
+ {
656
674
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
657
675
root_node. last_leaf_edge ( ) . left_kv ( ) . ok ( ) . map ( Handle :: into_kv)
658
676
}
@@ -678,7 +696,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
678
696
/// assert_eq!(*map.get(&2).unwrap(), "last");
679
697
/// ```
680
698
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
681
- pub fn last_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > > {
699
+ pub fn last_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > >
700
+ where
701
+ K : Ord ,
702
+ {
682
703
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
683
704
let root_node = map. root . as_mut ( ) ?. borrow_mut ( ) ;
684
705
let kv = root_node. last_leaf_edge ( ) . left_kv ( ) . ok ( ) ?;
@@ -705,7 +726,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
705
726
/// assert!(map.is_empty());
706
727
/// ```
707
728
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
708
- pub fn pop_last ( & mut self ) -> Option < ( K , V ) > {
729
+ pub fn pop_last ( & mut self ) -> Option < ( K , V ) >
730
+ where
731
+ K : Ord ,
732
+ {
709
733
self . last_entry ( ) . map ( |entry| entry. remove_entry ( ) )
710
734
}
711
735
@@ -729,7 +753,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
729
753
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
730
754
pub fn contains_key < Q : ?Sized > ( & self , key : & Q ) -> bool
731
755
where
732
- K : Borrow < Q > ,
756
+ K : Borrow < Q > + Ord ,
733
757
Q : Ord ,
734
758
{
735
759
self . get ( key) . is_some ( )
@@ -758,7 +782,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
758
782
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
759
783
pub fn get_mut < Q : ?Sized > ( & mut self , key : & Q ) -> Option < & mut V >
760
784
where
761
- K : Borrow < Q > ,
785
+ K : Borrow < Q > + Ord ,
762
786
Q : Ord ,
763
787
{
764
788
let root_node = self . root . as_mut ( ) ?. borrow_mut ( ) ;
@@ -795,7 +819,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
795
819
/// assert_eq!(map[&37], "c");
796
820
/// ```
797
821
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
798
- pub fn insert ( & mut self , key : K , value : V ) -> Option < V > {
822
+ pub fn insert ( & mut self , key : K , value : V ) -> Option < V >
823
+ where
824
+ K : Ord ,
825
+ {
799
826
match self . entry ( key) {
800
827
Occupied ( mut entry) => Some ( entry. insert ( value) ) ,
801
828
Vacant ( entry) => {
@@ -826,7 +853,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
826
853
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
827
854
pub fn remove < Q : ?Sized > ( & mut self , key : & Q ) -> Option < V >
828
855
where
829
- K : Borrow < Q > ,
856
+ K : Borrow < Q > + Ord ,
830
857
Q : Ord ,
831
858
{
832
859
self . remove_entry ( key) . map ( |( _, v) | v)
@@ -853,7 +880,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
853
880
#[ stable( feature = "btreemap_remove_entry" , since = "1.45.0" ) ]
854
881
pub fn remove_entry < Q : ?Sized > ( & mut self , key : & Q ) -> Option < ( K , V ) >
855
882
where
856
- K : Borrow < Q > ,
883
+ K : Borrow < Q > + Ord ,
857
884
Q : Ord ,
858
885
{
859
886
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
@@ -885,6 +912,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
885
912
#[ unstable( feature = "btree_retain" , issue = "79025" ) ]
886
913
pub fn retain < F > ( & mut self , mut f : F )
887
914
where
915
+ K : Ord ,
888
916
F : FnMut ( & K , & mut V ) -> bool ,
889
917
{
890
918
self . drain_filter ( |k, v| !f ( k, v) ) ;
@@ -919,7 +947,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
919
947
/// assert_eq!(a[&5], "f");
920
948
/// ```
921
949
#[ stable( feature = "btree_append" , since = "1.11.0" ) ]
922
- pub fn append ( & mut self , other : & mut Self ) {
950
+ pub fn append ( & mut self , other : & mut Self )
951
+ where
952
+ K : Ord ,
953
+ {
923
954
// Do we have to append anything at all?
924
955
if other. is_empty ( ) {
925
956
return ;
@@ -970,7 +1001,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
970
1001
pub fn range < T : ?Sized , R > ( & self , range : R ) -> Range < ' _ , K , V >
971
1002
where
972
1003
T : Ord ,
973
- K : Borrow < T > ,
1004
+ K : Borrow < T > + Ord ,
974
1005
R : RangeBounds < T > ,
975
1006
{
976
1007
if let Some ( root) = & self . root {
@@ -1016,7 +1047,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
1016
1047
pub fn range_mut < T : ?Sized , R > ( & mut self , range : R ) -> RangeMut < ' _ , K , V >
1017
1048
where
1018
1049
T : Ord ,
1019
- K : Borrow < T > ,
1050
+ K : Borrow < T > + Ord ,
1020
1051
R : RangeBounds < T > ,
1021
1052
{
1022
1053
if let Some ( root) = & mut self . root {
@@ -1047,7 +1078,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
1047
1078
/// assert_eq!(count["a"], 3);
1048
1079
/// ```
1049
1080
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1050
- pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V > {
1081
+ pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V >
1082
+ where
1083
+ K : Ord ,
1084
+ {
1051
1085
// FIXME(@porglezomp) Avoid allocating if we don't insert
1052
1086
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
1053
1087
let root_node = Self :: ensure_is_owned ( & mut map. root ) . borrow_mut ( ) ;
@@ -1091,7 +1125,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
1091
1125
#[ stable( feature = "btree_split_off" , since = "1.11.0" ) ]
1092
1126
pub fn split_off < Q : ?Sized + Ord > ( & mut self , key : & Q ) -> Self
1093
1127
where
1094
- K : Borrow < Q > ,
1128
+ K : Borrow < Q > + Ord ,
1095
1129
{
1096
1130
if self . is_empty ( ) {
1097
1131
return Self :: new ( ) ;
@@ -1149,12 +1183,16 @@ impl<K: Ord, V> BTreeMap<K, V> {
1149
1183
#[ unstable( feature = "btree_drain_filter" , issue = "70530" ) ]
1150
1184
pub fn drain_filter < F > ( & mut self , pred : F ) -> DrainFilter < ' _ , K , V , F >
1151
1185
where
1186
+ K : Ord ,
1152
1187
F : FnMut ( & K , & mut V ) -> bool ,
1153
1188
{
1154
1189
DrainFilter { pred, inner : self . drain_filter_inner ( ) }
1155
1190
}
1156
1191
1157
- pub ( super ) fn drain_filter_inner ( & mut self ) -> DrainFilterInner < ' _ , K , V > {
1192
+ pub ( super ) fn drain_filter_inner ( & mut self ) -> DrainFilterInner < ' _ , K , V >
1193
+ where
1194
+ K : Ord ,
1195
+ {
1158
1196
if let Some ( root) = self . root . as_mut ( ) {
1159
1197
let ( root, dormant_root) = DormantMutRef :: new ( root) ;
1160
1198
let front = root. borrow_mut ( ) . first_leaf_edge ( ) ;
@@ -1187,7 +1225,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
1187
1225
/// ```
1188
1226
#[ inline]
1189
1227
#[ unstable( feature = "map_into_keys_values" , issue = "75294" ) ]
1190
- pub fn into_keys ( self ) -> IntoKeys < K , V > {
1228
+ pub fn into_keys ( self ) -> IntoKeys < K , V >
1229
+ where
1230
+ K : Ord ,
1231
+ {
1191
1232
IntoKeys { inner : self . into_iter ( ) }
1192
1233
}
1193
1234
@@ -1210,7 +1251,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
1210
1251
/// ```
1211
1252
#[ inline]
1212
1253
#[ unstable( feature = "map_into_keys_values" , issue = "75294" ) ]
1213
- pub fn into_values ( self ) -> IntoValues < K , V > {
1254
+ pub fn into_values ( self ) -> IntoValues < K , V >
1255
+ where
1256
+ K : Ord ,
1257
+ {
1214
1258
IntoValues { inner : self . into_iter ( ) }
1215
1259
}
1216
1260
}
@@ -1967,9 +2011,9 @@ impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
1967
2011
}
1968
2012
1969
2013
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1970
- impl < K : Ord , Q : ?Sized , V > Index < & Q > for BTreeMap < K , V >
2014
+ impl < K , Q : ?Sized , V > Index < & Q > for BTreeMap < K , V >
1971
2015
where
1972
- K : Borrow < Q > ,
2016
+ K : Borrow < Q > + Ord ,
1973
2017
Q : Ord ,
1974
2018
{
1975
2019
type Output = V ;
0 commit comments