1
0
Fork 0

update move sorting

This commit is contained in:
Paul-Nicolas Madelaine 2025-11-17 22:07:05 +01:00
parent 36535f292a
commit 2994e9d7eb

View file

@ -298,11 +298,32 @@ impl<'l> Moves<'l> {
})
}
/// Sorts the moves in the list.
///
/// See [`slice::sort_unstable_by`] for potential panics.
/// Sorts the list in ascending order with a comparison function, preserving initial order of
/// equal elements. See `std::slice::sort_by` for details.
#[inline]
pub fn sort_by<F>(&mut self, mut compare: F)
where
F: FnMut(Move, Move) -> core::cmp::Ordering,
{
self.array.as_mut_slice().sort_by(|a, b| {
compare(
Move {
position: self.position,
raw: *a,
},
Move {
position: self.position,
raw: *b,
},
)
});
}
/// Sorts the list in ascending order with a comparison function, **without** preserving the
/// initial order of equal elements. See [`sort_unstable_by`](`slice::sort_unstable_by`) for
/// details.
#[inline]
pub fn sort_unstable_by<F>(&mut self, mut compare: F)
where
F: FnMut(Move, Move) -> core::cmp::Ordering,
{