mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-21 09:37:16 +08:00
Simplify our insertion sort implementation
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
25
src/types.h
25
src/types.h
@@ -485,23 +485,18 @@ inline const std::string square_to_string(Square s) {
|
|||||||
/// Our insertion sort implementation, works with pointers and iterators and is
|
/// Our insertion sort implementation, works with pointers and iterators and is
|
||||||
/// guaranteed to be stable, as is needed.
|
/// guaranteed to be stable, as is needed.
|
||||||
template<typename T, typename K>
|
template<typename T, typename K>
|
||||||
void sort(K firstMove, K lastMove)
|
void sort(K first, K last)
|
||||||
{
|
{
|
||||||
T value;
|
T tmp;
|
||||||
K cur, p, d;
|
K p, q;
|
||||||
|
|
||||||
if (firstMove != lastMove)
|
for (p = first + 1; p < last; p++)
|
||||||
for (cur = firstMove + 1; cur != lastMove; cur++)
|
{
|
||||||
{
|
tmp = *p;
|
||||||
p = d = cur;
|
for (q = p; q != first && *(q-1) < tmp; --q)
|
||||||
value = *p--;
|
*q = *(q-1);
|
||||||
if (*p < value)
|
*q = tmp;
|
||||||
{
|
}
|
||||||
do *d = *p;
|
|
||||||
while (--d != firstMove && *--p < value);
|
|
||||||
*d = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(TYPES_H_INCLUDED)
|
#endif // !defined(TYPES_H_INCLUDED)
|
||||||
|
|||||||
Reference in New Issue
Block a user