Skip to content

Commit 9057a6d

Browse files
committed
Clarify explicitly that BTree{Map,Set} are ordered.
1 parent 092e1c9 commit 9057a6d

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
3131
// An empty map is represented either by the absence of a root node or by a
3232
// root node that is an empty leaf.
3333

34-
/// A map based on a [B-Tree].
34+
/// An ordered map based on a [B-Tree].
3535
///
3636
/// B-Trees represent a fundamental compromise between cache-efficiency and actually minimizing
3737
/// the amount of work performed in a search. In theory, a binary search tree (BST) is the optimal
@@ -65,6 +65,9 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
6565
/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined
6666
/// behavior.
6767
///
68+
/// Entries in a `BTreeMap` are stored in ascending order according to the [`Ord`] implementation on the key.
69+
/// Thus, iteration methods are guaranteed to produce iterators that yield items in that order.
70+
///
6871
/// [B-Tree]: https://en.wikipedia.org/wiki/B-tree
6972
/// [`Cell`]: core::cell::Cell
7073
/// [`RefCell`]: core::cell::RefCell

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::Recover;
1515

1616
// FIXME(conventions): implement bounded iterators
1717

18-
/// A set based on a B-Tree.
18+
/// An ordered set based on a B-Tree.
1919
///
2020
/// See [`BTreeMap`]'s documentation for a detailed discussion of this collection's performance
2121
/// benefits and drawbacks.
@@ -27,6 +27,9 @@ use super::Recover;
2727
/// incorrect results, aborts, memory leaks, or non-termination) but will not be undefined
2828
/// behavior.
2929
///
30+
/// Entries in a `BTreeSet` are stored in ascending order according to the [`Ord`] implementation on the key.
31+
/// Thus, iteration methods are guaranteed to produce iterators that yield items in that order.
32+
///
3033
/// [`Ord`]: core::cmp::Ord
3134
/// [`Cell`]: core::cell::Cell
3235
/// [`RefCell`]: core::cell::RefCell

library/alloc/src/collections/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ pub mod vec_deque;
1414
#[cfg(not(no_global_oom_handling))]
1515
#[stable(feature = "rust1", since = "1.0.0")]
1616
pub mod btree_map {
17-
//! A map based on a B-Tree.
17+
//! An ordered map based on a B-Tree.
1818
#[stable(feature = "rust1", since = "1.0.0")]
1919
pub use super::btree::map::*;
2020
}
2121

2222
#[cfg(not(no_global_oom_handling))]
2323
#[stable(feature = "rust1", since = "1.0.0")]
2424
pub mod btree_set {
25-
//! A set based on a B-Tree.
25+
//! An ordered set based on a B-Tree.
2626
#[stable(feature = "rust1", since = "1.0.0")]
2727
pub use super::btree::set::*;
2828
}

0 commit comments

Comments
 (0)