docs: public static void sort(double[] x, int start, int end, Collection<List<?>> paired)
      {
          int a = start;
          int n = end-start;
          if (n < 7)/* Insertion sort on smallest arrays */
          {
              for (int i = a; i < end; i++)
                  for (int j = i; j > a && x[j - 1] > x[j]; j--)
                      swap(x, j, j - 1, paired);
              return;
          }
          
          int pm = a + (n/2);  /* Small arrays, middle element */
          if (n > 7)
          {
              int pl = a;
              int pn = a + n - 1;
              if (n > 40) /* Big arrays, pseudomedian of 9 */
              {        
                  int s = n / 8;
                  pl = med3(x, pl, pl + s, pl + 2 * s);
                  pm = med3(x, pm - s, pm, pm + s);
                  pn = med3(x, pn - 2 * s, pn - s, pn);
              }
              pm = med3(x, pl, pm, pn); /* Mid-size, med of 3 */
          }
          double pivotValue = x[pm];
  
          int pa = a, pb = pa, pc = end - 1, pd = pc;
          while (true)
          {
              while (pb <= pc && x[pb] <= pivotValue)
              {
                  if (x[pb] == pivotValue)
                      swap(x, pa++, pb, paired);
                  pb++;
              }
              while (pc >= pb && x[pc] >= pivotValue)
              {
                  if (x[pc] == pivotValue)
                      swap(x, pc, pd--, paired);
                  pc--;
              }
              if (pb > pc)
                  break;
              swap(x, pb++, pc--, paired);
          }
  
          
          int s;
          int pn = end;
          s = Math.min(pa - a, pb - pa);
          vecswap(x, a, pb - s, s, paired);
          s = Math.min(pd - pc, pn - pd - 1);
          vecswap(x, pb, pn - s, s, paired);
  
          //recurse 
          if ((s = pb - pa) > 1)
              sort(x, a, a+s, paired);
          if ((s = pd - pc) > 1)
              sort(x, pn - s, pn, paired);
          
      }