@@ -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) => {
@@ -827,7 +854,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
827
854
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
828
855
pub fn remove < Q : ?Sized > ( & mut self , key : & Q ) -> Option < V >
829
856
where
830
- K : Borrow < Q > ,
857
+ K : Borrow < Q > + Ord ,
831
858
Q : Ord ,
832
859
{
833
860
self . remove_entry ( key) . map ( |( _, v) | v)
@@ -854,7 +881,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
854
881
#[ stable( feature = "btreemap_remove_entry" , since = "1.45.0" ) ]
855
882
pub fn remove_entry < Q : ?Sized > ( & mut self , key : & Q ) -> Option < ( K , V ) >
856
883
where
857
- K : Borrow < Q > ,
884
+ K : Borrow < Q > + Ord ,
858
885
Q : Ord ,
859
886
{
860
887
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
@@ -886,6 +913,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
886
913
#[ unstable( feature = "btree_retain" , issue = "79025" ) ]
887
914
pub fn retain < F > ( & mut self , mut f : F )
888
915
where
916
+ K : Ord ,
889
917
F : FnMut ( & K , & mut V ) -> bool ,
890
918
{
891
919
self . drain_filter ( |k, v| !f ( k, v) ) ;
@@ -920,7 +948,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
920
948
/// assert_eq!(a[&5], "f");
921
949
/// ```
922
950
#[ stable( feature = "btree_append" , since = "1.11.0" ) ]
923
- pub fn append ( & mut self , other : & mut Self ) {
951
+ pub fn append ( & mut self , other : & mut Self )
952
+ where
953
+ K : Ord ,
954
+ {
924
955
// Do we have to append anything at all?
925
956
if other. is_empty ( ) {
926
957
return ;
@@ -971,7 +1002,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
971
1002
pub fn range < T : ?Sized , R > ( & self , range : R ) -> Range < ' _ , K , V >
972
1003
where
973
1004
T : Ord ,
974
- K : Borrow < T > ,
1005
+ K : Borrow < T > + Ord ,
975
1006
R : RangeBounds < T > ,
976
1007
{
977
1008
if let Some ( root) = & self . root {
@@ -1017,7 +1048,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
1017
1048
pub fn range_mut < T : ?Sized , R > ( & mut self , range : R ) -> RangeMut < ' _ , K , V >
1018
1049
where
1019
1050
T : Ord ,
1020
- K : Borrow < T > ,
1051
+ K : Borrow < T > + Ord ,
1021
1052
R : RangeBounds < T > ,
1022
1053
{
1023
1054
if let Some ( root) = & mut self . root {
@@ -1048,7 +1079,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
1048
1079
/// assert_eq!(count["a"], 3);
1049
1080
/// ```
1050
1081
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1051
- pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V > {
1082
+ pub fn entry ( & mut self , key : K ) -> Entry < ' _ , K , V >
1083
+ where
1084
+ K : Ord ,
1085
+ {
1052
1086
// FIXME(@porglezomp) Avoid allocating if we don't insert
1053
1087
let ( map, dormant_map) = DormantMutRef :: new ( self ) ;
1054
1088
let root_node = Self :: ensure_is_owned ( & mut map. root ) . borrow_mut ( ) ;
@@ -1092,7 +1126,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
1092
1126
#[ stable( feature = "btree_split_off" , since = "1.11.0" ) ]
1093
1127
pub fn split_off < Q : ?Sized + Ord > ( & mut self , key : & Q ) -> Self
1094
1128
where
1095
- K : Borrow < Q > ,
1129
+ K : Borrow < Q > + Ord ,
1096
1130
{
1097
1131
if self . is_empty ( ) {
1098
1132
return Self :: new ( ) ;
@@ -1150,12 +1184,16 @@ impl<K: Ord, V> BTreeMap<K, V> {
1150
1184
#[ unstable( feature = "btree_drain_filter" , issue = "70530" ) ]
1151
1185
pub fn drain_filter < F > ( & mut self , pred : F ) -> DrainFilter < ' _ , K , V , F >
1152
1186
where
1187
+ K : Ord ,
1153
1188
F : FnMut ( & K , & mut V ) -> bool ,
1154
1189
{
1155
1190
DrainFilter { pred, inner : self . drain_filter_inner ( ) }
1156
1191
}
1157
1192
1158
- pub ( super ) fn drain_filter_inner ( & mut self ) -> DrainFilterInner < ' _ , K , V > {
1193
+ pub ( super ) fn drain_filter_inner ( & mut self ) -> DrainFilterInner < ' _ , K , V >
1194
+ where
1195
+ K : Ord ,
1196
+ {
1159
1197
if let Some ( root) = self . root . as_mut ( ) {
1160
1198
let ( root, dormant_root) = DormantMutRef :: new ( root) ;
1161
1199
let front = root. borrow_mut ( ) . first_leaf_edge ( ) ;
@@ -1188,7 +1226,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
1188
1226
/// ```
1189
1227
#[ inline]
1190
1228
#[ unstable( feature = "map_into_keys_values" , issue = "75294" ) ]
1191
- pub fn into_keys ( self ) -> IntoKeys < K , V > {
1229
+ pub fn into_keys ( self ) -> IntoKeys < K , V >
1230
+ where
1231
+ K : Ord ,
1232
+ {
1192
1233
IntoKeys { inner : self . into_iter ( ) }
1193
1234
}
1194
1235
@@ -1211,7 +1252,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
1211
1252
/// ```
1212
1253
#[ inline]
1213
1254
#[ unstable( feature = "map_into_keys_values" , issue = "75294" ) ]
1214
- pub fn into_values ( self ) -> IntoValues < K , V > {
1255
+ pub fn into_values ( self ) -> IntoValues < K , V >
1256
+ where
1257
+ K : Ord ,
1258
+ {
1215
1259
IntoValues { inner : self . into_iter ( ) }
1216
1260
}
1217
1261
}
@@ -1968,9 +2012,9 @@ impl<K: Debug, V: Debug> Debug for BTreeMap<K, V> {
1968
2012
}
1969
2013
1970
2014
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1971
- impl < K : Ord , Q : ?Sized , V > Index < & Q > for BTreeMap < K , V >
2015
+ impl < K , Q : ?Sized , V > Index < & Q > for BTreeMap < K , V >
1972
2016
where
1973
- K : Borrow < Q > ,
2017
+ K : Borrow < Q > + Ord ,
1974
2018
Q : Ord ,
1975
2019
{
1976
2020
type Output = V ;
0 commit comments