test/jdk/java/util/Arrays/ParallelSorting.java
author pli
Tue, 16 Jul 2019 00:57:00 +0000
changeset 55689 8c5c9d86e1d6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227512: [TESTBUG] Fix JTReg javac test failures with Graal Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14925
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 17712
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
14925
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     4
 *
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     8
 *
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    13
 * accompanied this code).
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    14
 *
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    18
 *
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    21
 * questions.
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    22
 */
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    23
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    24
/* Adapted from test/java/util/Arrays/Sorting.java
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    25
 *
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    26
 * Where that test checks Arrays.sort against manual quicksort routines,
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    27
 * this test checks parallelSort against either Arrays.sort or manual
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    28
 * quicksort routines.
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    29
 */
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    30
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    31
/*
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    32
 * @test
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    33
 * @bug 8003981
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    34
 * @run main ParallelSorting -shortrun
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    35
 * @summary Exercise Arrays.parallelSort (adapted from test Sorting)
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    36
 *
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    37
 * @author Vladimir Yaroslavskiy
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    38
 * @author Jon Bentley
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    39
 * @author Josh Bloch
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    40
 */
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    41
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    42
import java.util.Arrays;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    43
import java.util.Random;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    44
import java.io.PrintStream;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    45
import java.util.Comparator;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    46
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    47
public class ParallelSorting {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    48
    private static final PrintStream out = System.out;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    49
    private static final PrintStream err = System.err;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    50
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    51
    // Array lengths used in a long run (default)
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    52
    private static final int[] LONG_RUN_LENGTHS = {
17712
b56c69500af6 8014076: Arrays parallel and serial sorting improvements
dl
parents: 14925
diff changeset
    53
        1000, 10000, 100000, 1000000 };
14925
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    54
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    55
    // Array lengths used in a short run
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    56
    private static final int[] SHORT_RUN_LENGTHS = {
17712
b56c69500af6 8014076: Arrays parallel and serial sorting improvements
dl
parents: 14925
diff changeset
    57
        5000, 9000, 10000, 12000 };
14925
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    58
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    59
    // Random initial values used in a long run (default)
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    60
    private static final long[] LONG_RUN_RANDOMS = { 666, 0xC0FFEE, 999 };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    61
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    62
    // Random initial values used in a short run
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    63
    private static final long[] SHORT_RUN_RANDOMS = { 666 };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    64
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    65
    public static void main(String[] args) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    66
        boolean shortRun = args.length > 0 && args[0].equals("-shortrun");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    67
        long start = System.currentTimeMillis();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    68
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    69
        if (shortRun) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    70
            testAndCheck(SHORT_RUN_LENGTHS, SHORT_RUN_RANDOMS);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    71
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    72
            testAndCheck(LONG_RUN_LENGTHS, LONG_RUN_RANDOMS);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    73
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    74
        long end = System.currentTimeMillis();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    75
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    76
        out.format("PASSED in %d sec.\n", Math.round((end - start) / 1E3));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    77
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    78
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    79
    private static void testAndCheck(int[] lengths, long[] randoms) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    80
        testEmptyAndNullIntArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    81
        testEmptyAndNullLongArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    82
        testEmptyAndNullShortArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    83
        testEmptyAndNullCharArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    84
        testEmptyAndNullByteArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    85
        testEmptyAndNullFloatArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    86
        testEmptyAndNullDoubleArray();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    87
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    88
        for (int length : lengths) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    89
            testMergeSort(length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    90
            testAndCheckRange(length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    91
            testAndCheckSubArray(length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    92
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    93
        for (long seed : randoms) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    94
            for (int length : lengths) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    95
                testAndCheckWithInsertionSort(length, new MyRandom(seed));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    96
                testAndCheckWithCheckSum(length, new MyRandom(seed));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    97
                testAndCheckWithScrambling(length, new MyRandom(seed));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    98
                testAndCheckFloat(length, new MyRandom(seed));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
    99
                testAndCheckDouble(length, new MyRandom(seed));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   100
                testStable(length, new MyRandom(seed));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   101
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   102
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   103
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   104
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   105
    private static void testEmptyAndNullIntArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   106
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   107
        Arrays.parallelSort(new int[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   108
        Arrays.parallelSort(new int[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   109
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   110
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   111
            Arrays.parallelSort((int[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   112
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   113
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   114
                Arrays.parallelSort((int[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   115
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   116
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   117
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   118
            failed("Arrays.parallelSort(int[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   119
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   120
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   121
        failed("Arrays.parallelSort(int[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   122
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   123
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   124
    private static void testEmptyAndNullLongArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   125
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   126
        Arrays.parallelSort(new long[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   127
        Arrays.parallelSort(new long[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   128
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   129
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   130
            Arrays.parallelSort((long[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   131
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   132
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   133
                Arrays.parallelSort((long[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   134
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   135
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   136
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   137
            failed("Arrays.parallelSort(long[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   138
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   139
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   140
        failed("Arrays.parallelSort(long[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   141
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   142
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   143
    private static void testEmptyAndNullShortArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   144
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   145
        Arrays.parallelSort(new short[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   146
        Arrays.parallelSort(new short[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   147
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   148
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   149
            Arrays.parallelSort((short[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   150
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   151
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   152
                Arrays.parallelSort((short[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   153
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   154
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   155
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   156
            failed("Arrays.parallelSort(short[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   157
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   158
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   159
        failed("Arrays.parallelSort(short[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   160
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   161
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   162
    private static void testEmptyAndNullCharArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   163
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   164
        Arrays.parallelSort(new char[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   165
        Arrays.parallelSort(new char[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   166
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   167
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   168
            Arrays.parallelSort((char[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   169
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   170
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   171
                Arrays.parallelSort((char[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   172
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   173
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   174
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   175
            failed("Arrays.parallelSort(char[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   176
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   177
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   178
        failed("Arrays.parallelSort(char[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   179
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   180
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   181
    private static void testEmptyAndNullByteArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   182
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   183
        Arrays.parallelSort(new byte[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   184
        Arrays.parallelSort(new byte[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   185
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   186
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   187
            Arrays.parallelSort((byte[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   188
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   189
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   190
                Arrays.parallelSort((byte[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   191
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   192
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   193
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   194
            failed("Arrays.parallelSort(byte[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   195
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   196
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   197
        failed("Arrays.parallelSort(byte[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   198
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   199
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   200
    private static void testEmptyAndNullFloatArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   201
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   202
        Arrays.parallelSort(new float[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   203
        Arrays.parallelSort(new float[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   204
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   205
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   206
            Arrays.parallelSort((float[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   207
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   208
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   209
                Arrays.parallelSort((float[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   210
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   211
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   212
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   213
            failed("Arrays.parallelSort(float[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   214
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   215
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   216
        failed("Arrays.parallelSort(float[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   217
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   218
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   219
    private static void testEmptyAndNullDoubleArray() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   220
        ourDescription = "Check empty and null array";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   221
        Arrays.parallelSort(new double[]{});
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   222
        Arrays.parallelSort(new double[]{}, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   223
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   224
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   225
            Arrays.parallelSort((double[]) null);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   226
        } catch (NullPointerException expected) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   227
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   228
                Arrays.parallelSort((double[]) null, 0, 0);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   229
            } catch (NullPointerException expected2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   230
                return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   231
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   232
            failed("Arrays.parallelSort(double[],fromIndex,toIndex) shouldn't " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   233
                "catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   234
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   235
        failed("Arrays.parallelSort(double[]) shouldn't catch null array");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   236
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   237
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   238
    private static void testAndCheckSubArray(int length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   239
        ourDescription = "Check sorting of subarray";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   240
        int[] golden = new int[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   241
        boolean newLine = false;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   242
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   243
        for (int m = 1; m < length / 2; m *= 2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   244
            newLine = true;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   245
            int fromIndex = m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   246
            int toIndex = length - m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   247
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   248
            prepareSubArray(golden, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   249
            int[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   250
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   251
            for (TypeConverter converter : TypeConverter.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   252
                out.println("Test 'subarray': " + converter +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   253
                   " length = " + length + ", m = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   254
                Object convertedGolden = converter.convert(golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   255
                Object convertedTest = converter.convert(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   256
                sortSubArray(convertedTest, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   257
                checkSubArray(convertedTest, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   258
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   259
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   260
        if (newLine) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   261
            out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   262
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   263
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   264
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   265
    private static void testAndCheckRange(int length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   266
        ourDescription = "Check range check";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   267
        int[] golden = new int[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   268
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   269
        for (int m = 1; m < 2 * length; m *= 2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   270
            for (int i = 1; i <= length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   271
                golden[i - 1] = i % m + m % i;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   272
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   273
            for (TypeConverter converter : TypeConverter.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   274
                out.println("Test 'range': " + converter +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   275
                   ", length = " + length + ", m = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   276
                Object convertedGolden = converter.convert(golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   277
                checkRange(convertedGolden, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   278
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   279
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   280
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   281
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   282
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   283
    private static void testStable(int length, MyRandom random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   284
        ourDescription = "Check if sorting is stable";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   285
        Pair[] a = build(length, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   286
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   287
        out.println("Test 'stable': " + "random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   288
            ", length = " + length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   289
        Arrays.parallelSort(a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   290
        checkSorted(a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   291
        checkStable(a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   292
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   293
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   294
        a = build(length, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   295
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   296
        out.println("Test 'stable' comparator: " + "random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   297
            ", length = " + length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   298
        Arrays.parallelSort(a, pairCmp);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   299
        checkSorted(a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   300
        checkStable(a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   301
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   302
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   303
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   304
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   305
    private static void checkSorted(Pair[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   306
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   307
            if (a[i].getKey() > a[i + 1].getKey()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   308
                failedSort(i, "" + a[i].getKey(), "" + a[i + 1].getKey());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   309
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   310
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   311
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   312
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   313
    private static void checkStable(Pair[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   314
        for (int i = 0; i < a.length / 4; ) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   315
            int key1 = a[i].getKey();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   316
            int value1 = a[i++].getValue();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   317
            int key2 = a[i].getKey();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   318
            int value2 = a[i++].getValue();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   319
            int key3 = a[i].getKey();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   320
            int value3 = a[i++].getValue();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   321
            int key4 = a[i].getKey();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   322
            int value4 = a[i++].getValue();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   323
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   324
            if (!(key1 == key2 && key2 == key3 && key3 == key4)) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   325
                failed("On position " + i + " keys are different " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   326
                    key1 + ", " + key2 + ", " + key3 + ", " + key4);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   327
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   328
            if (!(value1 < value2 && value2 < value3 && value3 < value4)) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   329
                failed("Sorting is not stable at position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   330
                    ". Second values have been changed: " +  value1 + ", " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   331
                    value2 + ", " + value3 + ", " + value4);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   332
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   333
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   334
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   335
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   336
    private static Pair[] build(int length, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   337
        Pair[] a = new Pair[length * 4];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   338
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   339
        for (int i = 0; i < a.length; ) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   340
            int key = random.nextInt();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   341
            a[i++] = new Pair(key, 1);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   342
            a[i++] = new Pair(key, 2);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   343
            a[i++] = new Pair(key, 3);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   344
            a[i++] = new Pair(key, 4);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   345
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   346
        return a;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   347
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   348
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   349
    private static Comparator<Pair> pairCmp = new Comparator<Pair>() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   350
        public int compare(Pair p1, Pair p2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   351
            return p1.compareTo(p2);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   352
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   353
    };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   354
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   355
    private static final class Pair implements Comparable<Pair> {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   356
        Pair(int key, int value) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   357
            myKey = key;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   358
            myValue = value;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   359
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   360
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   361
        int getKey() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   362
            return myKey;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   363
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   364
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   365
        int getValue() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   366
            return myValue;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   367
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   368
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   369
        public int compareTo(Pair pair) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   370
            if (myKey < pair.myKey) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   371
                return -1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   372
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   373
            if (myKey > pair.myKey) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   374
                return 1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   375
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   376
            return 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   377
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   378
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   379
        @Override
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   380
        public String toString() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   381
            return "(" + myKey + ", " + myValue + ")";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   382
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   383
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   384
        private int myKey;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   385
        private int myValue;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   386
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   387
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   388
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   389
    private static void testAndCheckWithInsertionSort(int length, MyRandom random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   390
        if (length > 1000) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   391
            return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   392
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   393
        ourDescription = "Check sorting with insertion sort";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   394
        int[] golden = new int[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   395
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   396
        for (int m = 1; m < 2 * length; m *= 2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   397
            for (UnsortedBuilder builder : UnsortedBuilder.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   398
                builder.build(golden, m, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   399
                int[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   400
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   401
                for (TypeConverter converter : TypeConverter.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   402
                    out.println("Test 'insertion sort': " + converter +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   403
                        " " + builder + "random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   404
                        ", length = " + length + ", m = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   405
                    Object convertedGolden = converter.convert(golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   406
                    Object convertedTest1 = converter.convert(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   407
                    Object convertedTest2 = converter.convert(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   408
                    sort(convertedTest1);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   409
                    sortByInsertionSort(convertedTest2);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   410
                    compare(convertedTest1, convertedTest2);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   411
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   412
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   413
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   414
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   415
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   416
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   417
    private static void testMergeSort(int length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   418
        if (length < 1000) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   419
            return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   420
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   421
        ourDescription = "Check merge sorting";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   422
        int[] golden = new int[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   423
        int period = 67; // java.util.DualPivotQuicksort.MAX_RUN_COUNT
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   424
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   425
        for (int m = period - 2; m <= period + 2; m++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   426
            for (MergeBuilder builder : MergeBuilder.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   427
                builder.build(golden, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   428
                int[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   429
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   430
                for (TypeConverter converter : TypeConverter.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   431
                    out.println("Test 'merge sort': " + converter + " " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   432
                        builder + "length = " + length + ", m = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   433
                    Object convertedGolden = converter.convert(golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   434
                    sort(convertedGolden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   435
                    checkSorted(convertedGolden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   436
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   437
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   438
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   439
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   440
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   441
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   442
    private static void testAndCheckWithCheckSum(int length, MyRandom random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   443
        ourDescription = "Check sorting with check sum";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   444
        int[] golden = new int[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   445
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   446
        for (int m = 1; m < 2 * length; m *= 2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   447
            for (UnsortedBuilder builder : UnsortedBuilder.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   448
                builder.build(golden, m, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   449
                int[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   450
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   451
                for (TypeConverter converter : TypeConverter.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   452
                    out.println("Test 'check sum': " + converter +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   453
                        " " + builder + "random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   454
                        ", length = " + length + ", m = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   455
                    Object convertedGolden = converter.convert(golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   456
                    Object convertedTest = converter.convert(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   457
                    sort(convertedTest);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   458
                    checkWithCheckSum(convertedTest, convertedGolden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   459
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   460
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   461
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   462
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   463
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   464
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   465
    private static void testAndCheckWithScrambling(int length, MyRandom random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   466
        ourDescription = "Check sorting with scrambling";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   467
        int[] golden = new int[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   468
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   469
        for (int m = 1; m <= 7; m++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   470
            if (m > length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   471
                break;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   472
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   473
            for (SortedBuilder builder : SortedBuilder.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   474
                builder.build(golden, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   475
                int[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   476
                scramble(test, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   477
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   478
                for (TypeConverter converter : TypeConverter.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   479
                    out.println("Test 'scrambling': " + converter +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   480
                       " " + builder + "random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   481
                       ", length = " + length + ", m = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   482
                    Object convertedGolden = converter.convert(golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   483
                    Object convertedTest = converter.convert(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   484
                    sort(convertedTest);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   485
                    compare(convertedTest, convertedGolden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   486
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   487
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   488
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   489
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   490
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   491
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   492
    private static void testAndCheckFloat(int length, MyRandom random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   493
        ourDescription = "Check float sorting";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   494
        float[] golden = new float[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   495
        final int MAX = 10;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   496
        boolean newLine = false;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   497
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   498
        for (int a = 0; a <= MAX; a++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   499
            for (int g = 0; g <= MAX; g++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   500
                for (int z = 0; z <= MAX; z++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   501
                    for (int n = 0; n <= MAX; n++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   502
                        for (int p = 0; p <= MAX; p++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   503
                            if (a + g + z + n + p > length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   504
                                continue;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   505
                            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   506
                            if (a + g + z + n + p < length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   507
                                continue;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   508
                            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   509
                            for (FloatBuilder builder : FloatBuilder.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   510
                                out.println("Test 'float': random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   511
                                   ", length = " + length + ", a = " + a + ", g = " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   512
                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   513
                                builder.build(golden, a, g, z, n, p, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   514
                                float[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   515
                                scramble(test, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   516
                                sort(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   517
                                compare(test, golden, a, n, g);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   518
                            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   519
                            newLine = true;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   520
                        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   521
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   522
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   523
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   524
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   525
        if (newLine) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   526
            out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   527
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   528
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   529
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   530
    private static void testAndCheckDouble(int length, MyRandom random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   531
        ourDescription = "Check double sorting";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   532
        double[] golden = new double[length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   533
        final int MAX = 10;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   534
        boolean newLine = false;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   535
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   536
        for (int a = 0; a <= MAX; a++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   537
            for (int g = 0; g <= MAX; g++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   538
                for (int z = 0; z <= MAX; z++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   539
                    for (int n = 0; n <= MAX; n++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   540
                        for (int p = 0; p <= MAX; p++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   541
                            if (a + g + z + n + p > length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   542
                                continue;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   543
                            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   544
                            if (a + g + z + n + p < length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   545
                                continue;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   546
                            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   547
                            for (DoubleBuilder builder : DoubleBuilder.values()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   548
                                out.println("Test 'double': random = " + random.getSeed() +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   549
                                   ", length = " + length + ", a = " + a + ", g = " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   550
                                   g + ", z = " + z + ", n = " + n + ", p = " + p);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   551
                                builder.build(golden, a, g, z, n, p, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   552
                                double[] test = golden.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   553
                                scramble(test, random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   554
                                sort(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   555
                                compare(test, golden, a, n, g);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   556
                            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   557
                            newLine = true;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   558
                        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   559
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   560
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   561
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   562
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   563
        if (newLine) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   564
            out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   565
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   566
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   567
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   568
    private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   569
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   570
            a[i] = 0xDEDA;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   571
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   572
        int middle = (fromIndex + toIndex) >>> 1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   573
        int k = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   574
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   575
        for (int i = fromIndex; i < middle; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   576
            a[i] = k++;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   577
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   578
        for (int i = middle; i < toIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   579
            a[i] = k--;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   580
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   581
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   582
            a[i] = 0xBABA;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   583
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   584
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   585
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   586
    private static void scramble(int[] a, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   587
        for (int i = 0; i < a.length * 7; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   588
            swap(a, random.nextInt(a.length), random.nextInt(a.length));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   589
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   590
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   591
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   592
    private static void scramble(float[] a, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   593
        for (int i = 0; i < a.length * 7; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   594
            swap(a, random.nextInt(a.length), random.nextInt(a.length));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   595
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   596
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   597
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   598
    private static void scramble(double[] a, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   599
        for (int i = 0; i < a.length * 7; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   600
            swap(a, random.nextInt(a.length), random.nextInt(a.length));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   601
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   602
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   603
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   604
    private static void swap(int[] a, int i, int j) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   605
        int t = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   606
        a[i] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   607
        a[j] = t;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   608
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   609
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   610
    private static void swap(float[] a, int i, int j) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   611
        float t = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   612
        a[i] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   613
        a[j] = t;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   614
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   615
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   616
    private static void swap(double[] a, int i, int j) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   617
        double t = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   618
        a[i] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   619
        a[j] = t;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   620
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   621
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   622
    private static enum TypeConverter {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   623
        INT {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   624
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   625
                return a.clone();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   626
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   627
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   628
        LONG {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   629
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   630
                long[] b = new long[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   631
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   632
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   633
                    b[i] = (long) a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   634
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   635
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   636
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   637
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   638
        BYTE {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   639
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   640
                byte[] b = new byte[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   641
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   642
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   643
                    b[i] = (byte) a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   644
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   645
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   646
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   647
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   648
        SHORT {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   649
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   650
                short[] b = new short[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   651
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   652
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   653
                    b[i] = (short) a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   654
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   655
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   656
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   657
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   658
        CHAR {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   659
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   660
                char[] b = new char[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   661
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   662
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   663
                    b[i] = (char) a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   664
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   665
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   666
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   667
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   668
        FLOAT {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   669
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   670
                float[] b = new float[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   671
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   672
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   673
                    b[i] = (float) a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   674
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   675
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   676
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   677
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   678
        DOUBLE {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   679
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   680
                double[] b = new double[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   681
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   682
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   683
                    b[i] = (double) a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   684
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   685
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   686
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   687
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   688
        INTEGER {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   689
            Object convert(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   690
                Integer[] b = new Integer[a.length];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   691
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   692
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   693
                    b[i] = new Integer(a[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   694
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   695
                return b;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   696
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   697
        };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   698
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   699
        abstract Object convert(int[] a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   700
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   701
        @Override public String toString() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   702
            String name = name();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   703
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   704
            for (int i = name.length(); i < 9; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   705
                name += " ";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   706
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   707
            return name;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   708
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   709
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   710
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   711
    private static enum FloatBuilder {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   712
        SIMPLE {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   713
            void build(float[] x, int a, int g, int z, int n, int p, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   714
                int fromIndex = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   715
                float negativeValue = -random.nextFloat();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   716
                float positiveValue =  random.nextFloat();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   717
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   718
                writeValue(x, negativeValue, fromIndex, n);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   719
                fromIndex += n;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   720
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   721
                writeValue(x, -0.0f, fromIndex, g);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   722
                fromIndex += g;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   723
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   724
                writeValue(x, 0.0f, fromIndex, z);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   725
                fromIndex += z;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   726
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   727
                writeValue(x, positiveValue, fromIndex, p);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   728
                fromIndex += p;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   729
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   730
                writeValue(x, Float.NaN, fromIndex, a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   731
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   732
        };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   733
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   734
        abstract void build(float[] x, int a, int g, int z, int n, int p, Random random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   735
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   736
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   737
    private static enum DoubleBuilder {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   738
        SIMPLE {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   739
            void build(double[] x, int a, int g, int z, int n, int p, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   740
                int fromIndex = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   741
                double negativeValue = -random.nextFloat();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   742
                double positiveValue =  random.nextFloat();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   743
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   744
                writeValue(x, negativeValue, fromIndex, n);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   745
                fromIndex += n;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   746
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   747
                writeValue(x, -0.0d, fromIndex, g);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   748
                fromIndex += g;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   749
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   750
                writeValue(x, 0.0d, fromIndex, z);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   751
                fromIndex += z;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   752
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   753
                writeValue(x, positiveValue, fromIndex, p);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   754
                fromIndex += p;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   755
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   756
                writeValue(x, Double.NaN, fromIndex, a);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   757
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   758
        };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   759
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   760
        abstract void build(double[] x, int a, int g, int z, int n, int p, Random random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   761
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   762
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   763
    private static void writeValue(float[] a, float value, int fromIndex, int count) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   764
        for (int i = fromIndex; i < fromIndex + count; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   765
            a[i] = value;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   766
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   767
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   768
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   769
    private static void compare(float[] a, float[] b, int numNaN, int numNeg, int numNegZero) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   770
        for (int i = a.length - numNaN; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   771
            if (a[i] == a[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   772
                failed("On position " + i + " must be NaN instead of " + a[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   773
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   774
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   775
        final int NEGATIVE_ZERO = Float.floatToIntBits(-0.0f);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   776
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   777
        for (int i = numNeg; i < numNeg + numNegZero; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   778
            if (NEGATIVE_ZERO != Float.floatToIntBits(a[i])) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   779
                failed("On position " + i + " must be -0.0 instead of " + a[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   780
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   781
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   782
        for (int i = 0; i < a.length - numNaN; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   783
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   784
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   785
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   786
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   787
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   788
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   789
    private static void writeValue(double[] a, double value, int fromIndex, int count) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   790
        for (int i = fromIndex; i < fromIndex + count; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   791
            a[i] = value;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   792
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   793
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   794
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   795
    private static void compare(double[] a, double[] b, int numNaN, int numNeg, int numNegZero) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   796
        for (int i = a.length - numNaN; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   797
            if (a[i] == a[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   798
                failed("On position " + i + " must be NaN instead of " + a[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   799
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   800
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   801
        final long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0d);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   802
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   803
        for (int i = numNeg; i < numNeg + numNegZero; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   804
            if (NEGATIVE_ZERO != Double.doubleToLongBits(a[i])) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   805
                failed("On position " + i + " must be -0.0 instead of " + a[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   806
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   807
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   808
        for (int i = 0; i < a.length - numNaN; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   809
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   810
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   811
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   812
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   813
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   814
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   815
    private static enum SortedBuilder {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   816
        REPEATED {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   817
            void build(int[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   818
                int period = a.length / m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   819
                int i = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   820
                int k = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   821
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   822
                while (true) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   823
                    for (int t = 1; t <= period; t++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   824
                        if (i >= a.length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   825
                            return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   826
                        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   827
                        a[i++] = k;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   828
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   829
                    if (i >= a.length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   830
                        return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   831
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   832
                    k++;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   833
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   834
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   835
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   836
        ORGAN_PIPES {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   837
            void build(int[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   838
                int i = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   839
                int k = m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   840
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   841
                while (true) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   842
                    for (int t = 1; t <= m; t++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   843
                        if (i >= a.length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   844
                            return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   845
                        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   846
                        a[i++] = k;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   847
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   848
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   849
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   850
        };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   851
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   852
        abstract void build(int[] a, int m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   853
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   854
        @Override public String toString() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   855
            String name = name();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   856
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   857
            for (int i = name.length(); i < 12; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   858
                name += " ";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   859
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   860
            return name;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   861
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   862
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   863
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   864
    private static enum MergeBuilder {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   865
        ASCENDING {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   866
            void build(int[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   867
                int period = a.length / m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   868
                int v = 1, i = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   869
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   870
                for (int k = 0; k < m; k++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   871
                    v = 1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   872
                    for (int p = 0; p < period; p++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   873
                        a[i++] = v++;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   874
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   875
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   876
                for (int j = i; j < a.length - 1; j++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   877
                    a[j] = v++;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   878
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   879
                a[a.length - 1] = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   880
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   881
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   882
        DESCENDING {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   883
            void build(int[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   884
                int period = a.length / m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   885
                int v = -1, i = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   886
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   887
                for (int k = 0; k < m; k++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   888
                    v = -1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   889
                    for (int p = 0; p < period; p++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   890
                        a[i++] = v--;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   891
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   892
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   893
                for (int j = i; j < a.length - 1; j++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   894
                    a[j] = v--;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   895
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   896
                a[a.length - 1] = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   897
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   898
        };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   899
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   900
        abstract void build(int[] a, int m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   901
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   902
        @Override public String toString() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   903
            String name = name();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   904
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   905
            for (int i = name.length(); i < 12; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   906
                name += " ";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   907
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   908
            return name;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   909
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   910
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   911
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   912
    private static enum UnsortedBuilder {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   913
        RANDOM {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   914
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   915
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   916
                    a[i] = random.nextInt();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   917
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   918
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   919
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   920
        ASCENDING {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   921
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   922
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   923
                    a[i] = m + i;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   924
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   925
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   926
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   927
        DESCENDING {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   928
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   929
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   930
                    a[i] = a.length - m - i;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   931
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   932
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   933
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   934
        ALL_EQUAL {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   935
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   936
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   937
                    a[i] = m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   938
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   939
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   940
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   941
        SAW {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   942
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   943
                int incCount = 1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   944
                int decCount = a.length;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   945
                int i = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   946
                int period = m--;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   947
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   948
                while (true) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   949
                    for (int k = 1; k <= period; k++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   950
                        if (i >= a.length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   951
                            return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   952
                        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   953
                        a[i++] = incCount++;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   954
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   955
                    period += m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   956
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   957
                    for (int k = 1; k <= period; k++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   958
                        if (i >= a.length) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   959
                            return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   960
                        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   961
                        a[i++] = decCount--;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   962
                    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   963
                    period += m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   964
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   965
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   966
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   967
        REPEATED {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   968
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   969
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   970
                    a[i] = i % m;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   971
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   972
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   973
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   974
        DUPLICATED {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   975
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   976
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   977
                    a[i] = random.nextInt(m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   978
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   979
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   980
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   981
        ORGAN_PIPES {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   982
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   983
                int middle = a.length / (m + 1);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   984
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   985
                for (int i = 0; i < middle; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   986
                    a[i] = i;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   987
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   988
                for (int i = middle; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   989
                    a[i] = a.length - i - 1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   990
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   991
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   992
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   993
        STAGGER {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   994
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   995
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   996
                    a[i] = (i * m + i) % a.length;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   997
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   998
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
   999
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1000
        PLATEAU {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1001
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1002
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1003
                    a[i] = Math.min(i, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1004
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1005
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1006
        },
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1007
        SHUFFLE {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1008
            void build(int[] a, int m, Random random) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1009
                int x = 0, y = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1010
                for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1011
                    a[i] = random.nextBoolean() ? (x += 2) : (y += 2);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1012
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1013
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1014
        };
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1015
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1016
        abstract void build(int[] a, int m, Random random);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1017
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1018
        @Override public String toString() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1019
            String name = name();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1020
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1021
            for (int i = name.length(); i < 12; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1022
                name += " ";
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1023
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1024
            return name;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1025
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1026
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1027
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1028
    private static void checkWithCheckSum(Object test, Object golden) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1029
        checkSorted(test);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1030
        checkCheckSum(test, golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1031
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1032
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1033
    private static void failed(String message) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1034
        err.format("\n*** TEST FAILED - %s.\n\n%s.\n\n", ourDescription, message);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1035
        throw new RuntimeException("Test failed - see log file for details");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1036
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1037
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1038
    private static void failedSort(int index, String value1, String value2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1039
        failed("Array is not sorted at " + index + "-th position: " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1040
            value1 + " and " + value2);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1041
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1042
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1043
    private static void failedCompare(int index, String value1, String value2) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1044
        failed("On position " + index + " must be " + value2 + " instead of " + value1);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1045
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1046
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1047
    private static void compare(Object test, Object golden) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1048
        if (test instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1049
            compare((int[]) test, (int[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1050
        } else if (test instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1051
            compare((long[]) test, (long[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1052
        } else if (test instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1053
            compare((short[]) test, (short[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1054
        } else if (test instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1055
            compare((byte[]) test, (byte[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1056
        } else if (test instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1057
            compare((char[]) test, (char[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1058
        } else if (test instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1059
            compare((float[]) test, (float[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1060
        } else if (test instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1061
            compare((double[]) test, (double[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1062
        } else if (test instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1063
            compare((Integer[]) test, (Integer[]) golden);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1064
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1065
            failed("Unknow type of array: " + test + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1066
                test.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1067
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1068
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1069
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1070
    private static void compare(int[] a, int[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1071
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1072
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1073
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1074
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1075
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1076
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1077
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1078
    private static void compare(long[] a, long[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1079
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1080
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1081
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1082
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1083
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1084
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1085
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1086
    private static void compare(short[] a, short[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1087
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1088
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1089
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1090
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1091
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1092
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1093
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1094
    private static void compare(byte[] a, byte[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1095
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1096
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1097
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1098
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1099
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1100
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1101
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1102
    private static void compare(char[] a, char[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1103
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1104
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1105
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1106
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1107
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1108
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1109
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1110
    private static void compare(float[] a, float[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1111
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1112
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1113
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1114
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1115
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1116
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1117
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1118
    private static void compare(double[] a, double[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1119
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1120
            if (a[i] != b[i]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1121
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1122
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1123
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1124
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1125
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1126
    private static void compare(Integer[] a, Integer[] b) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1127
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1128
            if (a[i].compareTo(b[i]) != 0) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1129
                failedCompare(i, "" + a[i], "" + b[i]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1130
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1131
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1132
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1133
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1134
    private static void checkSorted(Object object) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1135
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1136
            checkSorted((int[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1137
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1138
            checkSorted((long[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1139
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1140
            checkSorted((short[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1141
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1142
            checkSorted((byte[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1143
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1144
            checkSorted((char[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1145
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1146
            checkSorted((float[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1147
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1148
            checkSorted((double[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1149
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1150
            checkSorted((Integer[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1151
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1152
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1153
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1154
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1155
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1156
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1157
    private static void checkSorted(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1158
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1159
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1160
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1161
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1162
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1163
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1164
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1165
    private static void checkSorted(long[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1166
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1167
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1168
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1169
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1170
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1171
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1172
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1173
    private static void checkSorted(short[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1174
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1175
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1176
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1177
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1178
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1179
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1180
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1181
    private static void checkSorted(byte[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1182
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1183
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1184
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1185
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1186
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1187
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1188
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1189
    private static void checkSorted(char[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1190
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1191
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1192
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1193
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1194
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1195
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1196
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1197
    private static void checkSorted(float[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1198
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1199
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1200
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1201
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1202
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1203
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1204
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1205
    private static void checkSorted(double[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1206
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1207
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1208
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1209
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1210
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1211
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1212
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1213
    private static void checkSorted(Integer[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1214
        for (int i = 0; i < a.length - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1215
            if (a[i].intValue() > a[i + 1].intValue()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1216
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1217
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1218
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1219
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1220
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1221
    private static void checkCheckSum(Object test, Object golden) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1222
        if (checkSumXor(test) != checkSumXor(golden)) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1223
            failed("Original and sorted arrays are not identical [xor]");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1224
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1225
        if (checkSumPlus(test) != checkSumPlus(golden)) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1226
            failed("Original and sorted arrays are not identical [plus]");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1227
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1228
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1229
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1230
    private static int checkSumXor(Object object) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1231
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1232
            return checkSumXor((int[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1233
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1234
            return checkSumXor((long[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1235
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1236
            return checkSumXor((short[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1237
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1238
            return checkSumXor((byte[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1239
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1240
            return checkSumXor((char[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1241
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1242
            return checkSumXor((float[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1243
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1244
            return checkSumXor((double[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1245
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1246
            return checkSumXor((Integer[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1247
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1248
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1249
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1250
            return -1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1251
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1252
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1253
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1254
    private static int checkSumXor(Integer[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1255
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1256
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1257
        for (Integer e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1258
            checkSum ^= e.intValue();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1259
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1260
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1261
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1262
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1263
    private static int checkSumXor(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1264
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1265
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1266
        for (int e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1267
            checkSum ^= e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1268
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1269
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1270
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1271
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1272
    private static int checkSumXor(long[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1273
        long checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1274
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1275
        for (long e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1276
            checkSum ^= e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1277
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1278
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1279
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1280
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1281
    private static int checkSumXor(short[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1282
        short checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1283
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1284
        for (short e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1285
            checkSum ^= e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1286
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1287
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1288
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1289
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1290
    private static int checkSumXor(byte[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1291
        byte checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1292
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1293
        for (byte e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1294
            checkSum ^= e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1295
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1296
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1297
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1298
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1299
    private static int checkSumXor(char[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1300
        char checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1301
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1302
        for (char e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1303
            checkSum ^= e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1304
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1305
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1306
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1307
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1308
    private static int checkSumXor(float[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1309
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1310
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1311
        for (float e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1312
            checkSum ^= (int) e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1313
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1314
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1315
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1316
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1317
    private static int checkSumXor(double[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1318
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1319
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1320
        for (double e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1321
            checkSum ^= (int) e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1322
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1323
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1324
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1325
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1326
    private static int checkSumPlus(Object object) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1327
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1328
            return checkSumPlus((int[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1329
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1330
            return checkSumPlus((long[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1331
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1332
            return checkSumPlus((short[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1333
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1334
            return checkSumPlus((byte[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1335
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1336
            return checkSumPlus((char[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1337
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1338
            return checkSumPlus((float[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1339
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1340
            return checkSumPlus((double[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1341
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1342
            return checkSumPlus((Integer[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1343
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1344
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1345
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1346
            return -1;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1347
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1348
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1349
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1350
    private static int checkSumPlus(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1351
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1352
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1353
        for (int e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1354
            checkSum += e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1355
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1356
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1357
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1358
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1359
    private static int checkSumPlus(long[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1360
        long checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1361
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1362
        for (long e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1363
            checkSum += e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1364
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1365
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1366
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1367
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1368
    private static int checkSumPlus(short[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1369
        short checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1370
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1371
        for (short e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1372
            checkSum += e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1373
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1374
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1375
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1376
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1377
    private static int checkSumPlus(byte[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1378
        byte checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1379
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1380
        for (byte e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1381
            checkSum += e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1382
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1383
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1384
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1385
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1386
    private static int checkSumPlus(char[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1387
        char checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1388
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1389
        for (char e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1390
            checkSum += e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1391
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1392
        return (int) checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1393
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1394
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1395
    private static int checkSumPlus(float[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1396
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1397
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1398
        for (float e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1399
            checkSum += (int) e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1400
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1401
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1402
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1403
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1404
    private static int checkSumPlus(double[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1405
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1406
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1407
        for (double e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1408
            checkSum += (int) e;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1409
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1410
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1411
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1412
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1413
    private static int checkSumPlus(Integer[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1414
        int checkSum = 0;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1415
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1416
        for (Integer e : a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1417
            checkSum += e.intValue();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1418
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1419
        return checkSum;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1420
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1421
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1422
    private static void sortByInsertionSort(Object object) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1423
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1424
            sortByInsertionSort((int[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1425
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1426
            sortByInsertionSort((long[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1427
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1428
            sortByInsertionSort((short[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1429
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1430
            sortByInsertionSort((byte[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1431
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1432
            sortByInsertionSort((char[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1433
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1434
            sortByInsertionSort((float[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1435
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1436
            sortByInsertionSort((double[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1437
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1438
            sortByInsertionSort((Integer[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1439
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1440
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1441
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1442
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1443
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1444
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1445
    private static void sortByInsertionSort(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1446
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1447
            int ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1448
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1449
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1450
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1451
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1452
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1453
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1454
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1455
    private static void sortByInsertionSort(long[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1456
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1457
            long ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1458
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1459
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1460
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1461
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1462
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1463
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1464
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1465
    private static void sortByInsertionSort(short[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1466
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1467
            short ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1468
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1469
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1470
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1471
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1472
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1473
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1474
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1475
    private static void sortByInsertionSort(byte[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1476
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1477
            byte ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1478
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1479
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1480
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1481
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1482
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1483
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1484
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1485
    private static void sortByInsertionSort(char[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1486
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1487
            char ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1488
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1489
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1490
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1491
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1492
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1493
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1494
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1495
    private static void sortByInsertionSort(float[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1496
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1497
            float ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1498
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1499
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1500
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1501
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1502
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1503
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1504
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1505
    private static void sortByInsertionSort(double[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1506
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1507
            double ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1508
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1509
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1510
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1511
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1512
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1513
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1514
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1515
    private static void sortByInsertionSort(Integer[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1516
        for (int j, i = 1; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1517
            Integer ai = a[i];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1518
            for (j = i - 1; j >= 0 && ai < a[j]; j--) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1519
                a[j + 1] = a[j];
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1520
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1521
            a[j + 1] = ai;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1522
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1523
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1524
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1525
    private static void sort(Object object) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1526
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1527
            Arrays.parallelSort((int[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1528
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1529
            Arrays.parallelSort((long[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1530
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1531
            Arrays.parallelSort((short[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1532
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1533
            Arrays.parallelSort((byte[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1534
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1535
            Arrays.parallelSort((char[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1536
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1537
            Arrays.parallelSort((float[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1538
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1539
            Arrays.parallelSort((double[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1540
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1541
            Arrays.parallelSort((Integer[]) object);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1542
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1543
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1544
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1545
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1546
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1547
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1548
    private static void sortSubArray(Object object, int fromIndex, int toIndex) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1549
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1550
            Arrays.parallelSort((int[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1551
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1552
            Arrays.parallelSort((long[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1553
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1554
            Arrays.parallelSort((short[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1555
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1556
            Arrays.parallelSort((byte[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1557
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1558
            Arrays.parallelSort((char[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1559
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1560
            Arrays.parallelSort((float[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1561
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1562
            Arrays.parallelSort((double[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1563
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1564
            Arrays.parallelSort((Integer[]) object, fromIndex, toIndex);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1565
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1566
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1567
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1568
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1569
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1570
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1571
    private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1572
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1573
            checkSubArray((int[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1574
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1575
            checkSubArray((long[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1576
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1577
            checkSubArray((short[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1578
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1579
            checkSubArray((byte[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1580
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1581
            checkSubArray((char[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1582
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1583
            checkSubArray((float[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1584
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1585
            checkSubArray((double[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1586
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1587
            checkSubArray((Integer[]) object, fromIndex, toIndex, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1588
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1589
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1590
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1591
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1592
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1593
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1594
    private static void checkSubArray(Integer[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1595
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1596
            if (a[i].intValue() != 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1597
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1598
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1599
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1600
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1601
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1602
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1603
            if (a[i].intValue() > a[i + 1].intValue()) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1604
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1605
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1606
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1607
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1608
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1609
            if (a[i].intValue() != 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1610
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1611
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1612
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1613
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1614
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1615
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1616
    private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1617
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1618
            if (a[i] != 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1619
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1620
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1621
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1622
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1623
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1624
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1625
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1626
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1627
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1628
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1629
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1630
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1631
            if (a[i] != 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1632
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1633
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1634
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1635
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1636
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1637
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1638
    private static void checkSubArray(byte[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1639
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1640
            if (a[i] != (byte) 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1641
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1642
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1643
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1644
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1645
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1646
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1647
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1648
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1649
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1650
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1651
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1652
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1653
            if (a[i] != (byte) 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1654
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1655
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1656
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1657
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1658
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1659
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1660
    private static void checkSubArray(long[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1661
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1662
            if (a[i] != (long) 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1663
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1664
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1665
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1666
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1667
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1668
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1669
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1670
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1671
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1672
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1673
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1674
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1675
            if (a[i] != (long) 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1676
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1677
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1678
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1679
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1680
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1681
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1682
    private static void checkSubArray(char[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1683
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1684
            if (a[i] != (char) 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1685
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1686
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1687
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1688
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1689
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1690
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1691
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1692
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1693
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1694
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1695
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1696
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1697
            if (a[i] != (char) 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1698
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1699
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1700
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1701
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1702
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1703
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1704
    private static void checkSubArray(short[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1705
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1706
            if (a[i] != (short) 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1707
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1708
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1709
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1710
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1711
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1712
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1713
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1714
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1715
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1716
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1717
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1718
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1719
            if (a[i] != (short) 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1720
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1721
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1722
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1723
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1724
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1725
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1726
    private static void checkSubArray(float[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1727
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1728
            if (a[i] != (float) 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1729
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1730
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1731
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1732
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1733
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1734
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1735
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1736
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1737
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1738
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1739
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1740
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1741
            if (a[i] != (float) 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1742
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1743
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1744
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1745
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1746
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1747
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1748
    private static void checkSubArray(double[] a, int fromIndex, int toIndex, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1749
        for (int i = 0; i < fromIndex; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1750
            if (a[i] != (double) 0xDEDA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1751
                failed("Range sort changes left element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1752
                    ": " + a[i] + ", must be " + 0xDEDA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1753
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1754
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1755
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1756
        for (int i = fromIndex; i < toIndex - 1; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1757
            if (a[i] > a[i + 1]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1758
                failedSort(i, "" + a[i], "" + a[i + 1]);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1759
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1760
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1761
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1762
        for (int i = toIndex; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1763
            if (a[i] != (double) 0xBABA) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1764
                failed("Range sort changes right element on position " + i +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1765
                    ": " + a[i] + ", must be " + 0xBABA);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1766
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1767
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1768
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1769
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1770
    private static void checkRange(Object object, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1771
        if (object instanceof int[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1772
            checkRange((int[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1773
        } else if (object instanceof long[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1774
            checkRange((long[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1775
        } else if (object instanceof short[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1776
            checkRange((short[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1777
        } else if (object instanceof byte[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1778
            checkRange((byte[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1779
        } else if (object instanceof char[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1780
            checkRange((char[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1781
        } else if (object instanceof float[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1782
            checkRange((float[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1783
        } else if (object instanceof double[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1784
            checkRange((double[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1785
        } else if (object instanceof Integer[]) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1786
            checkRange((Integer[]) object, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1787
        } else {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1788
            failed("Unknow type of array: " + object + " of class " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1789
                object.getClass().getName());
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1790
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1791
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1792
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1793
    private static void checkRange(Integer[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1794
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1795
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1796
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1797
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1798
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1799
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1800
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1801
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1802
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1803
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1804
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1805
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1806
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1807
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1808
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1809
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1810
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1811
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1812
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1813
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1814
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1815
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1816
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1817
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1818
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1819
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1820
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1821
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1822
    private static void checkRange(int[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1823
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1824
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1825
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1826
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1827
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1828
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1829
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1830
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1831
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1832
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1833
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1834
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1835
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1836
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1837
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1838
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1839
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1840
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1841
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1842
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1843
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1844
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1845
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1846
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1847
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1848
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1849
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1850
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1851
    private static void checkRange(long[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1852
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1853
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1854
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1855
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1856
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1857
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1858
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1859
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1860
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1861
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1862
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1863
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1864
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1865
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1866
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1867
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1868
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1869
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1870
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1871
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1872
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1873
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1874
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1875
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1876
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1877
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1878
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1879
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1880
    private static void checkRange(byte[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1881
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1882
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1883
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1884
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1885
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1886
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1887
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1888
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1889
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1890
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1891
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1892
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1893
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1894
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1895
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1896
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1897
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1898
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1899
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1900
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1901
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1902
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1903
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1904
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1905
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1906
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1907
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1908
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1909
    private static void checkRange(short[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1910
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1911
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1912
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1913
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1914
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1915
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1916
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1917
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1918
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1919
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1920
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1921
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1922
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1923
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1924
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1925
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1926
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1927
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1928
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1929
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1930
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1931
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1932
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1933
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1934
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1935
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1936
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1937
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1938
    private static void checkRange(char[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1939
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1940
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1941
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1942
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1943
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1944
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1945
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1946
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1947
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1948
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1949
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1950
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1951
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1952
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1953
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1954
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1955
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1956
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1957
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1958
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1959
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1960
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1961
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1962
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1963
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1964
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1965
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1966
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1967
    private static void checkRange(float[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1968
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1969
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1970
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1971
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1972
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1973
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1974
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1975
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1976
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1977
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1978
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1979
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1980
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1981
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1982
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1983
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1984
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1985
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1986
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1987
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1988
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1989
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1990
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1991
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1992
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1993
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1994
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1995
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1996
    private static void checkRange(double[] a, int m) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1997
        try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1998
            Arrays.parallelSort(a, m + 1, m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  1999
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2000
            failed("ParallelSort does not throw IllegalArgumentException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2001
                " as expected: fromIndex = " + (m + 1) +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2002
                " toIndex = " + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2003
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2004
        catch (IllegalArgumentException iae) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2005
            try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2006
                Arrays.parallelSort(a, -m, a.length);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2007
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2008
                failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2009
                    " as expected: fromIndex = " + (-m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2010
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2011
            catch (ArrayIndexOutOfBoundsException aoe) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2012
                try {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2013
                    Arrays.parallelSort(a, 0, a.length + m);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2014
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2015
                    failed("ParallelSort does not throw ArrayIndexOutOfBoundsException " +
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2016
                        " as expected: toIndex = " + (a.length + m));
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2017
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2018
                catch (ArrayIndexOutOfBoundsException aie) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2019
                    return;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2020
                }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2021
            }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2022
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2023
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2024
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2025
    private static void outArray(Object[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2026
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2027
            out.print(a[i] + " ");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2028
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2029
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2030
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2031
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2032
    private static void outArray(int[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2033
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2034
            out.print(a[i] + " ");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2035
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2036
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2037
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2038
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2039
    private static void outArray(float[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2040
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2041
            out.print(a[i] + " ");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2042
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2043
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2044
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2045
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2046
    private static void outArray(double[] a) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2047
        for (int i = 0; i < a.length; i++) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2048
            out.print(a[i] + " ");
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2049
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2050
        out.println();
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2051
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2052
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2053
    private static class MyRandom extends Random {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2054
        MyRandom(long seed) {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2055
            super(seed);
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2056
            mySeed = seed;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2057
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2058
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2059
        long getSeed() {
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2060
            return mySeed;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2061
        }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2062
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2063
        private long mySeed;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2064
    }
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2065
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2066
    private static String ourDescription;
72729557c226 8003981: Support Parallel Array Sorting - JEP 103
chegar
parents:
diff changeset
  2067
}