Skip to content

Commit 3143030

Browse files
authored
Rollup merge of #112151 - chloekek:patch-1, r=workingjubilee
Clarify behavior of inclusive bounds in BTreeMap::{lower,upper}_bound It wasn’t quite clear to me how these methods would interpret inclusive bounds so I added examples for those.
2 parents fb53384 + aee2b35 commit 3143030

File tree

1 file changed

+8
-0
lines changed
  • library/alloc/src/collections/btree

1 file changed

+8
-0
lines changed

library/alloc/src/collections/btree/map.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
25432543
/// a.insert(2, "b");
25442544
/// a.insert(3, "c");
25452545
/// a.insert(4, "c");
2546+
/// let cursor = a.lower_bound(Bound::Included(&2));
2547+
/// assert_eq!(cursor.key(), Some(&2));
25462548
/// let cursor = a.lower_bound(Bound::Excluded(&2));
25472549
/// assert_eq!(cursor.key(), Some(&3));
25482550
/// ```
@@ -2582,6 +2584,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
25822584
/// a.insert(2, "b");
25832585
/// a.insert(3, "c");
25842586
/// a.insert(4, "c");
2587+
/// let cursor = a.lower_bound_mut(Bound::Included(&2));
2588+
/// assert_eq!(cursor.key(), Some(&2));
25852589
/// let cursor = a.lower_bound_mut(Bound::Excluded(&2));
25862590
/// assert_eq!(cursor.key(), Some(&3));
25872591
/// ```
@@ -2634,6 +2638,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
26342638
/// a.insert(2, "b");
26352639
/// a.insert(3, "c");
26362640
/// a.insert(4, "c");
2641+
/// let cursor = a.upper_bound(Bound::Included(&3));
2642+
/// assert_eq!(cursor.key(), Some(&3));
26372643
/// let cursor = a.upper_bound(Bound::Excluded(&3));
26382644
/// assert_eq!(cursor.key(), Some(&2));
26392645
/// ```
@@ -2673,6 +2679,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
26732679
/// a.insert(2, "b");
26742680
/// a.insert(3, "c");
26752681
/// a.insert(4, "c");
2682+
/// let cursor = a.upper_bound_mut(Bound::Included(&3));
2683+
/// assert_eq!(cursor.key(), Some(&3));
26762684
/// let cursor = a.upper_bound_mut(Bound::Excluded(&3));
26772685
/// assert_eq!(cursor.key(), Some(&2));
26782686
/// ```

0 commit comments

Comments
 (0)