--- /dev/null 2019-08-05 11:37:22.000000000 -0700 +++ new/test/jdk/java/util/Arrays/java.base/java/util/SortingHelper.java 2019-08-05 11:37:21.000000000 -0700 @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.util; + +/** + * This class provides access to package-private + * methods of DualPivotQuicksort class. + * + * @author Vladimir Yaroslavskiy + * + * @version 2018.08.18 + * + * @since 14 + */ +public final class SortingHelper { + + // Heap sort is invoked for this depth + private static final int BIG_DEPTH = 100; + + private static final SortingHelper DUAL_PIVOT_QUICKSORT_HELPER = new SortingHelper(0); + private static final SortingHelper PARALLEL_SORT_HELPER = new SortingHelper(87); + private static final SortingHelper HEAP_SORT_HELPER = new SortingHelper(-1); + + private int parallelism; + + public static SortingHelper getDualPivotQuicksortHelper() { + return DUAL_PIVOT_QUICKSORT_HELPER; + } + + public static SortingHelper getParallelSortHelper() { + return PARALLEL_SORT_HELPER; + } + + public static SortingHelper getHeapSortHelper() { + return HEAP_SORT_HELPER; + } + + private SortingHelper(int parallelism) { + this.parallelism = parallelism; + } + + public void sort(int[] a) { + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, 0, a.length); + } else { + DualPivotQuicksort.sort(a, parallelism, 0, a.length); + } + } + + public void sort(int[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, low, high); + } else { + DualPivotQuicksort.sort(a, parallelism, low, high); + } + } + + public void sort(long[] a) { + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, 0, a.length); + } else { + DualPivotQuicksort.sort(a, parallelism, 0, a.length); + } + } + + public void sort(long[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, low, high); + } else { + DualPivotQuicksort.sort(a, parallelism, low, high); + } + } + + public void sort(byte[] a) { + DualPivotQuicksort.sort(a, 0, a.length); + } + + public void sort(byte[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + DualPivotQuicksort.sort(a, low, high); + } + + public void sort(char[] a) { + if (parallelism < 0) { + DualPivotQuicksort.sort(a, BIG_DEPTH, 0, a.length); + } else { + DualPivotQuicksort.sort(a, 0, a.length); + } + } + + public void sort(char[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + + if (parallelism < 0) { + DualPivotQuicksort.sort(a, BIG_DEPTH, low, high); + } else { + DualPivotQuicksort.sort(a, low, high); + } + } + + public void sort(short[] a) { + if (parallelism < 0) { + DualPivotQuicksort.sort(a, BIG_DEPTH, 0, a.length); + } else { + DualPivotQuicksort.sort(a, 0, a.length); + } + } + + public void sort(short[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + + if (parallelism < 0) { + DualPivotQuicksort.sort(a, BIG_DEPTH, low, high); + } else { + DualPivotQuicksort.sort(a, low, high); + } + } + + public void sort(float[] a) { + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, 0, a.length); + } else { + DualPivotQuicksort.sort(a, parallelism, 0, a.length); + } + } + + public void sort(float[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, low, high); + } else { + DualPivotQuicksort.sort(a, parallelism, low, high); + } + } + + public void sort(double[] a) { + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, 0, a.length); + } else { + DualPivotQuicksort.sort(a, parallelism, 0, a.length); + } + } + + public void sort(double[] a, int low, int high) { + Arrays.rangeCheck(a.length, low, high); + + if (parallelism < 0) { + DualPivotQuicksort.sort(null, a, BIG_DEPTH, low, high); + } else { + DualPivotQuicksort.sort(a, parallelism, low, high); + } + } + + @Override + public String toString() { + if (parallelism < 0) { + return "Heap sort"; + } + if (parallelism == 0) { + return "Dual-Pivot Quicksort"; + } + return "Parallel Sorting"; + } +}