@@ -1342,6 +1342,12 @@ impl<T, A: Allocator> VecDeque<T, A> {
1342
1342
/// Returns `true` if the deque contains an element equal to the
1343
1343
/// given value.
1344
1344
///
1345
+ /// This operation is *O*(*n*).
1346
+ ///
1347
+ /// Note that if you have a sorted `VecDeque`, [`binary_search`] may be faster.
1348
+ ///
1349
+ /// [`binary_search`]: VecDeque::binary_search
1350
+ ///
1345
1351
/// # Examples
1346
1352
///
1347
1353
/// ```
@@ -2560,7 +2566,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
2560
2566
}
2561
2567
}
2562
2568
2563
- /// Binary searches the sorted deque for a given element.
2569
+ /// Binary searches this `VecDeque` for a given element.
2570
+ /// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
2564
2571
///
2565
2572
/// If the value is found then [`Result::Ok`] is returned, containing the
2566
2573
/// index of the matching element. If there are multiple matches, then any
@@ -2570,6 +2577,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
2570
2577
///
2571
2578
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
2572
2579
///
2580
+ /// [`contains`]: VecDeque::contains
2573
2581
/// [`binary_search_by`]: VecDeque::binary_search_by
2574
2582
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
2575
2583
/// [`partition_point`]: VecDeque::partition_point
@@ -2614,7 +2622,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
2614
2622
self . binary_search_by ( |e| e. cmp ( x) )
2615
2623
}
2616
2624
2617
- /// Binary searches the sorted deque with a comparator function.
2625
+ /// Binary searches this `VecDeque` with a comparator function.
2626
+ /// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
2618
2627
///
2619
2628
/// The comparator function should implement an order consistent
2620
2629
/// with the sort order of the deque, returning an order code that
@@ -2629,6 +2638,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
2629
2638
///
2630
2639
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
2631
2640
///
2641
+ /// [`contains`]: VecDeque::contains
2632
2642
/// [`binary_search`]: VecDeque::binary_search
2633
2643
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
2634
2644
/// [`partition_point`]: VecDeque::partition_point
@@ -2667,7 +2677,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
2667
2677
}
2668
2678
}
2669
2679
2670
- /// Binary searches the sorted deque with a key extraction function.
2680
+ /// Binary searches this `VecDeque` with a key extraction function.
2681
+ /// This behaves similarly to [`contains`] if this `VecDeque` is sorted.
2671
2682
///
2672
2683
/// Assumes that the deque is sorted by the key, for instance with
2673
2684
/// [`make_contiguous().sort_by_key()`] using the same key extraction function.
@@ -2680,6 +2691,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
2680
2691
///
2681
2692
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
2682
2693
///
2694
+ /// [`contains`]: VecDeque::contains
2683
2695
/// [`make_contiguous().sort_by_key()`]: VecDeque::make_contiguous
2684
2696
/// [`binary_search`]: VecDeque::binary_search
2685
2697
/// [`binary_search_by`]: VecDeque::binary_search_by
0 commit comments