public void sort(T[] array, Comparator<T> comparator) {
        this.array = array;
        this.comparator = comparator;
        clean();
        int low = 0;
        int high = length;
        int remaining = high - low;

        /*
         * If array's size is below min_size, we perform a binary insertion sort,
         * but first we check if some existing ordered pattern exists to reduce 
         * the size of data to be sorted.
         */
        if (remaining < MIN_SIZE) {
            int runLength = getRunLength(array, low, high, comparator);
            binaryInsertionSort(array, low, high, low + runLength, comparator);
            return;
        }

        /*
         * Main iteration: compute minimum run length, then iterate through the
         * array to find runs and merge them until they can be binary sorted 
         * if their length < minLength
         */
        int minLength = mergeComputeMinRun(remaining);
        while (remaining != 0) {
            int runLength = getRunLength(array, low, high, comparator);

            /* If the run length is below the threshold, binary sort the remaining
             * elements.
             */
            if (runLength < minLength) {
                int newLength = remaining <= minLength ? remaining : minLength;
                binaryInsertionSort(array, low, low + newLength, low + runLength, comparator);
                runLength = newLength;
            }

            // Add run to pending runs to merge and merge if necessary.
            runsIndices[nbRuns] = low;
            runsLength[nbRuns] = runLength;
            nbRuns++;
            mergeCollapse();

            // Advance to find next run
            low += runLength;
            remaining -= runLength;
        }

        // Merge all remaining runs to complete sort        
        mergeForceCollapse();        

    }
Sort the given array given the comparator
@param array the array to sort
@param comparator the comparator to compare elements of the array
jme3-core/src/main/java/com/jme3/util/ListSort.java