Skip to content

Commit aee2b35

Browse files
authored
Clarify behavior of inclusive bounds in BTreeMap::{lower,upper}_bound
1 parent ad8304a commit aee2b35

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
@@ -2603,6 +2603,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
26032603
/// a.insert(2, "b");
26042604
/// a.insert(3, "c");
26052605
/// a.insert(4, "c");
2606+
/// let cursor = a.lower_bound(Bound::Included(&2));
2607+
/// assert_eq!(cursor.key(), Some(&2));
26062608
/// let cursor = a.lower_bound(Bound::Excluded(&2));
26072609
/// assert_eq!(cursor.key(), Some(&3));
26082610
/// ```
@@ -2644,6 +2646,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
26442646
/// a.insert(2, "b");
26452647
/// a.insert(3, "c");
26462648
/// a.insert(4, "c");
2649+
/// let cursor = a.lower_bound_mut(Bound::Included(&2));
2650+
/// assert_eq!(cursor.key(), Some(&2));
26472651
/// let cursor = a.lower_bound_mut(Bound::Excluded(&2));
26482652
/// assert_eq!(cursor.key(), Some(&3));
26492653
/// ```
@@ -2698,6 +2702,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
26982702
/// a.insert(2, "b");
26992703
/// a.insert(3, "c");
27002704
/// a.insert(4, "c");
2705+
/// let cursor = a.upper_bound(Bound::Included(&3));
2706+
/// assert_eq!(cursor.key(), Some(&3));
27012707
/// let cursor = a.upper_bound(Bound::Excluded(&3));
27022708
/// assert_eq!(cursor.key(), Some(&2));
27032709
/// ```
@@ -2739,6 +2745,8 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
27392745
/// a.insert(2, "b");
27402746
/// a.insert(3, "c");
27412747
/// a.insert(4, "c");
2748+
/// let cursor = a.upper_bound_mut(Bound::Included(&3));
2749+
/// assert_eq!(cursor.key(), Some(&3));
27422750
/// let cursor = a.upper_bound_mut(Bound::Excluded(&3));
27432751
/// assert_eq!(cursor.key(), Some(&2));
27442752
/// ```

0 commit comments

Comments
 (0)