Skip to content

Commit 2dd69aa

Browse files
committed
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.
1 parent 64de497 commit 2dd69aa

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
@@ -936,6 +936,7 @@ impl<K, V> BTreeMap<K, V> {
936936
/// Retains only the elements specified by the predicate.
937937
///
938938
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
939+
/// The elements are visited in ascending key order.
939940
///
940941
/// # Examples
941942
///

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

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

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

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

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

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

0 commit comments

Comments
 (0)