diff options
| author | jofas <jonas@fc-web.de> | 2023-03-29 11:14:23 +0200 |
|---|---|---|
| committer | jofas <jonas@fc-web.de> | 2023-03-29 11:14:23 +0200 |
| commit | 37ed3cebbc24c9953ae0c2a17dd74ae1268b8650 (patch) | |
| tree | 0ba87cc697a939f8a454fc9e2752240de8284840 /library/alloc/src | |
| parent | 159ba8a92c9e2fa4121f106176309521f4af87e9 (diff) | |
| download | rust-37ed3cebbc24c9953ae0c2a17dd74ae1268b8650.tar.gz rust-37ed3cebbc24c9953ae0c2a17dd74ae1268b8650.zip | |
enhanced documentation of binary search methods for slice and VecDeque for unsorted instances
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/vec_deque/mod.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 451e4936bc5..1ae72b715cd 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2378,7 +2378,8 @@ impl<T, A: Allocator> VecDeque<T, A> { } /// Binary searches this `VecDeque` for a given element. - /// This behaves similarly to [`contains`] if this `VecDeque` is sorted. + /// If the `VecDeque` is not sorted, the returned result is unspecified and + /// meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2434,12 +2435,13 @@ impl<T, A: Allocator> VecDeque<T, A> { } /// Binary searches this `VecDeque` with a comparator function. - /// This behaves similarly to [`contains`] if this `VecDeque` is sorted. /// - /// The comparator function should implement an order consistent - /// with the sort order of the deque, returning an order code that - /// indicates whether its argument is `Less`, `Equal` or `Greater` - /// than the desired target. + /// The comparator function should return an order code that indicates + /// whether its argument is `Less`, `Equal` or `Greater` the desired + /// target. + /// If the `VecDeque` is not sorted or if the comparator function does not + /// implement an order consistent with the sort order of the underlying + /// `VecDeque`, the returned result is unspecified and meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any @@ -2489,10 +2491,11 @@ impl<T, A: Allocator> VecDeque<T, A> { } /// Binary searches this `VecDeque` with a key extraction function. - /// This behaves similarly to [`contains`] if this `VecDeque` is sorted. /// /// Assumes that the deque is sorted by the key, for instance with /// [`make_contiguous().sort_by_key()`] using the same key extraction function. + /// If the deque is not sorted by the key, the returned result is + /// unspecified and meaningless. /// /// If the value is found then [`Result::Ok`] is returned, containing the /// index of the matching element. If there are multiple matches, then any |
