static void sort(short[] a, int left, int right,
                     short[] work, int workBase, int workLen) {
        // Use counting sort on large arrays
        if (right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR) {
            int[] count = new int[NUM_SHORT_VALUES];

            for (int i = left - 1; ++i <= right;
                count[a[i] - Short.MIN_VALUE]++
            );
            for (int i = NUM_SHORT_VALUES, k = right + 1; k > left; ) {
                while (count[--i] == 0);
                short value = (short) (i + Short.MIN_VALUE);
                int s = count[i];

                do {
                    a[--k] = value;
                } while (--s > 0);
            }
        } else { // Use Dual-Pivot Quicksort on small arrays
            doSort(a, left, right, work, workBase, workLen);
        }
    }
static void sort ( short [ ] a , int left , int right , short [ ] work , int workBase , int workLen ) { if ( right - left > COUNTING_SORT_THRESHOLD_FOR_SHORT_OR_CHAR ) { int [ ] count = new int [ NUM_SHORT_VALUES ] ; for ( int i = left - 1 ; ++ i <= right ; count [ a [ i ] - Short . MIN_VALUE ] ++ ) ; for ( int i = NUM_SHORT_VALUES , k = right + 1 ; k > left ; ) { while ( count [ -- i ] == 0 ) ; short value = ( short ) ( i + Short . MIN_VALUE ) ; int s = count [ i ] ; do { a [ -- k ] = value ; } while ( -- s > 0 ) ; } } else { doSort ( a , left , right , work , workBase , workLen ) ; } }
Sorts the specified range of the array using the given
workspace array slice if possible for merging

@param a the array to be sorted
@param left the index of the first element, inclusive, to be sorted
@param right the index of the last element, inclusive, to be sorted
@param work a workspace array (slice)
@param workBase origin of usable space in work array
@param workLen usable size of work array