update move sorting
This commit is contained in:
parent
36535f292a
commit
2994e9d7eb
1 changed files with 24 additions and 3 deletions
27
src/moves.rs
27
src/moves.rs
|
|
@ -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,
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue