]> git.sesse.net Git - stockfish/commitdiff
Simplify our insertion sort implementation
authorMarco Costalba <mcostalba@gmail.com>
Sun, 22 Jan 2012 21:53:57 +0000 (22:53 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 23 Jan 2012 19:24:15 +0000 (20:24 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/types.h

index 601d0703761a3fa5a1e1e51ac6189a1e80c82472..8ce7dab55df09cc92a9ba14ebd2ef4c48de94fad 100644 (file)
@@ -485,23 +485,18 @@ inline const std::string square_to_string(Square s) {
 /// Our insertion sort implementation, works with pointers and iterators and is
 /// guaranteed to be stable, as is needed.
 template<typename T, typename K>
 /// Our insertion sort implementation, works with pointers and iterators and is
 /// guaranteed to be stable, as is needed.
 template<typename T, typename K>
-void sort(K firstMove, K lastMove)
+void sort(K first, K last)
 {
 {
-  T value;
-  K cur, p, d;
-
-  if (firstMove != lastMove)
-      for (cur = firstMove + 1; cur != lastMove; cur++)
-      {
-          p = d = cur;
-          value = *p--;
-          if (*p < value)
-          {
-              do *d = *p;
-              while (--d != firstMove && *--p < value);
-              *d = value;
-          }
-      }
+  T tmp;
+  K p, q;
+
+  for (p = first + 1; p < last; p++)
+  {
+      tmp = *p;
+      for (q = p; q != first && *(q-1) < tmp; --q)
+          *q = *(q-1);
+      *q = tmp;
+  }
 }
 
 #endif // !defined(TYPES_H_INCLUDED)
 }
 
 #endif // !defined(TYPES_H_INCLUDED)