@Test public void testMergeSortIsStable() { final XorShift128P rnd = new XorShift128P(0xdeadbeefL); final int[] data = new int[10000]; for (int i = 0; i < data.length; i++) { data[i] = rnd.nextInt(0x100); } int[] order = IndirectSort.mergesort( 0, data.length, (indexA, indexB) -> (data[indexA] & 0xf0) - (data[indexB] & 0xf0)); for (int i = 1; i < order.length; i++) { if ((data[order[i - 1]] & 0xf0) == (data[order[i]] & 0xf0)) { assertTrue(order[i - 1] < order[i]); } } }
public static int[] mergesort(int start, int length, IntBinaryOperator comparator) { final int[] src = createOrderArray(start, length); if (length > 1) { final int[] dst = (int[]) src.clone(); topDownMergeSort(src, dst, 0, length, comparator); return dst; } return src; }
IndirectSort { public static int[] mergesort(int start, int length, IntBinaryOperator comparator) { final int[] src = createOrderArray(start, length); if (length > 1) { final int[] dst = (int[]) src.clone(); topDownMergeSort(src, dst, 0, length, comparator); return dst; } return src; } }
IndirectSort { public static int[] mergesort(int start, int length, IntBinaryOperator comparator) { final int[] src = createOrderArray(start, length); if (length > 1) { final int[] dst = (int[]) src.clone(); topDownMergeSort(src, dst, 0, length, comparator); return dst; } return src; } private  IndirectSort(); }
IndirectSort { public static int[] mergesort(int start, int length, IntBinaryOperator comparator) { final int[] src = createOrderArray(start, length); if (length > 1) { final int[] dst = (int[]) src.clone(); topDownMergeSort(src, dst, 0, length, comparator); return dst; } return src; } private  IndirectSort(); static int[] mergesort(int start, int length, IntBinaryOperator comparator); static int[] mergesort(
      T[] input, int start, int length, Comparator<? super T> comparator); }
IndirectSort { public static int[] mergesort(int start, int length, IntBinaryOperator comparator) { final int[] src = createOrderArray(start, length); if (length > 1) { final int[] dst = (int[]) src.clone(); topDownMergeSort(src, dst, 0, length, comparator); return dst; } return src; } private  IndirectSort(); static int[] mergesort(int start, int length, IntBinaryOperator comparator); static int[] mergesort(
      T[] input, int start, int length, Comparator<? super T> comparator);  }