Skip to content

Commit 249a11f

Browse files
authored
Rollup merge of #86790 - janikrabe:retain-iter-order-doc, r=m-ou-se
Document iteration order of `retain` functions For `HashSet` and `HashMap`, this simply copies the comment from `BinaryHeap::retain`. For `BTreeSet` and `BTreeMap`, this adds an additional guarantee that wasn't previously documented. I think that because these data structures are inherently ordered and other functions guarantee ordered iteration, it makes sense to provide this guarantee for `retain` as well.
2 parents d453290 + 2dd69aa commit 249a11f

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ impl<K, V> BTreeMap<K, V> {
935935
/// Retains only the elements specified by the predicate.
936936
///
937937
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
938+
/// The elements are visited in ascending key order.
938939
///
939940
/// # Examples
940941
///

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

+1
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ impl<T> BTreeSet<T> {
846846
/// Retains only the elements specified by the predicate.
847847
///
848848
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
849+
/// The elements are visited in ascending order.
849850
///
850851
/// # Examples
851852
///

library/std/src/collections/hash/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ where
934934
/// Retains only the elements specified by the predicate.
935935
///
936936
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
937+
/// The elements are visited in unsorted (and unspecified) order.
937938
///
938939
/// # Examples
939940
///

library/std/src/collections/hash/set.rs

+1
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ where
912912
/// Retains only the elements specified by the predicate.
913913
///
914914
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
915+
/// The elements are visited in unsorted (and unspecified) order.
915916
///
916917
/// # Examples
917918
///

0 commit comments

Comments
 (0)