public static final void sortKeyValuePairs(long[] keys, double[] values,
      int startInd, int endInd) {
    // Base case.
    if (endInd - startInd <= 1) {
      return;
    }

    // Choose pivot.
    int pivotInd = (int) (Math.random() * (endInd - startInd)) + startInd;

    // Perform swaps to partition array around the pivot.
    swap(keys, values, startInd, pivotInd);
    pivotInd = startInd;

    for (int i = startInd + 1; i < endInd; i++) {
      if (keys[i] < keys[pivotInd]) {
        swap(keys, values, pivotInd, pivotInd + 1);
        if (i != pivotInd + 1) {
          swap(keys, values, pivotInd, i);
        }
        pivotInd++;
      }
    }

    // Recursively sort the subcomponents of the arrays.
    sortKeyValuePairs(keys, values, startInd, pivotInd);
    sortKeyValuePairs(keys, values, pivotInd + 1, endInd);
  }
public static final void sortKeyValuePairs ( long [ ] keys , double [ ] values , int startInd , int endInd ) { if ( endInd - startInd <= 1 ) { return ; } int pivotInd = ( int ) ( Math . random ( ) * ( endInd - startInd ) ) + startInd ; swap ( keys , values , startInd , pivotInd ) ; pivotInd = startInd ; for ( int i = startInd + 1 ; i < endInd ; i ++ ) { if ( keys [ i ] < keys [ pivotInd ] ) { swap ( keys , values , pivotInd , pivotInd + 1 ) ; if ( i != pivotInd + 1 ) { swap ( keys , values , pivotInd , i ) ; } pivotInd ++ ; } } sortKeyValuePairs ( keys , values , startInd , pivotInd ) ; sortKeyValuePairs ( keys , values , pivotInd + 1 , endInd ) ; }
Sorts a portion of the given key/value pairs by key. This method
sorts the section of {@code keys} from {@code startInd}
(inclusive) to {@code endInd} (not inclusive), simultaneously
swapping the corresponding entries of {@code values}.

@param keys
@param values
@param startInd
@param endInd