Skip to content

Commit

Permalink
fix: add forgotten set parallel unstable sorting methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bhgomes committed Dec 9, 2021
1 parent 2a2b163 commit 7bdcfc0
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/rayon/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ where
});
}

/// Sort the set’s values in place and in parallel, using the comparison function `compare`.
/// Sort the set’s values in place and in parallel, using the comparison function `cmp`.
pub fn par_sort_by<F>(&mut self, cmp: F)
where
F: Fn(&T, &T) -> Ordering + Sync,
Expand All @@ -462,7 +462,7 @@ where
});
}

/// Sort the values of the set in parallel and return a by value parallel iterator of
/// Sort the values of the set in parallel and return a by-value parallel iterator of
/// the values with the result.
pub fn par_sorted_by<F>(self, cmp: F) -> IntoParIter<T>
where
Expand All @@ -472,6 +472,37 @@ where
entries.par_sort_by(move |a, b| cmp(&a.key, &b.key));
IntoParIter { entries }
}

/// Sort the set's values in parallel by their default ordering.
pub fn par_sort_unstable(&mut self)
where
T: Ord,
{
self.with_entries(|entries| {
entries.par_sort_unstable_by(|a, b| T::cmp(&a.key, &b.key));
});
}

/// Sort the set’s values in place and in parallel, using the comparison function `cmp`.
pub fn par_sort_unstable_by<F>(&mut self, cmp: F)
where
F: Fn(&T, &T) -> Ordering + Sync,
{
self.with_entries(|entries| {
entries.par_sort_unstable_by(move |a, b| cmp(&a.key, &b.key));
});
}

/// Sort the values of the set in parallel and return a by-value parallel iterator of
/// the values with the result.
pub fn par_sorted_unstable_by<F>(self, cmp: F) -> IntoParIter<T>
where
F: Fn(&T, &T) -> Ordering + Sync,
{
let mut entries = self.into_entries();
entries.par_sort_unstable_by(move |a, b| cmp(&a.key, &b.key));
IntoParIter { entries }
}
}

/// Requires crate feature `"rayon"`.
Expand Down

0 comments on commit 7bdcfc0

Please sign in to comment.