|
|
|
@@ -20,6 +20,7 @@ use crate::{ |
|
|
|
map::Map, |
|
|
|
map_init::MapInit, |
|
|
|
map_with::MapWith, |
|
|
|
max::{Max, MaxBy}, |
|
|
|
min::{Min, MinBy}, |
|
|
|
product::Product, |
|
|
|
reduce::{Reduce, ReduceWith}, |
|
|
|
@@ -1139,6 +1140,60 @@ pub trait ParallelIterator<'a>: Sized + Send { |
|
|
|
MinBy::new(self, operation) |
|
|
|
} |
|
|
|
|
|
|
|
/// Computes the maximum of all the items in the iterator. If the |
|
|
|
/// iterator is empty, `None` is returned; otherwise, `Some(max)` |
|
|
|
/// is returned. |
|
|
|
/// |
|
|
|
/// Note that the order in which the items will be reduced is not |
|
|
|
/// specified, so if the `Ord` impl is not truly associative, then |
|
|
|
/// the results are not deterministic. |
|
|
|
/// |
|
|
|
/// Basically equivalent to `self.reduce_with(|a, b| cmp::max(a, b))`. |
|
|
|
/// |
|
|
|
/// # Examples |
|
|
|
/// |
|
|
|
/// ``` |
|
|
|
/// use rayon::prelude::*; |
|
|
|
/// |
|
|
|
/// let a = [45, 74, 32]; |
|
|
|
/// |
|
|
|
/// assert_eq!(a.par_iter().max(), Some(&74)); |
|
|
|
/// |
|
|
|
/// let b: [i32; 0] = []; |
|
|
|
/// |
|
|
|
/// assert_eq!(b.par_iter().max(), None); |
|
|
|
/// ``` |
|
|
|
fn max(self) -> Max<Self> |
|
|
|
where |
|
|
|
Self::Item: Ord, |
|
|
|
{ |
|
|
|
Max::new(self) |
|
|
|
} |
|
|
|
|
|
|
|
/// Computes the maximum of all the items in the iterator with respect to |
|
|
|
/// the given comparison function. If the iterator is empty, `None` is |
|
|
|
/// returned; otherwise, `Some(min)` is returned. |
|
|
|
/// |
|
|
|
/// Note that the order in which the items will be reduced is not |
|
|
|
/// specified, so if the comparison function is not associative, then |
|
|
|
/// the results are not deterministic. |
|
|
|
/// |
|
|
|
/// # Examples |
|
|
|
/// |
|
|
|
/// ``` |
|
|
|
/// use rayon::prelude::*; |
|
|
|
/// |
|
|
|
/// let a = [-3_i32, 77, 53, 240, -1]; |
|
|
|
/// |
|
|
|
/// assert_eq!(a.par_iter().max_by(|x, y| x.abs().cmp(&y.abs())), Some(&240)); |
|
|
|
/// ``` |
|
|
|
fn max_by<O>(self, operation: O) -> MaxBy<Self, O> |
|
|
|
where |
|
|
|
O: Fn(&Self::Item, &Self::Item) -> Ordering + Clone + Send + Sync + 'a, |
|
|
|
{ |
|
|
|
MaxBy::new(self, operation) |
|
|
|
} |
|
|
|
|
|
|
|
/// Creates a fresh collection containing all the elements produced |
|
|
|
/// by this parallel iterator. |
|
|
|
/// |
|
|
|
|