static unsafe void Swap <TX>(TX *left, TX *right) where TX : unmanaged { var tmp = *left; *left = *right; *right = tmp; }
static unsafe void SwapIfGreater <TX>(TX *left, TX *right) where TX : unmanaged, IComparable <TX> { if ((*left).CompareTo(*right) <= 0) { return; } Swap(left, right); }
static unsafe void InsertionSort <TX>(TX *left, TX *right) where TX : unmanaged, IComparable <TX> { for (var i = left; i < right; i++) { var j = i; var t = *(i + 1); while (j >= left && t.CompareTo(*j) < 0) { *(j + 1) = *j; j--; } *(j + 1) = t; } }