Skip to content

Commit f81a11b

Browse files
committed
Document that BTreeMap iteration is in order
Also change the examples to make this more obvious. Fixes #31129.
1 parent 8f36038 commit f81a11b

File tree

1 file changed

+10
-10
lines changed
  • src/libcollections/btree

1 file changed

+10
-10
lines changed

src/libcollections/btree/map.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1194,17 +1194,17 @@ unsafe fn unwrap_unchecked<T>(val: Option<T>) -> T {
11941194
}
11951195

11961196
impl<K, V> BTreeMap<K, V> {
1197-
/// Gets an iterator over the entries of the map.
1197+
/// Gets an iterator over the entries of the map, sorted by key.
11981198
///
11991199
/// # Examples
12001200
///
12011201
/// ```
12021202
/// use std::collections::BTreeMap;
12031203
///
12041204
/// let mut map = BTreeMap::new();
1205-
/// map.insert(1, "a");
1206-
/// map.insert(2, "b");
12071205
/// map.insert(3, "c");
1206+
/// map.insert(2, "b");
1207+
/// map.insert(1, "a");
12081208
///
12091209
/// for (key, value) in map.iter() {
12101210
/// println!("{}: {}", key, value);
@@ -1224,7 +1224,7 @@ impl<K, V> BTreeMap<K, V> {
12241224
}
12251225
}
12261226

1227-
/// Gets a mutable iterator over the entries of the map.
1227+
/// Gets a mutable iterator over the entries of the map, sorted by key.
12281228
///
12291229
/// # Examples
12301230
///
@@ -1257,16 +1257,16 @@ impl<K, V> BTreeMap<K, V> {
12571257
}
12581258
}
12591259

1260-
/// Gets an iterator over the keys of the map.
1260+
/// Gets an iterator over the keys of the map, in sorted order.
12611261
///
12621262
/// # Examples
12631263
///
12641264
/// ```
12651265
/// use std::collections::BTreeMap;
12661266
///
12671267
/// let mut a = BTreeMap::new();
1268-
/// a.insert(1, "a");
12691268
/// a.insert(2, "b");
1269+
/// a.insert(1, "a");
12701270
///
12711271
/// let keys: Vec<_> = a.keys().cloned().collect();
12721272
/// assert_eq!(keys, [1, 2]);
@@ -1276,19 +1276,19 @@ impl<K, V> BTreeMap<K, V> {
12761276
Keys { inner: self.iter() }
12771277
}
12781278

1279-
/// Gets an iterator over the values of the map.
1279+
/// Gets an iterator over the values of the map, in order by key.
12801280
///
12811281
/// # Examples
12821282
///
12831283
/// ```
12841284
/// use std::collections::BTreeMap;
12851285
///
12861286
/// let mut a = BTreeMap::new();
1287-
/// a.insert(1, "a");
1288-
/// a.insert(2, "b");
1287+
/// a.insert(1, "hello");
1288+
/// a.insert(2, "goodbye");
12891289
///
12901290
/// let values: Vec<&str> = a.values().cloned().collect();
1291-
/// assert_eq!(values, ["a", "b"]);
1291+
/// assert_eq!(values, ["hello", "goodbye"]);
12921292
/// ```
12931293
#[stable(feature = "rust1", since = "1.0.0")]
12941294
pub fn values<'a>(&'a self) -> Values<'a, K, V> {

0 commit comments

Comments
 (0)