Skip to content

Commit 6dec9e4

Browse files
committed
FEAT: Add OrderSet::sort,sort_by()
1 parent c047493 commit 6dec9e4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/set.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,20 @@ impl<T, S> OrderSet<T, S>
342342
self.map.retain(move |x, &mut ()| keep(x))
343343
}
344344

345+
/// Sort the set’s values by their default ordering.
346+
pub fn sort(&mut self)
347+
where T: Ord,
348+
{
349+
self.map.sort_keys()
350+
}
351+
352+
/// Sort the set’s values in place using the comparison function `compare`.
353+
pub fn sort_by<F>(&mut self, mut compare: F)
354+
where F: FnMut(&T, &T) -> Ordering,
355+
{
356+
self.map.sort_by(move |a, _, b, _| compare(a, b));
357+
}
358+
345359
/// Sort the values of the set and return a by value iterator of
346360
/// the values with the result.
347361
///

0 commit comments

Comments
 (0)