@@ -600,8 +600,7 @@ impl<K, V> BTreeMap<K, V> {
600
600
}
601
601
}
602
602
603
- /// Returns the first key-value pair in the map.
604
- /// The key in this pair is the minimum key in the map.
603
+ /// Returns the key-value pair with the minimum key in the map.
605
604
///
606
605
/// # Examples
607
606
///
@@ -612,22 +611,21 @@ impl<K, V> BTreeMap<K, V> {
612
611
/// use std::collections::BTreeMap;
613
612
///
614
613
/// let mut map = BTreeMap::new();
615
- /// assert_eq!(map.first_key_value (), None);
614
+ /// assert_eq!(map.min_key_value (), None);
616
615
/// map.insert(1, "b");
617
616
/// map.insert(2, "a");
618
- /// assert_eq!(map.first_key_value (), Some((&1, &"b")));
617
+ /// assert_eq!(map.min_key_value (), Some((&1, &"b")));
619
618
/// ```
620
619
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
621
- pub fn first_key_value ( & self ) -> Option < ( & K , & V ) >
620
+ pub fn min_key_value ( & self ) -> Option < ( & K , & V ) >
622
621
where
623
622
K : Ord ,
624
623
{
625
624
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
626
625
root_node. first_leaf_edge ( ) . right_kv ( ) . ok ( ) . map ( Handle :: into_kv)
627
626
}
628
627
629
- /// Returns the first entry in the map for in-place manipulation.
630
- /// The key of this entry is the minimum key in the map.
628
+ /// Returns the entry with the minimum key in the map for in-place manipulation.
631
629
///
632
630
/// # Examples
633
631
///
@@ -638,16 +636,16 @@ impl<K, V> BTreeMap<K, V> {
638
636
/// let mut map = BTreeMap::new();
639
637
/// map.insert(1, "a");
640
638
/// map.insert(2, "b");
641
- /// if let Some(mut entry) = map.first_entry () {
639
+ /// if let Some(mut entry) = map.min_entry () {
642
640
/// if *entry.key() > 0 {
643
- /// entry.insert("first ");
641
+ /// entry.insert("min ");
644
642
/// }
645
643
/// }
646
- /// assert_eq!(*map.get(&1).unwrap(), "first ");
644
+ /// assert_eq!(*map.get(&1).unwrap(), "min ");
647
645
/// assert_eq!(*map.get(&2).unwrap(), "b");
648
646
/// ```
649
647
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
650
- pub fn first_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > >
648
+ pub fn min_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > >
651
649
where
652
650
K : Ord ,
653
651
{
@@ -657,8 +655,7 @@ impl<K, V> BTreeMap<K, V> {
657
655
Some ( OccupiedEntry { handle : kv. forget_node_type ( ) , dormant_map, _marker : PhantomData } )
658
656
}
659
657
660
- /// Removes and returns the first element in the map.
661
- /// The key of this element is the minimum key that was in the map.
658
+ /// Removes and returns the key-value pair with the minimum key in the map.
662
659
///
663
660
/// # Examples
664
661
///
@@ -671,21 +668,21 @@ impl<K, V> BTreeMap<K, V> {
671
668
/// let mut map = BTreeMap::new();
672
669
/// map.insert(1, "a");
673
670
/// map.insert(2, "b");
674
- /// while let Some((key, _val)) = map.pop_first () {
671
+ /// while let Some((key, _val)) = map.pop_min () {
675
672
/// assert!(map.iter().all(|(k, _v)| *k > key));
676
673
/// }
677
674
/// assert!(map.is_empty());
678
675
/// ```
679
676
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
680
- pub fn pop_first ( & mut self ) -> Option < ( K , V ) >
677
+ pub fn pop_min ( & mut self ) -> Option < ( K , V ) >
681
678
where
682
679
K : Ord ,
683
680
{
684
- self . first_entry ( ) . map ( |entry| entry. remove_entry ( ) )
681
+ self . min_entry ( ) . map ( |entry| entry. remove_entry ( ) )
685
682
}
686
683
687
- /// Returns the last key-value pair in the map.
688
- /// The key in this pair is the maximum key in the map.
684
+ /// Returns the key-value pair with the maximum key in the
685
+ /// map. The key in this pair is the maximum key in the map.
689
686
///
690
687
/// # Examples
691
688
///
@@ -698,19 +695,18 @@ impl<K, V> BTreeMap<K, V> {
698
695
/// let mut map = BTreeMap::new();
699
696
/// map.insert(1, "b");
700
697
/// map.insert(2, "a");
701
- /// assert_eq!(map.last_key_value (), Some((&2, &"a")));
698
+ /// assert_eq!(map.max_key_value (), Some((&2, &"a")));
702
699
/// ```
703
700
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
704
- pub fn last_key_value ( & self ) -> Option < ( & K , & V ) >
701
+ pub fn max_key_value ( & self ) -> Option < ( & K , & V ) >
705
702
where
706
703
K : Ord ,
707
704
{
708
705
let root_node = self . root . as_ref ( ) ?. reborrow ( ) ;
709
706
root_node. last_leaf_edge ( ) . left_kv ( ) . ok ( ) . map ( Handle :: into_kv)
710
707
}
711
708
712
- /// Returns the last entry in the map for in-place manipulation.
713
- /// The key of this entry is the maximum key in the map.
709
+ /// Returns the entry with the maximum key in the map for in-place manipulation.
714
710
///
715
711
/// # Examples
716
712
///
@@ -721,16 +717,16 @@ impl<K, V> BTreeMap<K, V> {
721
717
/// let mut map = BTreeMap::new();
722
718
/// map.insert(1, "a");
723
719
/// map.insert(2, "b");
724
- /// if let Some(mut entry) = map.last_entry () {
720
+ /// if let Some(mut entry) = map.max_entry () {
725
721
/// if *entry.key() > 0 {
726
- /// entry.insert("last ");
722
+ /// entry.insert("max ");
727
723
/// }
728
724
/// }
729
725
/// assert_eq!(*map.get(&1).unwrap(), "a");
730
- /// assert_eq!(*map.get(&2).unwrap(), "last ");
726
+ /// assert_eq!(*map.get(&2).unwrap(), "max ");
731
727
/// ```
732
728
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
733
- pub fn last_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > >
729
+ pub fn max_entry ( & mut self ) -> Option < OccupiedEntry < ' _ , K , V > >
734
730
where
735
731
K : Ord ,
736
732
{
@@ -740,8 +736,7 @@ impl<K, V> BTreeMap<K, V> {
740
736
Some ( OccupiedEntry { handle : kv. forget_node_type ( ) , dormant_map, _marker : PhantomData } )
741
737
}
742
738
743
- /// Removes and returns the last element in the map.
744
- /// The key of this element is the maximum key that was in the map.
739
+ /// Removes and returns the key-value pair with the maximum key in the map.
745
740
///
746
741
/// # Examples
747
742
///
@@ -754,17 +749,17 @@ impl<K, V> BTreeMap<K, V> {
754
749
/// let mut map = BTreeMap::new();
755
750
/// map.insert(1, "a");
756
751
/// map.insert(2, "b");
757
- /// while let Some((key, _val)) = map.pop_last () {
752
+ /// while let Some((key, _val)) = map.pop_max () {
758
753
/// assert!(map.iter().all(|(k, _v)| *k < key));
759
754
/// }
760
755
/// assert!(map.is_empty());
761
756
/// ```
762
757
#[ unstable( feature = "map_first_last" , issue = "62924" ) ]
763
- pub fn pop_last ( & mut self ) -> Option < ( K , V ) >
758
+ pub fn pop_max ( & mut self ) -> Option < ( K , V ) >
764
759
where
765
760
K : Ord ,
766
761
{
767
- self . last_entry ( ) . map ( |entry| entry. remove_entry ( ) )
762
+ self . max_entry ( ) . map ( |entry| entry. remove_entry ( ) )
768
763
}
769
764
770
765
/// Returns `true` if the map contains a value for the specified key.
0 commit comments